Skip to content

Commit 767db64

Browse files
Merge pull request #54972 from nextcloud/backport/54950/stable32
[stable32] fix(files_trashbin): Fix size propagation when moving file to trash
2 parents 2e9e5f6 + 2b57ab7 commit 767db64

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

apps/files_trashbin/lib/Trashbin.php

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

300+
$inCache = $sourceStorage->getCache()->inCache($sourceInternalPath);
300301
$trashStorage->moveFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
301-
if ($sourceStorage->getCache()->inCache($sourceInternalPath)) {
302+
if ($inCache) {
302303
$trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
303304
}
304305
} catch (CopyRecursiveException $e) {

apps/files_trashbin/tests/TrashbinTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,28 @@ public function testRestoreFileIntoReadOnlySourceFolder(): void {
656656
}
657657
}
658658

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

0 commit comments

Comments
 (0)