Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  Fix PartialCleanDir
  • Loading branch information
Jelle-S committed Mar 3, 2017
2 parents e29558c + c63c396 commit 20f53e3
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/PartialCleanDirs.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,25 @@ protected function cleanDir($dir, $keep)
if ($keep) {
array_splice($items, -$keep);
}
foreach ($items as $item) {
while ($items) {
$item = reset($items);
try {
// To delete a file we must have access rights on the parent
// directory.
$this->fs->chmod(dirname(realpath($item)), 0777, 0000, true);
$this->fs->chmod($item, 0777, 0000, true);
} catch (IOException $e) {
// If chmod didn't work, try to remove anyway.
// If chmod didn't work and the exception contains a path, try
// to remove anyway.
$path = $e->getPath();
if ($path && realpath($path) !== realpath($item)) {
$this->fs->remove($path);
continue;
}

}
$this->fs->remove($item);
array_shift($items);
}
}
}

0 comments on commit 20f53e3

Please sign in to comment.