]> source.dussan.org Git - nextcloud-server.git/commitdiff
rollback cache rename if trashbin move fails
authorRobin Appelman <robin@icewind.nl>
Tue, 30 Jun 2020 14:09:50 +0000 (16:09 +0200)
committerRobin Appelman <robin@icewind.nl>
Thu, 23 Jul 2020 13:24:48 +0000 (15:24 +0200)
Signed-off-by: Robin Appelman <robin@icewind.nl>
apps/files_trashbin/lib/Trashbin.php
tests/lib/Files/ViewTest.php

index e23368f825bee2f4f40bbeed318b4012c61d8a69..db00a7ed272888f4ff38ba030c13bfe0e4449182 100644 (file)
@@ -278,6 +278,8 @@ class Trashbin {
                /** @var \OC\Files\Storage\Storage $sourceStorage */
                [$sourceStorage, $sourceInternalPath] = $ownerView->resolvePath('/files/' . $ownerPath);
 
+               $connection = \OC::$server->getDatabaseConnection();
+               $connection->beginTransaction();
                $trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
 
                try {
@@ -300,9 +302,12 @@ class Trashbin {
                        } else {
                                $sourceStorage->unlink($sourceInternalPath);
                        }
+                       $connection->rollBack();
                        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]);
index 036fc038a600efffef53e643e86946bed6f11cae..ae6c4b22dec565ffa99c1a30f919c0ca68f02e4c 100644 (file)
@@ -1167,13 +1167,8 @@ class ViewTest extends \Test\TestCase {
                        ->setMethods(['fopen'])
                        ->getMock();
 
-               $storage2->expects($this->any())
-                       ->method('fopen')
-                       ->willReturnCallback(function ($path, $mode) use ($storage2) {
-                               /** @var \PHPUnit_Framework_MockObject_MockObject | \OC\Files\Storage\Temporary $storage2 */
-                               $source = fopen($storage2->getSourcePath($path), $mode);
-                               return Quota::wrap($source, 9);
-                       });
+               $storage2->method('writeStream')
+                       ->willReturn(0);
 
                $storage1->mkdir('sub');
                $storage1->file_put_contents('foo.txt', '0123456789ABCDEFGH');