Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve moving object store items to trashbin #48224

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions apps/files_trashbin/lib/Trashbin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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 @@ -30,6 +29,7 @@
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\Files\Storage\ILockingStorage;
use OCP\Files\Storage\IStorage;
use OCP\FilesMetadata\IFilesMetadataManager;
use OCP\IConfig;
use OCP\IDBConnection;
Expand Down Expand Up @@ -256,11 +256,10 @@ public static function move2trash($file_path, $ownerOnly = false) {
$trashPath = '/files_trashbin/files/' . static::getTrashFilename($filename, $timestamp);
$gotLock = false;

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

$trashStorage->acquireLock($trashInternalPath, ILockingProvider::LOCK_EXCLUSIVE, $lockingProvider);
$gotLock = true;
} catch (LockedException $e) {
Expand All @@ -271,7 +270,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 @@ -285,14 +284,12 @@ public static function move2trash($file_path, $ownerOnly = false) {
return false;
}

$trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);

try {
$moveSuccessful = true;

// 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);
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
if ($sourceStorage->getCache()->inCache($sourceInternalPath)) {
$trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
}
} catch (\OCA\Files_Trashbin\Exceptions\CopyRecursiveException $e) {
$moveSuccessful = false;
Expand Down
Loading