diff options
author | Morris Jobke <hey@morrisjobke.de> | 2020-07-31 10:10:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-31 10:10:33 +0200 |
commit | e19bbce7f6e243e0f42633008f4fad02f21732df (patch) | |
tree | 8fda8701c4e88cd36b6b1e0360037a9fd7bd9597 | |
parent | 0aac884f38afda522fb047c3aff9a14470926412 (diff) | |
parent | c2c9a6a0e17c5421c2a6941f7151cf05981636fa (diff) | |
download | nextcloud-server-e19bbce7f6e243e0f42633008f4fad02f21732df.tar.gz nextcloud-server-e19bbce7f6e243e0f42633008f4fad02f21732df.zip |
Merge pull request #22060 from nextcloud/trashbin-s3-fixes
Object store trashbin fixes
-rw-r--r-- | apps/files_trashbin/lib/Trashbin.php | 13 | ||||
-rw-r--r-- | lib/private/Files/Cache/Updater.php | 6 |
2 files changed, 15 insertions, 4 deletions
diff --git a/apps/files_trashbin/lib/Trashbin.php b/apps/files_trashbin/lib/Trashbin.php index db00a7ed272..db6fa35e85c 100644 --- a/apps/files_trashbin/lib/Trashbin.php +++ b/apps/files_trashbin/lib/Trashbin.php @@ -44,6 +44,7 @@ namespace OCA\Files_Trashbin; use OC\Files\Filesystem; +use OC\Files\ObjectStore\ObjectStoreStorage; use OC\Files\View; use OCA\Files_Trashbin\AppInfo\Application; use OCA\Files_Trashbin\Command\Expire; @@ -278,16 +279,22 @@ class Trashbin { /** @var \OC\Files\Storage\Storage $sourceStorage */ [$sourceStorage, $sourceInternalPath] = $ownerView->resolvePath('/files/' . $ownerPath); + + if ($trashStorage->file_exists($trashInternalPath)) { + $trashStorage->unlink($trashInternalPath); + } + $connection = \OC::$server->getDatabaseConnection(); $connection->beginTransaction(); $trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath); try { $moveSuccessful = true; - if ($trashStorage->file_exists($trashInternalPath)) { - $trashStorage->unlink($trashInternalPath); + + // when moving within the same object store, the cache update done above is enough to move the file + if (!($trashStorage->instanceOfStorage(ObjectStoreStorage::class) && $trashStorage->getId() === $sourceStorage->getId())) { + $trashStorage->moveFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath); } - $trashStorage->moveFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath); } catch (\OCA\Files_Trashbin\Exceptions\CopyRecursiveException $e) { $moveSuccessful = false; if ($trashStorage->file_exists($trashInternalPath)) { diff --git a/lib/private/Files/Cache/Updater.php b/lib/private/Files/Cache/Updater.php index b6a0e62a88a..79501d910e5 100644 --- a/lib/private/Files/Cache/Updater.php +++ b/lib/private/Files/Cache/Updater.php @@ -201,7 +201,11 @@ class Updater implements IUpdater { $this->cache->moveFromCache($sourceCache, $source, $target); } - if (pathinfo($source, PATHINFO_EXTENSION) !== pathinfo($target, PATHINFO_EXTENSION) && $sourceInfo->getMimeType() !== FileInfo::MIMETYPE_FOLDER) { + $sourceExtension = pathinfo($source, PATHINFO_EXTENSION); + $targetExtension = pathinfo($target, PATHINFO_EXTENSION); + $targetIsTrash = preg_match("/d\d+/", $targetExtension); + + if ($sourceExtension !== $targetExtension && $sourceInfo->getMimeType() !== FileInfo::MIMETYPE_FOLDER && !$targetIsTrash) { // handle mime type change $mimeType = $this->storage->getMimeType($target); $fileId = $this->cache->getId($target); |