MDL-45654 cron: fix non-empty directories deletion

Remove errors when attempting to delete non-empty directories when
child directories do not get removed since the mtime was updated when
files were removed from the child directory.
This commit is contained in:
Rod Norfor 2014-05-21 17:12:02 +01:00
parent a929fd50f9
commit 75b70ab6cd
2 changed files with 83 additions and 56 deletions

View file

@ -60,8 +60,11 @@ class file_temp_cleanup_task extends scheduled_task {
// Check if file or directory is older than the given time.
if ($iter->getMTime() < $time) {
if ($iter->isDir() && !$iter->isDot()) {
if (@rmdir($node) === false) {
mtrace("Failed removing directory '$node'.");
// Don't attempt to delete the directory if it isn't empty.
if (!glob($node. DIRECTORY_SEPARATOR . '*')) {
if (@rmdir($node) === false) {
mtrace("Failed removing directory '$node'.");
}
}
}
if ($iter->isFile()) {