aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2025-02-11 16:01:37 +0100
committerGitHub <noreply@github.com>2025-02-11 16:01:37 +0100
commit53749e06fc3fe3a3de3cb4f9e84ef3c6be9bf648 (patch)
tree52c5e5476ba7d10340b3c7cb92ada1625bd63e03 /apps/files_sharing
parent5f423df9fd406c1a548a3cbbf67d147c82d1a068 (diff)
parent65a10f281d1c64109b6371c0d073ea061008d68e (diff)
downloadnextcloud-server-53749e06fc3fe3a3de3cb4f9e84ef3c6be9bf648.tar.gz
nextcloud-server-53749e06fc3fe3a3de3cb4f9e84ef3c6be9bf648.zip
Merge pull request #50324 from nextcloud/shared-cache-watcher-update
fix: don't use cached root info from shared cache if the watcher has detected an update
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/lib/Cache.php4
-rw-r--r--apps/files_sharing/lib/SharedStorage.php5
-rw-r--r--apps/files_sharing/tests/CacheTest.php35
3 files changed, 44 insertions, 0 deletions
diff --git a/apps/files_sharing/lib/Cache.php b/apps/files_sharing/lib/Cache.php
index 350f4718712..ccc93eb0952 100644
--- a/apps/files_sharing/lib/Cache.php
+++ b/apps/files_sharing/lib/Cache.php
@@ -191,4 +191,8 @@ class Cache extends CacheJail {
return null;
}
}
+
+ public function markRootChanged(): void {
+ $this->rootUnchanged = false;
+ }
}
diff --git a/apps/files_sharing/lib/SharedStorage.php b/apps/files_sharing/lib/SharedStorage.php
index f54252d0458..539d3958e8d 100644
--- a/apps/files_sharing/lib/SharedStorage.php
+++ b/apps/files_sharing/lib/SharedStorage.php
@@ -441,7 +441,12 @@ class SharedStorage extends Jail implements LegacyISharedStorage, ISharedStorage
// 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;
}
}
diff --git a/apps/files_sharing/tests/CacheTest.php b/apps/files_sharing/tests/CacheTest.php
index 6813accd9be..bce641200d0 100644
--- a/apps/files_sharing/tests/CacheTest.php
+++ b/apps/files_sharing/tests/CacheTest.php
@@ -14,6 +14,7 @@ use OC\Files\Storage\Wrapper\Jail;
use OC\Files\View;
use OCA\Files_Sharing\SharedStorage;
use OCP\Constants;
+use OCP\Files\Cache\IWatcher;
use OCP\Share\IShare;
/**
@@ -567,4 +568,38 @@ class CacheTest extends TestCase {
$results = $sharedStorage->getCache()->search('foo.txt');
$this->assertCount(1, $results);
}
+
+ public function testWatcherRootChange() {
+ $sourceStorage = new Temporary();
+ $sourceStorage->mkdir('shared');
+ $sourceStorage->file_put_contents('shared/foo.txt', 'foo');
+ $sourceStorage->getScanner()->scan('');
+ $sourceStorage->getWatcher()->setPolicy(IWatcher::CHECK_ALWAYS);
+ $this->registerMount(self::TEST_FILES_SHARING_API_USER1, $sourceStorage, '/' . self::TEST_FILES_SHARING_API_USER1 . '/files/foo');
+
+ self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
+
+ $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
+ $node = $rootFolder->get('foo/shared');
+ $this->assertEquals(3, $node->getSize());
+
+ $share = $this->shareManager->newShare();
+ $share->setNode($node)
+ ->setShareType(IShare::TYPE_USER)
+ ->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
+ ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
+ ->setPermissions(Constants::PERMISSION_ALL);
+ $share = $this->shareManager->createShare($share);
+ $share->setStatus(IShare::STATUS_ACCEPTED);
+ $this->shareManager->updateShare($share);
+ \OC_Util::tearDownFS();
+
+ self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
+
+ $view = Filesystem::getView();
+
+ $sourceStorage->rmdir('shared');
+
+ $this->assertFalse($view->getFileInfo('shared'));
+ }
}