fix object store trashbin handling

object stores are "special" given how they interact with the cache on their own

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2020-07-30 16:31:56 +02:00
parent 8c3b22859c
commit c2c9a6a0e1
No known key found for this signature in database
GPG Key ID: 42B69D8A64526EFB
1 changed files with 10 additions and 3 deletions

View File

@ -44,6 +44,7 @@
namespace OCA\Files_Trashbin; namespace OCA\Files_Trashbin;
use OC\Files\Filesystem; use OC\Files\Filesystem;
use OC\Files\ObjectStore\ObjectStoreStorage;
use OC\Files\View; use OC\Files\View;
use OCA\Files_Trashbin\AppInfo\Application; use OCA\Files_Trashbin\AppInfo\Application;
use OCA\Files_Trashbin\Command\Expire; use OCA\Files_Trashbin\Command\Expire;
@ -278,16 +279,22 @@ class Trashbin {
/** @var \OC\Files\Storage\Storage $sourceStorage */ /** @var \OC\Files\Storage\Storage $sourceStorage */
[$sourceStorage, $sourceInternalPath] = $ownerView->resolvePath('/files/' . $ownerPath); [$sourceStorage, $sourceInternalPath] = $ownerView->resolvePath('/files/' . $ownerPath);
if ($trashStorage->file_exists($trashInternalPath)) {
$trashStorage->unlink($trashInternalPath);
}
$connection = \OC::$server->getDatabaseConnection(); $connection = \OC::$server->getDatabaseConnection();
$connection->beginTransaction(); $connection->beginTransaction();
$trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath); $trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
try { try {
$moveSuccessful = true; $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) { } catch (\OCA\Files_Trashbin\Exceptions\CopyRecursiveException $e) {
$moveSuccessful = false; $moveSuccessful = false;
if ($trashStorage->file_exists($trashInternalPath)) { if ($trashStorage->file_exists($trashInternalPath)) {