3636namespace OC \Files \Cache ;
3737
3838use Doctrine \DBAL \Exception ;
39+ use OC \Files \Storage \Wrapper \Encryption ;
3940use OCP \Files \Cache \IScanner ;
4041use OCP \Files \ForbiddenException ;
4142use OCP \Files \Storage \IReliableEtagStorage ;
@@ -207,9 +208,17 @@ public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData =
207208 $ data ['etag ' ] = $ etag ;
208209 }
209210 }
211+
212+ // we only updated unencrypted_size if it's already set
213+ if ($ cacheData ['unencrypted_size ' ] === 0 ) {
214+ unset($ data ['unencrypted_size ' ]);
215+ }
216+
210217 // Only update metadata that has changed
211218 $ newData = array_diff_assoc ($ data , $ cacheData ->getData ());
212219 } else {
220+ // we only updated unencrypted_size if it's already set
221+ unset($ data ['unencrypted_size ' ]);
213222 $ newData = $ data ;
214223 $ fileId = -1 ;
215224 }
@@ -219,7 +228,7 @@ public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData =
219228 $ newData ['parent ' ] = $ parentId ;
220229 $ data ['fileid ' ] = $ this ->addToCache ($ file , $ newData , $ fileId );
221230 }
222-
231+
223232 $ data ['oldSize ' ] = ($ cacheData && isset ($ cacheData ['size ' ])) ? $ cacheData ['size ' ] : 0 ;
224233
225234 if ($ cacheData && isset ($ cacheData ['encrypted ' ])) {
@@ -390,8 +399,15 @@ protected function scanChildren($path, $recursive = self::SCAN_RECURSIVE, $reuse
390399 }
391400 }
392401 $ oldSize = $ data ['size ' ] ?? null ;
393- if ($ this ->cacheActive && $ oldSize !== $ size ) {
394- $ this ->cache ->update ($ folderId , ['size ' => $ size ]);
402+
403+ // for encrypted storages, we trigger a regular folder size calculation instead of using the calculated size
404+ // to make sure we also updated the unencrypted-size where applicable
405+ if ($ this ->storage ->instanceOfStorage (Encryption::class)) {
406+ $ this ->cache ->calculateFolderSize ($ path );
407+ } else {
408+ if ($ this ->cacheActive && $ oldSize !== $ size ) {
409+ $ this ->cache ->update ($ folderId , ['size ' => $ size ]);
410+ }
395411 }
396412 $ this ->emit ('\OC\Files\Cache\Scanner ' , 'postScanFolder ' , [$ path , $ this ->storageId ]);
397413 return $ size ;
0 commit comments