Skip to content

Commit 76fe051

Browse files
authored
Merge pull request #23185 from nextcloud/backport/23109/stable20
[stable20] dont hold a transaction during the move to trash
2 parents 853b17b + acef362 commit 76fe051

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

apps/files_trashbin/lib/Trashbin.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,6 @@ public static function move2trash($file_path, $ownerOnly = false) {
285285
$trashStorage->unlink($trashInternalPath);
286286
}
287287

288-
$connection = \OC::$server->getDatabaseConnection();
289-
$connection->beginTransaction();
290288
$trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
291289

292290
try {
@@ -310,12 +308,16 @@ public static function move2trash($file_path, $ownerOnly = false) {
310308
} else {
311309
$sourceStorage->unlink($sourceInternalPath);
312310
}
313-
$connection->rollBack();
311+
312+
if ($sourceStorage->file_exists($sourceInternalPath)) {
313+
// undo the cache move
314+
$sourceStorage->getUpdater()->renameFromStorage($trashStorage, $trashInternalPath, $sourceInternalPath);
315+
} else {
316+
$trashStorage->getUpdater()->remove($trashInternalPath);
317+
}
314318
return false;
315319
}
316320

317-
$connection->commit();
318-
319321
if ($moveSuccessful) {
320322
$query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`user`) VALUES (?,?,?,?)");
321323
$result = $query->execute([$filename, $timestamp, $location, $owner]);

0 commit comments

Comments
 (0)