Filename.st
branchjv
changeset 19406 faccbadf3034
parent 19127 940613fe6659
parent 19362 dd6ee6342985
child 19478 1f5aa87f6170
equal deleted inserted replaced
19354:ec77be1507a3 19406:faccbadf3034
   627      DO NOT USE THIS FOR PLAIN FILES - IT IS UNSECURE use FileStream>>#newTemporaryIn:nameTemplate:"
   627      DO NOT USE THIS FOR PLAIN FILES - IT IS UNSECURE use FileStream>>#newTemporaryIn:nameTemplate:"
   628 
   628 
   629     |nameString newTempFilename|
   629     |nameString newTempFilename|
   630 
   630 
   631     self isAbstract ifTrue:[
   631     self isAbstract ifTrue:[
   632 	^ ConcreteClass newTemporaryIn:aDirectoryOrNil nameTemplate:template
   632         ^ ConcreteClass newTemporaryIn:aDirectoryOrNil nameTemplate:template
   633     ].
   633     ].
   634 
   634 
   635     "although the above allows things to be redefined in concrete classes,
   635     "although the above allows things to be redefined in concrete classes,
   636      the following should work on all systems ..."
   636      the following should work on all systems ..."
   637 
   637 
   638     [
   638     [
   639 	"Use random numbers in order to improve the security
   639         "Use random numbers in order to improve the security
   640 	 by making the generated names less predictable"
   640          by making the generated names less predictable"
   641 	nameString := template bindWith:(OperatingSystem getProcessId) with:RandomGenerator new nextInteger.
   641         nameString := template bindWith:(OperatingSystem getProcessId) with:(RandomGenerator nextLettersOrDigits:4).
   642 
   642 
   643 	aDirectoryOrNil isNil ifTrue:[
   643         aDirectoryOrNil isNil ifTrue:[
   644 	    newTempFilename := self named:nameString
   644             newTempFilename := self named:nameString
   645 	] ifFalse:[
   645         ] ifFalse:[
   646 	    newTempFilename := aDirectoryOrNil asFilename construct:nameString
   646             newTempFilename := aDirectoryOrNil asFilename construct:nameString
   647 	]
   647         ]
   648     ] doWhile:[
   648     ] doWhile:[
   649 	"care for existing leftOver tempFiles
   649         "care for existing leftOver tempFiles
   650 	 from a previous boot of the OS
   650          from a previous boot of the OS
   651 	 i.e. my pid could be the same as when executed
   651          i.e. my pid could be the same as when executed
   652 	 the last time before system reboot ...)"
   652          the last time before system reboot ...)"
   653 
   653 
   654 	newTempFilename exists
   654         newTempFilename exists
   655     ].
   655     ].
   656     ^ newTempFilename
   656     ^ newTempFilename
   657 
   657 
   658     "temp files in '/tmp':
   658     "temp files in '/tmp':
   659 
   659