diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-05-12 13:14:57 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-05-15 12:42:27 +0200 |
commit | f86699cd48c310be3e3f6fa625ea013e9d7cbe0e (patch) | |
tree | 198948592e8af3052ae695a1e1e68c157dda3427 /apps/files_trashbin/lib | |
parent | e1923bac07305fadb136f80ca098cd9f7e454f22 (diff) | |
download | nextcloud-server-f86699cd48c310be3e3f6fa625ea013e9d7cbe0e.tar.gz nextcloud-server-f86699cd48c310be3e3f6fa625ea013e9d7cbe0e.zip |
Fix restoring files from trash with unique name
When restoring a file, a unique name needs to be generated if a file
with the same name already exists.
Also fixed the restore() method to return false if the file to restore
does not exist.
Added unit tests to cover restore cases.
Diffstat (limited to 'apps/files_trashbin/lib')
-rw-r--r-- | apps/files_trashbin/lib/trashbin.php | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php index 1c880735b5a..31d77c01c91 100644 --- a/apps/files_trashbin/lib/trashbin.php +++ b/apps/files_trashbin/lib/trashbin.php @@ -277,16 +277,16 @@ class Trashbin { } /** - * restore files from trash bin + * Restore a file or folder from trash bin * - * @param string $file path to the deleted file - * @param string $filename name of the file - * @param int $timestamp time when the file was deleted + * @param string $file path to the deleted file/folder relative to "files_trashbin/files/", + * including the timestamp suffix ".d12345678" + * @param string $filename name of the file/folder + * @param int $timestamp time when the file/folder was deleted * - * @return bool + * @return bool true on success, false otherwise */ public static function restore($file, $filename, $timestamp) { - $user = \OCP\User::getUser(); $view = new \OC\Files\View('/' . $user); @@ -311,6 +311,9 @@ class Trashbin { $source = \OC\Files\Filesystem::normalizePath('files_trashbin/files/' . $file); $target = \OC\Files\Filesystem::normalizePath('files/' . $location . '/' . $uniqueFilename); + if (!$view->file_exists($source)) { + return false; + } $mtime = $view->filemtime($source); // restore file @@ -762,6 +765,8 @@ class Trashbin { $name = pathinfo($filename, PATHINFO_FILENAME); $l = \OC::$server->getL10N('files_trashbin'); + $location = '/' . trim($location, '/'); + // if extension is not empty we set a dot in front of it if ($ext !== '') { $ext = '.' . $ext; |