Skip to content

Commit 42ea824

Browse files
committed
fix: improve moving object store items to trashbin
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 00a27af commit 42ea824

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

apps/files_trashbin/lib/Trashbin.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use OC\Files\Node\Folder;
1616
use OC\Files\Node\NonExistingFile;
1717
use OC\Files\Node\NonExistingFolder;
18-
use OC\Files\ObjectStore\ObjectStoreStorage;
1918
use OC\Files\View;
2019
use OC_User;
2120
use OCA\Files_Trashbin\AppInfo\Application;
@@ -30,6 +29,7 @@
3029
use OCP\Files\NotFoundException;
3130
use OCP\Files\NotPermittedException;
3231
use OCP\Files\Storage\ILockingStorage;
32+
use OCP\Files\Storage\IStorage;
3333
use OCP\FilesMetadata\IFilesMetadataManager;
3434
use OCP\IConfig;
3535
use OCP\IDBConnection;
@@ -256,11 +256,10 @@ public static function move2trash($file_path, $ownerOnly = false) {
256256
$trashPath = '/files_trashbin/files/' . static::getTrashFilename($filename, $timestamp);
257257
$gotLock = false;
258258

259-
while (!$gotLock) {
259+
do {
260+
/** @var ILockingStorage & IStorage $trashStorage */
261+
[$trashStorage, $trashInternalPath] = $ownerView->resolvePath($trashPath);
260262
try {
261-
/** @var ILockingStorage $trashStorage */
262-
[$trashStorage, $trashInternalPath] = $ownerView->resolvePath($trashPath);
263-
264263
$trashStorage->acquireLock($trashInternalPath, ILockingProvider::LOCK_EXCLUSIVE, $lockingProvider);
265264
$gotLock = true;
266265
} catch (LockedException $e) {
@@ -271,7 +270,7 @@ public static function move2trash($file_path, $ownerOnly = false) {
271270

272271
$trashPath = '/files_trashbin/files/' . static::getTrashFilename($filename, $timestamp);
273272
}
274-
}
273+
} while (!$gotLock);
275274

276275
$sourceStorage = $sourceInfo->getStorage();
277276
$sourceInternalPath = $sourceInfo->getInternalPath();
@@ -285,14 +284,12 @@ public static function move2trash($file_path, $ownerOnly = false) {
285284
return false;
286285
}
287286

288-
$trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
289-
290287
try {
291288
$moveSuccessful = true;
292289

293-
// when moving within the same object store, the cache update done above is enough to move the file
294-
if (!($trashStorage->instanceOfStorage(ObjectStoreStorage::class) && $trashStorage->getId() === $sourceStorage->getId())) {
295-
$trashStorage->moveFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
290+
$trashStorage->moveFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
291+
if ($sourceStorage->getCache()->inCache($sourceInternalPath)) {
292+
$trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
296293
}
297294
} catch (\OCA\Files_Trashbin\Exceptions\CopyRecursiveException $e) {
298295
$moveSuccessful = false;

0 commit comments

Comments
 (0)