]> 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>
Fri, 31 Jul 2020 15:33:03 +0000 (17:33 +0200)
Signed-off-by: Robin Appelman <robin@icewind.nl>
apps/files_trashbin/lib/Trashbin.php
tests/lib/Files/ViewTest.php

index 2647cb2f0f850ea438db97f9e3beb327363d18da..9eccebe64dfb745ff694c7b27e6440c2b5d7b782 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(array($filename, $timestamp, $location, $owner));
index 570500593755035c1ac4bf5d60c6039511cbc755..e394e0a8651f4b22044828964469de02c6469bf6 100644 (file)
@@ -242,7 +242,7 @@ class ViewTest extends \Test\TestCase {
                $this->assertEquals('/foo.txt', $folderView->getPath($id2));
        }
 
-       
+
        public function testGetPathNotExisting() {
                $this->expectException(\OCP\Files\NotFoundException::class);
 
@@ -1167,13 +1167,8 @@ class ViewTest extends \Test\TestCase {
                        ->setMethods(['fopen'])
                        ->getMock();
 
-               $storage2->expects($this->any())
-                       ->method('fopen')
-                       ->will($this->returnCallback(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');
@@ -1291,7 +1286,7 @@ class ViewTest extends \Test\TestCase {
                $this->assertNull($view->getRelativePath(null));
        }
 
-       
+
        public function testNullAsRoot() {
                $this->expectException(\InvalidArgumentException::class);