Skip to content

Commit 09b9f2f

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

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

apps/files_trashbin/lib/Trashbin.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
use OC\Files\Node\Folder;
5454
use OC\Files\Node\NonExistingFile;
5555
use OC\Files\Node\NonExistingFolder;
56-
use OC\Files\ObjectStore\ObjectStoreStorage;
5756
use OC\Files\View;
5857
use OC_User;
5958
use OCA\Files_Trashbin\AppInfo\Application;
@@ -67,6 +66,8 @@
6766
use OCP\Files\Node;
6867
use OCP\Files\NotFoundException;
6968
use OCP\Files\NotPermittedException;
69+
use OCP\Files\Storage\ILockingStorage;
70+
use OCP\Files\Storage\IStorage;
7071
use OCP\FilesMetadata\IFilesMetadataManager;
7172
use OCP\IConfig;
7273
use OCP\Lock\ILockingProvider;
@@ -290,11 +291,10 @@ public static function move2trash($file_path, $ownerOnly = false) {
290291
$trashPath = '/files_trashbin/files/' . static::getTrashFilename($filename, $timestamp);
291292
$gotLock = false;
292293

293-
while (!$gotLock) {
294+
do {
295+
/** @var ILockingStorage & IStorage $trashStorage */
296+
[$trashStorage, $trashInternalPath] = $ownerView->resolvePath($trashPath);
294297
try {
295-
/** @var \OC\Files\Storage\Storage $trashStorage */
296-
[$trashStorage, $trashInternalPath] = $ownerView->resolvePath($trashPath);
297-
298298
$trashStorage->acquireLock($trashInternalPath, ILockingProvider::LOCK_EXCLUSIVE, $lockingProvider);
299299
$gotLock = true;
300300
} catch (LockedException $e) {
@@ -305,7 +305,7 @@ public static function move2trash($file_path, $ownerOnly = false) {
305305

306306
$trashPath = '/files_trashbin/files/' . static::getTrashFilename($filename, $timestamp);
307307
}
308-
}
308+
} while (!$gotLock);
309309

310310
$sourceStorage = $sourceInfo->getStorage();
311311
$sourceInternalPath = $sourceInfo->getInternalPath();
@@ -319,13 +319,12 @@ public static function move2trash($file_path, $ownerOnly = false) {
319319
return false;
320320
}
321321

322-
323322
try {
324323
$moveSuccessful = true;
325324

326-
// when moving within the same object store, the cache update done below is enough to move the file
327-
if (!($trashStorage->instanceOfStorage(ObjectStoreStorage::class) && $trashStorage->getId() === $sourceStorage->getId())) {
328-
$trashStorage->moveFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
325+
$trashStorage->moveFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
326+
if ($sourceStorage->getCache()->inCache($sourceInternalPath)) {
327+
$trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
329328
}
330329
if ($trashStorage->getCache()->inCache($sourceInternalPath)) {
331330
$trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);

0 commit comments

Comments
 (0)