@@ -132,10 +132,12 @@ public function lock(string $key): void
132132 @mkdir ($ dir ); // @ - directory may already exist
133133 }
134134 $ handle = fopen ($ cacheFile , 'c+b ' );
135- if ($ handle ) {
136- $ this ->locks [$ key ] = $ handle ;
137- flock ($ handle , LOCK_EX );
135+ if (!$ handle ) {
136+ return ;
138137 }
138+
139+ $ this ->locks [$ key ] = $ handle ;
140+ flock ($ handle , LOCK_EX );
139141 }
140142
141143
@@ -269,12 +271,14 @@ public function clean(array $conditions): void
269271 } elseif ($ namespaces ) {
270272 foreach ($ namespaces as $ namespace ) {
271273 $ dir = $ this ->dir . '/_ ' . urlencode ($ namespace );
272- if (is_dir ($ dir )) {
273- foreach (Nette \Utils \Finder::findFiles ('_* ' )->in ($ dir ) as $ entry ) {
274- $ this ->delete ((string ) $ entry );
275- }
276- @rmdir ($ dir ); // may already contain new files
274+ if (!is_dir ($ dir )) {
275+ continue ;
276+ }
277+
278+ foreach (Nette \Utils \Finder::findFiles ('_* ' )->in ($ dir ) as $ entry ) {
279+ $ this ->delete ((string ) $ entry );
277280 }
281+ @rmdir ($ dir ); // may already contain new files
278282 }
279283 }
280284
@@ -358,12 +362,14 @@ private static function delete(string $file, $handle = null): void
358362 if (!$ handle ) {
359363 $ handle = @fopen ($ file , 'r+ ' ); // @ - file may not exist
360364 }
361- if ($ handle ) {
362- flock ($ handle , LOCK_EX );
363- ftruncate ($ handle , 0 );
364- flock ($ handle , LOCK_UN );
365- fclose ($ handle );
366- @unlink ($ file ); // @ - file may not already exist
365+ if (!$ handle ) {
366+ return ;
367367 }
368+
369+ flock ($ handle , LOCK_EX );
370+ ftruncate ($ handle , 0 );
371+ flock ($ handle , LOCK_UN );
372+ fclose ($ handle );
373+ @unlink ($ file ); // @ - file may not already exist
368374 }
369375}
0 commit comments