Skip to content

Commit

Permalink
fix: improve moving object store items to trashbin
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Oct 4, 2024
1 parent ead4873 commit b8e9d3f
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions apps/files_trashbin/lib/Trashbin.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
use OC\Files\Node\Folder;
use OC\Files\Node\NonExistingFile;
use OC\Files\Node\NonExistingFolder;
use OC\Files\ObjectStore\ObjectStoreStorage;
use OC\Files\View;
use OC_User;
use OCA\Files_Trashbin\AppInfo\Application;
Expand All @@ -67,6 +66,7 @@
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\Files\Storage\IStorage;
use OCP\FilesMetadata\IFilesMetadataManager;
use OCP\IConfig;
use OCP\Lock\ILockingProvider;
Expand Down Expand Up @@ -290,11 +290,10 @@ public static function move2trash($file_path, $ownerOnly = false) {
$trashPath = '/files_trashbin/files/' . static::getTrashFilename($filename, $timestamp);
$gotLock = false;

while (!$gotLock) {
do {
/** @var IStorage $trashStorage */
[$trashStorage, $trashInternalPath] = $ownerView->resolvePath($trashPath);
try {
/** @var \OC\Files\Storage\Storage $trashStorage */
[$trashStorage, $trashInternalPath] = $ownerView->resolvePath($trashPath);

$trashStorage->acquireLock($trashInternalPath, ILockingProvider::LOCK_EXCLUSIVE, $lockingProvider);

Check failure on line 297 in apps/files_trashbin/lib/Trashbin.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedInterfaceMethod

apps/files_trashbin/lib/Trashbin.php:297:20: UndefinedInterfaceMethod: Method OCP\Files\Storage\IStorage::acquireLock does not exist (see https://psalm.dev/181)
$gotLock = true;
} catch (LockedException $e) {
Expand All @@ -305,7 +304,7 @@ public static function move2trash($file_path, $ownerOnly = false) {

$trashPath = '/files_trashbin/files/' . static::getTrashFilename($filename, $timestamp);
}
}
} while (!$gotLock);

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


try {
$moveSuccessful = true;

// when moving within the same object store, the cache update done below 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);
if ($sourceStorage->getCache()->inCache($sourceInternalPath)) {
$trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
}
if ($trashStorage->getCache()->inCache($sourceInternalPath)) {
$trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
Expand Down

0 comments on commit b8e9d3f

Please sign in to comment.