From 607662d66be4361c20322c7db84f9e7b1c529ba2 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sat, 24 Oct 2009 10:08:48 -0700 Subject: When an item is renamed or move insure that the target file name doesn't exist. fixes ticket #694 --- modules/gallery/models/item.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'modules/gallery/models') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 6f0e3525..c210fb54 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -99,6 +99,10 @@ class Item_Model extends ORM_MPTT { throw new Exception("@todo INVALID_MOVE_TYPE $target->type"); } + if (file_exists($target_file = "{$target->file_path()}/$this->name")) { + throw new Exception("@todo INVALID_MOVE_TARGET_EXISTS: $target_file"); + } + if ($this->id == 1) { throw new Exception("@todo INVALID_SOURCE root album"); } @@ -147,6 +151,10 @@ class Item_Model extends ORM_MPTT { $old_relative_path = urldecode($this->relative_path()); $new_relative_path = dirname($old_relative_path) . "/" . $new_name; + if (file_exists(VARPATH . "albums/$new_relative_path")) { + throw new Exception("@todo INVALID_RENAME_FILE_EXISTS: $new_relative_path"); + } + @rename(VARPATH . "albums/$old_relative_path", VARPATH . "albums/$new_relative_path"); @rename(VARPATH . "resizes/$old_relative_path", VARPATH . "resizes/$new_relative_path"); @rename(VARPATH . "thumbs/$old_relative_path", VARPATH . "thumbs/$new_relative_path"); -- cgit v1.2.3