diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-01-21 16:29:52 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-01-23 12:20:54 +0100 |
commit | 67f1534e0fd7c14e97fe5b17bd92aa2277520604 (patch) | |
tree | 52b863953936295764a52036cebc1162a6507dfd /apps/files_trashbin/lib | |
parent | 5fb8a4715d6ed34b1d94c5508700f3c488c0f734 (diff) | |
download | nextcloud-server-67f1534e0fd7c14e97fe5b17bd92aa2277520604.tar.gz nextcloud-server-67f1534e0fd7c14e97fe5b17bd92aa2277520604.zip |
Call final unlink in trash wrapper's storage
In the case of cross-storage delete, the files are copied to the trash,
then deleted. The final delete on the source storage would still reach
the trash wrapper.
This fix makes forwards that second call to the wrapped storage to make
the final delete work.
It fixes the issue with remote shares, local shares and external
storage.
Also, it uses a new function "renameRecursive" that renames the files
and preserves the mtimes (like "copy_recursive" did in the past))
Diffstat (limited to 'apps/files_trashbin/lib')
-rw-r--r-- | apps/files_trashbin/lib/storage.php | 3 | ||||
-rw-r--r-- | apps/files_trashbin/lib/trashbin.php | 43 |
2 files changed, 44 insertions, 2 deletions
diff --git a/apps/files_trashbin/lib/storage.php b/apps/files_trashbin/lib/storage.php index aa5d48b5fbe..5036a260d0c 100644 --- a/apps/files_trashbin/lib/storage.php +++ b/apps/files_trashbin/lib/storage.php @@ -46,6 +46,9 @@ class Storage extends Wrapper { if (count($parts) > 3 && $parts[2] === 'files') { $filesPath = implode('/', array_slice($parts, 3)); $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); } diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php index f5cebea6b78..1833936ea26 100644 --- a/apps/files_trashbin/lib/trashbin.php +++ b/apps/files_trashbin/lib/trashbin.php @@ -166,8 +166,7 @@ class Trashbin { \OC_FileProxy::$enabled = false; $trashPath = '/files_trashbin/files/' . $filename . '.d' . $timestamp; try { - $sizeOfAddedFiles = $view->filesize('/files/' . $file_path); - $view->rename('/files/' . $file_path, $trashPath); + $sizeOfAddedFiles = self::renameRecursive('/files/'.$file_path, $trashPath, $view); } catch (\OCA\Files_Trashbin\Exceptions\CopyRecursiveException $e) { $sizeOfAddedFiles = false; if ($view->file_exists($trashPath)) { @@ -807,6 +806,46 @@ class Trashbin { } /** + * recursive rename a whole directory and preserve timestamps + * + * @param string $source source path, relative to the users files directory + * @param string $destination destination path relative to the users root directoy + * @param \OC\Files\View $view file view for the users root directory + * @return int + * @throws Exceptions\CopyRecursiveException + */ + private static function renameRecursive($source, $destination, \OC\Files\View $view) { + $size = 0; + if ($view->is_dir($source)) { + $view->mkdir($destination); + $view->touch($destination, $view->filemtime($source)); + foreach ($view->getDirectoryContent($source) as $i) { + $pathDir = $source . '/' . $i['name']; + if ($view->is_dir($pathDir)) { + $size += self::renameRecursive($pathDir, $destination . '/' . $i['name'], $view); + } else { + $size += $view->filesize($pathDir); + $mtime = $view->filemtime($pathDir); + $result = $view->rename($pathDir, $destination . '/' . $i['name']); + if (!$result) { + throw new \OCA\Files_Trashbin\Exceptions\CopyRecursiveException(); + } + $view->touch($destination . '/' . $i['name'], $mtime); + } + } + } else { + $size += $view->filesize($source); + $mtime = $view->filemtime($source); + $result = $view->rename($source, $destination); + if (!$result) { + throw new \OCA\Files_Trashbin\Exceptions\CopyRecursiveException(); + } + $view->touch($destination, $mtime); + } + return $size; + } + + /** * find all versions which belong to the file we want to restore * * @param string $filename name of the file which should be restored |