@@ -150,6 +150,16 @@ public function testCacheEntryGetters(): void {
150150 $ this ->assertEquals ($ entry ->getUnencryptedSize (), 100 );
151151 }
152152
153+ public function testGetUnencryptedSizeEncryptedZeroByte (): void {
154+ $ file1 = 'encrypted_zero ' ;
155+ $ this ->cache ->put ($ file1 , ['size ' => 8192 , 'mtime ' => 50 , 'mimetype ' => 'application/octet-stream ' , 'encrypted ' => 1 , 'unencrypted_size ' => 0 ]);
156+ $ entry = $ this ->cache ->get ($ file1 );
157+
158+ // getUnencryptedSize() must return 0 (the true plaintext size), not 8192 (the encrypted on-disk size)
159+ $ this ->assertEquals (0 , $ entry ->getUnencryptedSize ());
160+ $ this ->assertTrue ($ entry ->isEncrypted ());
161+ }
162+
153163 public function testPartial (): void {
154164 $ file1 = 'foo ' ;
155165
@@ -289,6 +299,39 @@ public function testEncryptedFolder(): void {
289299 $ this ->assertFalse ($ this ->cache ->inCache ('folder/bar ' ));
290300 }
291301
302+ public function testCalculateFolderSizeWithEncryptedZeroByte (): void {
303+ $ folder = 'enc_folder ' ;
304+ $ this ->cache ->put ($ folder , ['size ' => -1 , 'mtime ' => 20 , 'mimetype ' => ICacheEntry::DIRECTORY_MIMETYPE ]);
305+
306+ // Child 1: zero-byte encrypted file — on-disk 8192 (header only), plaintext 0
307+ $ child1 = $ folder . '/empty.enc ' ;
308+ $ this ->cache ->put ($ child1 , [
309+ 'size ' => 8192 ,
310+ 'mtime ' => 20 ,
311+ 'mimetype ' => 'application/octet-stream ' ,
312+ 'encrypted ' => 1 ,
313+ 'unencrypted_size ' => 0 ,
314+ ]);
315+
316+ // Child 2: non-zero encrypted file — opens the write-back gate ($unencryptedMax > 0)
317+ $ child2 = $ folder . '/small.enc ' ;
318+ $ this ->cache ->put ($ child2 , [
319+ 'size ' => 8292 ,
320+ 'mtime ' => 20 ,
321+ 'mimetype ' => 'application/octet-stream ' ,
322+ 'encrypted ' => 1 ,
323+ 'unencrypted_size ' => 100 ,
324+ ]);
325+
326+ $ this ->cache ->calculateFolderSize ($ folder );
327+
328+ $ entry = $ this ->cache ->get ($ folder );
329+ // Must sum plaintext sizes (0 + 100 = 100), not fall back to on-disk size for
330+ // the zero-byte child (8192 + 100 = 8292 with the old buggy code)
331+ $ this ->assertEquals (100 , $ entry ['unencrypted_size ' ], 'Folder unencrypted_size should sum plaintext sizes ' );
332+ $ this ->assertEquals (16484 , $ entry ['size ' ], 'Folder size should sum on-disk sizes (8192 + 8292) ' );
333+ }
334+
292335 public function testRootFolderSizeForNonHomeStorage (): void {
293336 $ dir1 = 'knownsize ' ;
294337 $ dir2 = 'unknownsize ' ;
0 commit comments