Skip to content

Commit

Permalink
fix: don't use cached root info from shared cache if the watcher has …
Browse files Browse the repository at this point in the history
…detected an update

Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 authored and backportbot[bot] committed Feb 11, 2025
1 parent 205b597 commit 6d47838
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions apps/files_sharing/lib/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,8 @@ public function getCacheEntryFromSearchResult(ICacheEntry $rawEntry): ?ICacheEnt
return null;
}
}

public function markRootChanged(): void {
$this->rootUnchanged = false;
}
}
5 changes: 5 additions & 0 deletions apps/files_sharing/lib/SharedStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,12 @@ public function getWatcher(string $path = '', ?IStorage $storage = null): IWatch
// for shares from the home storage we can rely on the home storage to keep itself up to date
// for other storages we need use the proper watcher
if (!(str_starts_with($storageId, 'home::') || str_starts_with($storageId, 'object::user'))) {
$cache = $this->getCache();
$this->watcher = parent::getWatcher($path, $storage);
if ($cache instanceof Cache) {
$this->watcher->onUpdate($cache->markRootChanged(...));
}

return $this->watcher;
}
}
Expand Down
13 changes: 13 additions & 0 deletions lib/private/Files/Cache/Watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class Watcher implements IWatcher {
*/
protected $scanner;

/** @var callable[] */
protected $onUpdate = [];

/**
* @param \OC\Files\Storage\Storage $storage
*/
Expand Down Expand Up @@ -100,6 +103,9 @@ public function update($path, $cachedData) {
if ($this->cache instanceof Cache) {
$this->cache->correctFolderSize($path);
}
foreach ($this->onUpdate as $callback) {
$callback($path);
}
}

/**
Expand Down Expand Up @@ -130,4 +136,11 @@ public function cleanFolder($path) {
}
}
}

/**
* register a callback to be called whenever the watcher triggers and update
*/
public function onUpdate(callable $callback): void {
$this->onUpdate[] = $callback;
}
}
3 changes: 3 additions & 0 deletions lib/private/Files/Cache/Wrapper/JailWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,7 @@ public function cleanFolder($path) {
$this->watcher->cleanFolder($this->getSourcePath($path));
}

public function onUpdate(callable $callback): void {
$this->watcher->onUpdate($callback);
}
}
6 changes: 6 additions & 0 deletions lib/public/Files/Cache/IWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,10 @@ public function needsUpdate($path, $cachedData);
* @since 9.0.0
*/
public function cleanFolder($path);

/**
* register a callback to be called whenever the watcher triggers and update
* @since 31.0.0
*/
public function onUpdate(callable $callback): void;
}

0 comments on commit 6d47838

Please sign in to comment.