Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/private/Files/FileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function getSize($includeMounts = true) {
if ($includeMounts) {
$this->updateEntryFromSubMounts();

if ($this->isEncrypted() && isset($this->data['unencrypted_size'])) {
if (self::hasPlaintextSize($this->data)) {
return $this->data['unencrypted_size'];
} else {
return isset($this->data['size']) ? 0 + $this->data['size'] : 0;
Expand Down Expand Up @@ -342,7 +342,7 @@ public function addSubEntry($data, $entryPath) {
if (!$data) {
return;
}
$hasUnencryptedSize = !empty($data['encrypted']) && isset($data['unencrypted_size']);
$hasUnencryptedSize = self::hasPlaintextSize($data);
if ($hasUnencryptedSize) {
$subSize = $data['unencrypted_size'];
} else {
Expand Down
24 changes: 24 additions & 0 deletions tests/lib/Files/FileInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ public function testGetSizeEncryptedNonZero(): void {
$this->assertSame(5000, $info->getSize(false));
}

public function testGetSizeEncryptedFolderWithoutPlaintextSize(): void {
// End-to-end encrypted folders carry the `encrypted` flag but never a plaintext size,
// so the propagated `size` has to be reported instead of the unset `unencrypted_size`
$info = $this->makeFileInfo([
'encrypted' => true,
'mimetype' => FileInfo::MIMETYPE_FOLDER,
'size' => 8192,
'unencrypted_size' => 0,
]);
$this->assertSame(8192, $info->getSize(true));
$this->assertSame(8192, $info->getSize(false));
}

public function testGetSizeEncryptedFolderWithPlaintextSize(): void {
$info = $this->makeFileInfo([
'encrypted' => true,
'mimetype' => FileInfo::MIMETYPE_FOLDER,
'size' => 8192,
'unencrypted_size' => 5000,
]);
$this->assertSame(5000, $info->getSize(true));
$this->assertSame(5000, $info->getSize(false));
}

public function testGetSizeNonEncrypted(): void {
$info = $this->makeFileInfo(['encrypted' => false, 'size' => 100]);
$this->assertSame(100, $info->getSize(true));
Expand Down