Skip to content

Commit c63c396

Browse files
committed
Fix PartialCleanDir
1 parent f04ea21 commit c63c396

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/PartialCleanDirs.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,25 @@ protected function cleanDir($dir, $keep)
245245
if ($keep) {
246246
array_splice($items, -$keep);
247247
}
248-
foreach ($items as $item) {
248+
while ($items) {
249+
$item = reset($items);
249250
try {
250251
// To delete a file we must have access rights on the parent
251252
// directory.
252253
$this->fs->chmod(dirname(realpath($item)), 0777, 0000, true);
253254
$this->fs->chmod($item, 0777, 0000, true);
254255
} catch (IOException $e) {
255-
// If chmod didn't work, try to remove anyway.
256+
// If chmod didn't work and the exception contains a path, try
257+
// to remove anyway.
258+
$path = $e->getPath();
259+
if ($path && realpath($path) !== realpath($item)) {
260+
$this->fs->remove($path);
261+
continue;
262+
}
263+
256264
}
257265
$this->fs->remove($item);
266+
array_shift($items);
258267
}
259268
}
260269
}

0 commit comments

Comments
 (0)