diff options
Diffstat (limited to 'apps/files_trashbin/lib/storage.php')
-rw-r--r-- | apps/files_trashbin/lib/storage.php | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/apps/files_trashbin/lib/storage.php b/apps/files_trashbin/lib/storage.php index aa5d48b5fbe..21b4e56d0bb 100644 --- a/apps/files_trashbin/lib/storage.php +++ b/apps/files_trashbin/lib/storage.php @@ -23,6 +23,7 @@ namespace OCA\Files_Trashbin; +use OC\Files\Filesystem; use OC\Files\Storage\Wrapper\Wrapper; class Storage extends Wrapper { @@ -32,20 +33,54 @@ class Storage extends Wrapper { // move files across storages private $deletedFiles = array(); + /** + * Disable trash logic + * + * @var bool + */ + private static $disableTrash = false; + function __construct($parameters) { $this->mountPoint = $parameters['mountPoint']; parent::__construct($parameters); } + /** + * @internal + */ + public static function preRenameHook($params) { + // in cross-storage cases, a rename is a copy + unlink, + // that last unlink must not go to trash + self::$disableTrash = true; + } + + /** + * @internal + */ + public static function postRenameHook($params) { + self::$disableTrash = false; + } + + /** + * Deletes the given file by moving it into the trashbin. + * + * @param string $path + */ public function unlink($path) { - $normalized = \OC\Files\Filesystem::normalizePath($this->mountPoint . '/' . $path); + if (self::$disableTrash) { + return $this->storage->unlink($path); + } + $normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path); $result = true; if (!isset($this->deletedFiles[$normalized])) { + $view = Filesystem::getView(); $this->deletedFiles[$normalized] = $normalized; - $parts = explode('/', $normalized); - if (count($parts) > 3 && $parts[2] === 'files') { - $filesPath = implode('/', array_slice($parts, 3)); + if ($filesPath = $view->getRelativePath($normalized)) { + $filesPath = trim($filesPath, '/'); $result = \OCA\Files_Trashbin\Trashbin::move2trash($filesPath); + // in cross-storage cases the file will be copied + // but not deleted, so we delete it here + $this->storage->unlink($path); } else { $result = $this->storage->unlink($path); } |