Skip to content

Commit 9098aa6

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

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

lib/private/Files/Cache/Scanner.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

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
@@ -1224,9 +1224,22 @@ private function basicOperation(string $operation, string $path, array $hooks =
12241224
$this->removeUpdate($storage, $internalPath);
12251225
}
12261226
if ($result !== false && in_array('write', $hooks, true) && $operation !== 'fopen' && $operation !== 'touch') {
1227-
$isCreateOperation = $operation === 'mkdir' || ($operation === 'file_put_contents' && in_array('create', $hooks, true));
1228-
$sizeDifference = $operation === 'mkdir' ? 0 : $result;
1229-
$this->writeUpdate($storage, $internalPath, null, $isCreateOperation ? $sizeDifference : null);
1227+
if ($operation === 'mkdir') {
1228+
$sizeDifference = 0;
1229+
} elseif ($operation === 'file_put_contents') {
1230+
if (in_array('create', $hooks, true)) {
1231+
$sizeDifference = $result;
1232+
} elseif (in_array('update', $hooks, true)) {
1233+
$cacheData = $storage->getCache()->get($path);
1234+
$sizeDifference = $cacheData === false ? null : $result - $cacheData->getSize();
1235+
} else {
1236+
$sizeDifference = null;
1237+
}
1238+
} else {
1239+
$sizeDifference = null;
1240+
}
1241+
1242+
$this->writeUpdate($storage, $internalPath, null, $sizeDifference);
12301243
}
12311244
if ($result !== false && in_array('touch', $hooks)) {
12321245
$this->writeUpdate($storage, $internalPath, $extraParam, 0);

0 commit comments

Comments
 (0)