Skip to content

Commit 808cb1f

Browse files
Merge pull request #54971 from nextcloud/backport/54950/stable31
[stable31] fix(files_trashbin): Fix size propagation when moving file to trash
2 parents 5f4eb6b + b0a27e4 commit 808cb1f

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

apps/files_trashbin/lib/Trashbin.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,9 @@ public static function move2trash($file_path, $ownerOnly = false) {
293293
try {
294294
$moveSuccessful = true;
295295

296+
$inCache = $sourceStorage->getCache()->inCache($sourceInternalPath);
296297
$trashStorage->moveFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
297-
if ($sourceStorage->getCache()->inCache($sourceInternalPath)) {
298+
if ($inCache) {
298299
$trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
299300
}
300301
} catch (CopyRecursiveException $e) {

apps/files_trashbin/tests/TrashbinTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
use OCP\AppFramework\Utility\ITimeFactory;
2020
use OCP\Constants;
2121
use OCP\Files\FileInfo;
22+
use OCP\Files\IRootFolder;
2223
use OCP\IConfig;
24+
use OCP\Server;
2325
use OCP\Share\IShare;
2426

2527
/**
@@ -664,6 +666,28 @@ public function testRestoreFileIntoReadOnlySourceFolder(): void {
664666
}
665667
}
666668

669+
public function testTrashSizePropagation(): void {
670+
$view = new View('/' . self::TEST_TRASHBIN_USER1 . '/files_trashbin/files');
671+
672+
$userFolder = Server::get(IRootFolder::class)->getUserFolder(self::TEST_TRASHBIN_USER1);
673+
$file1 = $userFolder->newFile('foo.txt');
674+
$file1->putContent('1');
675+
676+
$this->assertTrue($userFolder->nodeExists('foo.txt'));
677+
$file1->delete();
678+
$this->assertFalse($userFolder->nodeExists('foo.txt'));
679+
$this->assertEquals(1, $view->getFileInfo('')->getSize());
680+
681+
$folder = $userFolder->newFolder('bar');
682+
$file2 = $folder->newFile('baz.txt');
683+
$file2->putContent('22');
684+
685+
$this->assertTrue($userFolder->nodeExists('bar'));
686+
$folder->delete();
687+
$this->assertFalse($userFolder->nodeExists('bar'));
688+
$this->assertEquals(3, $view->getFileInfo('')->getSize());
689+
}
690+
667691
/**
668692
* @param string $user
669693
* @param bool $create

0 commit comments

Comments
 (0)