diff options
Diffstat (limited to 'apps/files_trashbin/lib')
-rw-r--r-- | apps/files_trashbin/lib/storage.php | 35 | ||||
-rw-r--r-- | apps/files_trashbin/lib/trashbin.php | 17 |
2 files changed, 41 insertions, 11 deletions
diff --git a/apps/files_trashbin/lib/storage.php b/apps/files_trashbin/lib/storage.php index 418d7d2f1fd..006971fb242 100644 --- a/apps/files_trashbin/lib/storage.php +++ b/apps/files_trashbin/lib/storage.php @@ -81,14 +81,39 @@ class Storage extends Wrapper { /** * Deletes the given file by moving it into the trashbin. * - * @param string $path + * @param string $path path of file or folder to delete + * + * @return bool true if the operation succeeded, false otherwise */ public function unlink($path) { + return $this->doDelete($path, 'unlink'); + } + + /** + * Deletes the given folder by moving it into the trashbin. + * + * @param string $path path of folder to delete + * + * @return bool true if the operation succeeded, false otherwise + */ + public function rmdir($path) { + return $this->doDelete($path, 'rmdir'); + } + + /** + * Run the delete operation with the given method + * + * @param string $path path of file or folder to delete + * @param string $method either "unlink" or "rmdir" + * + * @return bool true if the operation succeeded, false otherwise + */ + private function doDelete($path, $method) { if (self::$disableTrash || !\OC_App::isEnabled('files_trashbin') || (pathinfo($path, PATHINFO_EXTENSION) === 'part') ) { - return $this->storage->unlink($path); + return call_user_func_array([$this->storage, $method], [$path]); } $normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path); $result = true; @@ -101,14 +126,14 @@ class Storage extends Wrapper { // in cross-storage cases the file will be copied // but not deleted, so we delete it here if ($result) { - $this->storage->unlink($path); + call_user_func_array([$this->storage, $method], [$path]); } } else { - $result = $this->storage->unlink($path); + $result = call_user_func_array([$this->storage, $method], [$path]); } unset($this->deletedFiles[$normalized]); } else if ($this->storage->file_exists($path)) { - $result = $this->storage->unlink($path); + $result = call_user_func_array([$this->storage, $method], [$path]); } return $result; 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; |