File tree Expand file tree Collapse file tree 2 files changed +26
-6
lines changed
Expand file tree Collapse file tree 2 files changed +26
-6
lines changed Original file line number Diff line number Diff line change 1515class FileSequence implements ISequence {
1616 /** Number of files to use */
1717 private const NB_FILES = 20 ;
18+ /** Lock file directory **/
19+ public const LOCK_FILE_DIRECTORY = 'sfi_file_sequence ' ;
1820 /** Lock filename format **/
1921 private const LOCK_FILE_FORMAT = 'seq-%03d.lock ' ;
2022 /** Delete sequences after SEQUENCE_TTL seconds **/
@@ -25,7 +27,25 @@ class FileSequence implements ISequence {
2527 public function __construct (
2628 ITempManager $ tempManager ,
2729 ) {
28- $ this ->workDir = $ tempManager ->getTemporaryFolder ('.snowflakes ' );
30+ $ this ->workDir = $ tempManager ->getTempBaseDir () . '/ ' . self ::LOCK_FILE_DIRECTORY ;
31+ $ this ->ensureWorkdirExists ();
32+ }
33+
34+ private function ensureWorkdirExists (): void {
35+ if (is_dir ($ this ->workDir )) {
36+ return ;
37+ }
38+
39+ if (@mkdir ($ this ->workDir , 0700 )) {
40+ return ;
41+ }
42+
43+ // Maybe the directory was created in the meantime
44+ if (is_dir ($ this ->workDir )) {
45+ return ;
46+ }
47+
48+ throw new \Exception ('Fail to create file sequence directory ' );
2949 }
3050
3151 #[Override]
Original file line number Diff line number Diff line change @@ -20,16 +20,16 @@ class FileSequenceTest extends ISequenceBase {
2020
2121 public function setUp ():void {
2222 $ tempManager = $ this ->createMock (ITempManager::class);
23- $ this ->path = uniqid (sys_get_temp_dir () . '/php_test_seq_ ' , true );
24- mkdir ($ this ->path );
25- $ tempManager ->method ('getTemporaryFolder ' )->willReturn ($ this ->path );
23+ $ this ->path = sys_get_temp_dir ();
24+ $ tempManager ->method ('getTempBaseDir ' )->willReturn ($ this ->path );
2625 $ this ->sequence = new FileSequence ($ tempManager );
2726 }
2827
2928 public function tearDown ():void {
30- foreach (glob ($ this ->path . '/* ' ) as $ file ) {
29+ $ lockDirectory = $ this ->path . '/ ' . FileSequence::LOCK_FILE_DIRECTORY ;
30+ foreach (glob ($ lockDirectory . '/* ' ) as $ file ) {
3131 unlink ($ file );
3232 }
33- rmdir ($ this -> path );
33+ rmdir ($ lockDirectory );
3434 }
3535}
You can’t perform that action at this time.
0 commit comments