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 |