Skip to content

Commit c2c9276

Browse files
Copilotdermatz
andcommitted
#feature-request - Add readable check and improve unlink race condition handling
Co-authored-by: dermatz <6103201+dermatz@users.noreply.github.com>
1 parent 4e20c35 commit c2c9276

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/Console/Command/Static/CleanCommand.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,11 @@ private function removeDirectory(string $dir): bool
267267
return false;
268268
}
269269

270-
// Check if directory is writable
270+
// Check if directory is readable and writable
271+
if (!is_readable($dir)) {
272+
throw new \RuntimeException(sprintf('Directory is not readable: %s', $dir));
273+
}
274+
271275
if (!is_writable($dir)) {
272276
throw new \RuntimeException(sprintf('Directory is not writable: %s', $dir));
273277
}
@@ -299,9 +303,12 @@ private function removeDirectory(string $dir): bool
299303
if (!is_writable($path)) {
300304
throw new \RuntimeException(sprintf('File is not writable: %s', $path));
301305
}
302-
// Re-check file exists before unlinking
303-
if (file_exists($path) && !unlink($path)) {
304-
throw new \RuntimeException(sprintf('Failed to remove file: %s', $path));
306+
// Unlink directly - it will return false if file doesn't exist
307+
if (!unlink($path)) {
308+
// Only throw if file still exists (not a race condition)
309+
if (file_exists($path)) {
310+
throw new \RuntimeException(sprintf('Failed to remove file: %s', $path));
311+
}
305312
}
306313
}
307314
}

0 commit comments

Comments
 (0)