Skip to content

Commit 598055d

Browse files
committed
feat: Forward sizeDifference on update
And remove unneeded oldSize hack Signed-off-by: Louis Chemineau <louis@chmn.me>
1 parent f26dc79 commit 598055d

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

lib/private/Files/Cache/Scanner.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData =
210210
* @var \OC\Files\Cache\CacheEntry $cacheData
211211
*/
212212
$newData = $this->array_diff_assoc_multi($data, $cacheData->getData());
213-
213+
214214
// make it known to the caller that etag has been changed and needs propagation
215215
if (isset($newData['etag'])) {
216216
$data['etag_changed'] = true;
@@ -228,7 +228,6 @@ public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData =
228228
}
229229

230230
if ($cacheData !== false) {
231-
$data['oldSize'] = $cacheData['size'] ?? 0;
232231
$data['encrypted'] = $cacheData['encrypted'] ?? false;
233232
}
234233

@@ -351,23 +350,23 @@ public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $loc
351350
*
352351
*/
353352
protected function array_diff_assoc_multi(array $array1, array $array2) {
354-
353+
355354
$result = [];
356355

357356
foreach ($array1 as $key => $value) {
358-
357+
359358
// if $array2 doesn't have the same key, that's a result
360359
if (!array_key_exists($key, $array2)) {
361360
$result[$key] = $value;
362361
continue;
363362
}
364-
363+
365364
// if $array2's value for the same key is different, that's a result
366365
if ($array2[$key] !== $value && !is_array($value)) {
367366
$result[$key] = $value;
368367
continue;
369368
}
370-
369+
371370
if (is_array($value)) {
372371
$nestedDiff = $this->array_diff_assoc_multi($value, $array2[$key]);
373372
if (!empty($nestedDiff)) {

lib/private/Files/Cache/Updater.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,6 @@ public function update($path, $time = null, ?int $sizeDifference = null) {
111111

112112
$data = $this->scanner->scan($path, Scanner::SCAN_SHALLOW, -1, false);
113113

114-
if (isset($data['oldSize']) && isset($data['size'])) {
115-
$sizeDifference = $data['size'] - $data['oldSize'];
116-
}
117-
118114
// encryption is a pita and touches the cache itself
119115
if (isset($data['encrypted']) && (bool)$data['encrypted']) {
120116
$sizeDifference = null;

lib/private/Files/View.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,9 +1222,22 @@ private function basicOperation(string $operation, string $path, array $hooks =
12221222
$this->removeUpdate($storage, $internalPath);
12231223
}
12241224
if ($result !== false && in_array('write', $hooks, true) && $operation !== 'fopen' && $operation !== 'touch') {
1225-
$isCreateOperation = $operation === 'mkdir' || ($operation === 'file_put_contents' && in_array('create', $hooks, true));
1226-
$sizeDifference = $operation === 'mkdir' ? 0 : $result;
1227-
$this->writeUpdate($storage, $internalPath, null, $isCreateOperation ? $sizeDifference : null);
1225+
if ($operation === 'mkdir') {
1226+
$sizeDifference = 0;
1227+
} else if ($operation === 'file_put_contents') {
1228+
if (in_array('create', $hooks, true)) {
1229+
$sizeDifference = $result;
1230+
} else if (in_array('update', $hooks, true)) {
1231+
$cacheData = $storage->getCache()->get($path);
1232+
$sizeDifference = $cacheData === false ? null : $result - $cacheData->getSize();
1233+
} else {
1234+
$sizeDifference = null;
1235+
}
1236+
} else {
1237+
$sizeDifference = null;
1238+
}
1239+
1240+
$this->writeUpdate($storage, $internalPath, null, $sizeDifference);
12281241
}
12291242
if ($result !== false && in_array('touch', $hooks)) {
12301243
$this->writeUpdate($storage, $internalPath, $extraParam, 0);

0 commit comments

Comments
 (0)