Skip to content

Commit 3e5b43c

Browse files
provokateurinjuliusknorr
authored andcommitted
fix(files_trashbin): Fix size propagation when moving file to trash
Signed-off-by: provokateurin <[email protected]>
1 parent bb8c800 commit 3e5b43c

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

apps/files_trashbin/lib/Trashbin.php

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

290+
$inCache = $sourceStorage->getCache()->inCache($sourceInternalPath);
290291
$trashStorage->moveFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
291-
if ($sourceStorage->getCache()->inCache($sourceInternalPath)) {
292+
if ($inCache) {
292293
$trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
293294
}
294295
} catch (\OCA\Files_Trashbin\Exceptions\CopyRecursiveException $e) {

apps/files_trashbin/tests/TrashbinTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,28 @@ public function testRestoreFileIntoReadOnlySourceFolder() {
653653
}
654654
}
655655

656+
public function testTrashSizePropagation(): void {
657+
$view = new \OC\Files\View('/' . self::TEST_TRASHBIN_USER1 . '/files_trashbin/files');
658+
659+
$userFolder = \OCP\Server::get(\OCP\Files\IRootFolder::class)->getUserFolder(self::TEST_TRASHBIN_USER1);
660+
$file1 = $userFolder->newFile('foo.txt');
661+
$file1->putContent('1');
662+
663+
$this->assertTrue($userFolder->nodeExists('foo.txt'));
664+
$file1->delete();
665+
$this->assertFalse($userFolder->nodeExists('foo.txt'));
666+
$this->assertEquals(1, $view->getFileInfo('')->getSize());
667+
668+
$folder = $userFolder->newFolder('bar');
669+
$file2 = $folder->newFile('baz.txt');
670+
$file2->putContent('22');
671+
672+
$this->assertTrue($userFolder->nodeExists('bar'));
673+
$folder->delete();
674+
$this->assertFalse($userFolder->nodeExists('bar'));
675+
$this->assertEquals(3, $view->getFileInfo('')->getSize());
676+
}
677+
656678
/**
657679
* @param string $user
658680
* @param bool $create

0 commit comments

Comments
 (0)