Skip to content

Commit 3bfcd83

Browse files
committed
fix: don't use cached root info from shared cache if the watcher has detected an update
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent bec0932 commit 3bfcd83

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

apps/files_sharing/lib/Cache.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,8 @@ public function getCacheEntryFromSearchResult(ICacheEntry $rawEntry): ?ICacheEnt
198198
return null;
199199
}
200200
}
201+
202+
public function markRootChanged(): void {
203+
$this->rootUnchanged = false;
204+
}
201205
}

apps/files_sharing/lib/SharedStorage.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,12 @@ public function getWatcher($path = '', $storage = null): Watcher {
460460
// for shares from the home storage we can rely on the home storage to keep itself up to date
461461
// for other storages we need use the proper watcher
462462
if (!(str_starts_with($storageId, 'home::') || str_starts_with($storageId, 'object::user'))) {
463+
$cache = $this->getCache();
463464
$this->watcher = parent::getWatcher($path, $storage);
465+
if ($cache instanceof Cache && $this->watcher instanceof Watcher) {
466+
$this->watcher->onUpdate([$cache, 'markRootChanged']);
467+
}
468+
464469
return $this->watcher;
465470
}
466471
}

lib/private/Files/Cache/Watcher.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class Watcher implements IWatcher {
3333
*/
3434
protected $scanner;
3535

36+
/** @var callable[] */
37+
protected $onUpdate = [];
38+
3639
/**
3740
* @param \OC\Files\Storage\Storage $storage
3841
*/
@@ -100,6 +103,9 @@ public function update($path, $cachedData) {
100103
if ($this->cache instanceof Cache) {
101104
$this->cache->correctFolderSize($path);
102105
}
106+
foreach ($this->onUpdate as $callback) {
107+
$callback($path);
108+
}
103109
}
104110

105111
/**
@@ -130,4 +136,11 @@ public function cleanFolder($path) {
130136
}
131137
}
132138
}
139+
140+
/**
141+
* register a callback to be called whenever the watcher triggers and update
142+
*/
143+
public function onUpdate(callable $callback): void {
144+
$this->onUpdate[] = $callback;
145+
}
133146
}

lib/private/Files/Cache/Wrapper/JailWatcher.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,7 @@ public function cleanFolder($path) {
5555
$this->watcher->cleanFolder($this->getSourcePath($path));
5656
}
5757

58+
public function onUpdate(callable $callback): void {
59+
$this->watcher->onUpdate($callback);
60+
}
5861
}

0 commit comments

Comments
 (0)