Skip to content

Commit b8e9d3f

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

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

apps/files_trashbin/lib/Trashbin.php

Lines changed: 8 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,7 @@
6766
use OCP\Files\Node;
6867
use OCP\Files\NotFoundException;
6968
use OCP\Files\NotPermittedException;
69+
use OCP\Files\Storage\IStorage;
7070
use OCP\FilesMetadata\IFilesMetadataManager;
7171
use OCP\IConfig;
7272
use OCP\Lock\ILockingProvider;
@@ -290,11 +290,10 @@ public static function move2trash($file_path, $ownerOnly = false) {
290290
$trashPath = '/files_trashbin/files/' . static::getTrashFilename($filename, $timestamp);
291291
$gotLock = false;
292292

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

306305
$trashPath = '/files_trashbin/files/' . static::getTrashFilename($filename, $timestamp);
307306
}
308-
}
307+
} while (!$gotLock);
309308

310309
$sourceStorage = $sourceInfo->getStorage();
311310
$sourceInternalPath = $sourceInfo->getInternalPath();
@@ -319,13 +318,12 @@ public static function move2trash($file_path, $ownerOnly = false) {
319318
return false;
320319
}
321320

322-
323321
try {
324322
$moveSuccessful = true;
325323

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);
324+
$trashStorage->moveFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
325+
if ($sourceStorage->getCache()->inCache($sourceInternalPath)) {
326+
$trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
329327
}
330328
if ($trashStorage->getCache()->inCache($sourceInternalPath)) {
331329
$trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);

0 commit comments

Comments
 (0)