Skip to content

Commit

Permalink
dont hold a transaction during the move to trash
Browse files Browse the repository at this point in the history
because moving to trash can take a long time, keeping a transaction active for the duration can lead to issues

Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 authored and nickvergessen committed Oct 5, 2020
1 parent 3759bef commit f6bf519
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions apps/files_trashbin/lib/Trashbin.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,6 @@ public static function move2trash($file_path, $ownerOnly = false) {
$trashStorage->unlink($trashInternalPath);
}

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

try {
Expand All @@ -309,12 +307,16 @@ public static function move2trash($file_path, $ownerOnly = false) {
} else {
$sourceStorage->unlink($sourceInternalPath);
}
$connection->rollBack();

if ($sourceStorage->file_exists($sourceInternalPath)) {
// undo the cache move
$sourceStorage->getUpdater()->renameFromStorage($trashStorage, $trashInternalPath, $sourceInternalPath);
} else {
$trashStorage->getUpdater()->remove($trashInternalPath);
}
return false;
}

$connection->commit();

if ($moveSuccessful) {
$query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`user`) VALUES (?,?,?,?)");
$result = $query->execute([$filename, $timestamp, $location, $owner]);
Expand Down

0 comments on commit f6bf519

Please sign in to comment.