Skip to content

Commit 1c515bf

Browse files
committed
fix(Files): Change how scanner diffs for changed metadata
Fixes #43408 Signed-off-by: Josh <josh.t.richards@gmail.com>
1 parent fe4c1b2 commit 1c515bf

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

lib/private/Files/Cache/Scanner.php

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,9 @@ public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData =
221221
}
222222

223223
// Only update metadata that has changed
224-
$newData = array_diff_assoc($data, $cacheData->getData());
225-
224+
// i.e. get all the values in $data that are not present in the cache already
225+
$newData = $this->array_diff_assoc_multi($data, $cacheData->getData());
226+
226227
// make it known to the caller that etag has been changed and needs propagation
227228
if (isset($newData['etag'])) {
228229
$data['etag_changed'] = true;
@@ -369,6 +370,59 @@ public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $loc
369370
return $data;
370371
}
371372

373+
/**
374+
* Compares $array1 against $array2 and returns all the values in $array1 that are not in $array2
375+
* Note this is a one-way check - i.e. we don't care about things that are in $array2 that aren't in $array1
376+
*
377+
* Supports multi-dimensional arrays
378+
* Also checks keys/indexes
379+
* Comparisons are strict just like array_diff_assoc
380+
* Order of keys/values does not matter
381+
*
382+
* @param array $array1
383+
* @param array $array2
384+
* @return array with the differences between $array1 and $array1
385+
* @throws \InvalidArgumentException if $array1 isn't an actual array
386+
*
387+
*/
388+
protected function array_diff_assoc_multi(array $array1, array $array2) {
389+
if (!is_array($array1)) {
390+
// this ain't gonna work
391+
throw new \InvalidArgumentException('$array1 must be an array!');
392+
}
393+
394+
if (!is_array($array2)) {
395+
// everything is different
396+
return $array1;
397+
}
398+
399+
$result = [];
400+
401+
foreach ($array1 as $key => $value) {
402+
403+
// if $array2 doesn't have the same key, that's a result
404+
if (!array_key_exists($key, $array2)) {
405+
$result[$key] = $value;
406+
continue;
407+
}
408+
409+
// if $array2's value for the same key is different, that's a result
410+
if ($array2[$key] !== $value && !is_array($value)) {
411+
$result[$key] = $value;
412+
continue;
413+
}
414+
415+
if (is_array($value)) {
416+
$nestedDiff = $this->array_diff_assoc_multi($value, $array2[$key]);
417+
if (!empty($nestedDiff)) {
418+
$result[$key] = $nestedDiff;
419+
continue;
420+
}
421+
}
422+
}
423+
return $result;
424+
}
425+
372426
/**
373427
* Get the children currently in the cache
374428
*

0 commit comments

Comments
 (0)