diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/models/item.php | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/core/models/item.php b/core/models/item.php index 9eaa2ed5..bd2d3024 100644 --- a/core/models/item.php +++ b/core/models/item.php @@ -97,23 +97,36 @@ class Item_Model extends ORM_MPTT { $original_resize_path = $this->resize_path(); $original_thumb_path = $this->thumb_path(); - // If there is no name, the path is invalid so don't try to delete parent::delete(); - if (!empty($this->name)) { - if ($this->is_album()) { - @dir::unlink($original_path); - @dir::unlink($original_resize_path); - @dir::unlink($original_thumb_path); - } else { - if (file_exists($original_path)) { - @unlink($original_path); - } - if (file_exists($original_resize_path)) { - @unlink($original_resize_path); - } - if (file_exists($original_thumb_path)) { - @unlink($original_thumb_path); - } + if (is_dir($original_path)) { + if (file_exists($original_path)) { + dir::unlink($original_path); + } + /* + * Both the thumb path and the resize path contain a path to .album.jpg + * So we need to try to delete both the path (may not exist) and its directory. + */ + if (file_exists($original_resize_path)) { + unlink($original_resize_path); + } + if (file_exists(dirname($original_resize_path))) { + dir::unlink(dirname($original_resize_path)); + } + if (file_exists($original_thumb_path)) { + unlink($original_thumb_path); + } + if (file_exists(dirname($original_thumb_path))) { + dir::unlink(dirname($original_thumb_path)); + } + } else { + if (file_exists($original_path)) { + unlink($original_path); + } + if (file_exists($original_resize_path)) { + unlink($original_resize_path); + } + if (file_exists($original_thumb_path)) { + unlink($original_thumb_path); } } } |