From 4dbd81cbdea371b98c1195bfb46d4ec60a4dd82c Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Thu, 21 May 2015 16:01:27 +0200 Subject: \c\file::clean_stale_files: Increase robustness Delete files not matching our pattern and be forgiving if directories are cleaned up by mfile->delete_data_id. Signed-off-by: Florian Pritz --- application/controllers/file.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'application/controllers/file.php') diff --git a/application/controllers/file.php b/application/controllers/file.php index a653d8e74..41a2c4908 100644 --- a/application/controllers/file.php +++ b/application/controllers/file.php @@ -1063,7 +1063,12 @@ class File extends MY_Controller { continue; } - list($hash, $storage_id) = explode("-", $file); + try { + list($hash, $storage_id) = explode("-", $file); + } catch (\ErrorException $e) { + unlink($upload_path."/".$dir."/".$file); + continue; + } $query = $this->db->select('hash, id') ->from('file_storage') @@ -1074,7 +1079,6 @@ class File extends MY_Controller { if (empty($query)) { $this->mfile->delete_data_id($file); - unlink($upload_path."/".$dir."/".$file); } else { $empty = false; } @@ -1082,7 +1086,7 @@ class File extends MY_Controller { closedir($dh); - if ($empty) { + if ($empty && file_exists($upload_path."/".$dir)) { rmdir($upload_path."/".$dir); } } -- cgit v1.2.3-24-g4f1b