aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Files
diff options
context:
space:
mode:
authorJosh <josh.t.richards@gmail.com>2024-02-23 12:55:58 -0500
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2024-05-13 09:06:41 +0000
commitb62901131f6416efd31141641338fdfa86e8e2c0 (patch)
treea89f291554a6cfe9076c37ec26a9c11977b871b6 /lib/private/Files
parentefb03b726d27907f161a0c011a6ebc3cc3bfcd2b (diff)
downloadnextcloud-server-b62901131f6416efd31141641338fdfa86e8e2c0.tar.gz
nextcloud-server-b62901131f6416efd31141641338fdfa86e8e2c0.zip
fix(Files): Change how scanner diffs for changed metadata
Fixes #43408 Signed-off-by: Josh <josh.t.richards@gmail.com>
Diffstat (limited to 'lib/private/Files')
-rw-r--r--lib/private/Files/Cache/Scanner.php49
1 files changed, 47 insertions, 2 deletions
diff --git a/lib/private/Files/Cache/Scanner.php b/lib/private/Files/Cache/Scanner.php
index 0c82e21e30d..e6c64632b6d 100644
--- a/lib/private/Files/Cache/Scanner.php
+++ b/lib/private/Files/Cache/Scanner.php
@@ -221,8 +221,9 @@ class Scanner extends BasicEmitter implements IScanner {
}
// Only update metadata that has changed
- $newData = array_diff_assoc($data, $cacheData->getData());
-
+ // i.e. get all the values in $data that are not present in the cache already
+ $newData = $this->array_diff_assoc_multi($data, $cacheData->getData());
+
// make it known to the caller that etag has been changed and needs propagation
if (isset($newData['etag'])) {
$data['etag_changed'] = true;
@@ -370,6 +371,50 @@ class Scanner extends BasicEmitter implements IScanner {
}
/**
+ * Compares $array1 against $array2 and returns all the values in $array1 that are not in $array2
+ * Note this is a one-way check - i.e. we don't care about things that are in $array2 that aren't in $array1
+ *
+ * Supports multi-dimensional arrays
+ * Also checks keys/indexes
+ * Comparisons are strict just like array_diff_assoc
+ * Order of keys/values does not matter
+ *
+ * @param array $array1
+ * @param array $array2
+ * @return array with the differences between $array1 and $array1
+ * @throws \InvalidArgumentException if $array1 isn't an actual array
+ *
+ */
+ protected function array_diff_assoc_multi(array $array1, array $array2) {
+
+ $result = [];
+
+ foreach ($array1 as $key => $value) {
+
+ // if $array2 doesn't have the same key, that's a result
+ if (!array_key_exists($key, $array2)) {
+ $result[$key] = $value;
+ continue;
+ }
+
+ // if $array2's value for the same key is different, that's a result
+ if ($array2[$key] !== $value && !is_array($value)) {
+ $result[$key] = $value;
+ continue;
+ }
+
+ if (is_array($value)) {
+ $nestedDiff = $this->array_diff_assoc_multi($value, $array2[$key]);
+ if (!empty($nestedDiff)) {
+ $result[$key] = $nestedDiff;
+ continue;
+ }
+ }
+ }
+ return $result;
+ }
+
+ /**
* Get the children currently in the cache
*
* @param int $folderId