@@ -153,6 +153,16 @@ public function testCacheEntryGetters(): void {
153153 $ this ->assertEquals ($ entry ->getUnencryptedSize (), 100 );
154154 }
155155
156+ public function testGetUnencryptedSizeEncryptedZeroByte (): void {
157+ $ file1 = 'encrypted_zero ' ;
158+ $ this ->cache ->put ($ file1 , ['size ' => 8192 , 'mtime ' => 50 , 'mimetype ' => 'application/octet-stream ' , 'encrypted ' => 1 , 'unencrypted_size ' => 0 ]);
159+ $ entry = $ this ->cache ->get ($ file1 );
160+
161+ // getUnencryptedSize() must return 0 (the true plaintext size), not 8192 (the encrypted on-disk size)
162+ $ this ->assertEquals (0 , $ entry ->getUnencryptedSize ());
163+ $ this ->assertTrue ($ entry ->isEncrypted ());
164+ }
165+
156166 public function testPartial (): void {
157167 $ file1 = 'foo ' ;
158168
@@ -292,6 +302,39 @@ public function testEncryptedFolder(): void {
292302 $ this ->assertFalse ($ this ->cache ->inCache ('folder/bar ' ));
293303 }
294304
305+ public function testCalculateFolderSizeWithEncryptedZeroByte (): void {
306+ $ folder = 'enc_folder ' ;
307+ $ this ->cache ->put ($ folder , ['size ' => -1 , 'mtime ' => 20 , 'mimetype ' => ICacheEntry::DIRECTORY_MIMETYPE ]);
308+
309+ // Child 1: zero-byte encrypted file — on-disk 8192 (header only), plaintext 0
310+ $ child1 = $ folder . '/empty.enc ' ;
311+ $ this ->cache ->put ($ child1 , [
312+ 'size ' => 8192 ,
313+ 'mtime ' => 20 ,
314+ 'mimetype ' => 'application/octet-stream ' ,
315+ 'encrypted ' => 1 ,
316+ 'unencrypted_size ' => 0 ,
317+ ]);
318+
319+ // Child 2: non-zero encrypted file — opens the write-back gate ($unencryptedMax > 0)
320+ $ child2 = $ folder . '/small.enc ' ;
321+ $ this ->cache ->put ($ child2 , [
322+ 'size ' => 8292 ,
323+ 'mtime ' => 20 ,
324+ 'mimetype ' => 'application/octet-stream ' ,
325+ 'encrypted ' => 1 ,
326+ 'unencrypted_size ' => 100 ,
327+ ]);
328+
329+ $ this ->cache ->calculateFolderSize ($ folder );
330+
331+ $ entry = $ this ->cache ->get ($ folder );
332+ // Must sum plaintext sizes (0 + 100 = 100), not fall back to on-disk size for
333+ // the zero-byte child (8192 + 100 = 8292 with the old buggy code)
334+ $ this ->assertEquals (100 , $ entry ['unencrypted_size ' ], 'Folder unencrypted_size should sum plaintext sizes ' );
335+ $ this ->assertEquals (16484 , $ entry ['size ' ], 'Folder size should sum on-disk sizes (8192 + 8292) ' );
336+ }
337+
295338 public function testRootFolderSizeForNonHomeStorage (): void {
296339 $ dir1 = 'knownsize ' ;
297340 $ dir2 = 'unknownsize ' ;
0 commit comments