From 0001c22668f3901dc4ca0dee5709401fb52eaa25 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 12 May 2025 18:32:38 +0200 Subject: [PATCH 1/2] test: add test for nested cache jail unjailedroot Signed-off-by: Robin Appelman --- lib/private/Files/Cache/Wrapper/CacheJail.php | 2 +- tests/lib/Files/Cache/Wrapper/CacheJailTest.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/private/Files/Cache/Wrapper/CacheJail.php b/lib/private/Files/Cache/Wrapper/CacheJail.php index 5c7bd4334f3..24050dce0c9 100644 --- a/lib/private/Files/Cache/Wrapper/CacheJail.php +++ b/lib/private/Files/Cache/Wrapper/CacheJail.php @@ -50,7 +50,7 @@ class CacheJail extends CacheWrapper { * * @return string */ - protected function getGetUnjailedRoot() { + public function getGetUnjailedRoot() { return $this->unjailedRoot; } diff --git a/tests/lib/Files/Cache/Wrapper/CacheJailTest.php b/tests/lib/Files/Cache/Wrapper/CacheJailTest.php index aed13c41ac0..57024e2eb79 100644 --- a/tests/lib/Files/Cache/Wrapper/CacheJailTest.php +++ b/tests/lib/Files/Cache/Wrapper/CacheJailTest.php @@ -8,6 +8,7 @@ namespace Test\Files\Cache\Wrapper; use OC\Files\Cache\Wrapper\CacheJail; +use OC\Files\Cache\Wrapper\CacheWrapper; use OC\Files\Search\SearchComparison; use OC\Files\Search\SearchQuery; use OC\Files\Storage\Wrapper\Jail; @@ -252,4 +253,14 @@ class CacheJailTest extends CacheTest { $storage->getWatcher()->update('bar', ['mimetype' => 'text/plain']); $this->assertTrue($this->cache->inCache('bar')); } + + public function testUnJailedRoot(): void { + $jail1 = new CacheJail($this->sourceCache, 'foo'); + $jail2 = new CacheJail($jail1, 'bar'); + $this->assertEquals('foo/bar', $jail2->getGetUnjailedRoot()); + + $middleWrapper = new CacheWrapper($jail1); + $jail3 = new CacheJail($middleWrapper, 'bar'); + $this->assertEquals('foo/bar', $jail3->getGetUnjailedRoot()); + } } From 1e72620169ca689d6aa3a7b1d47524bfd7bbe1b4 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 12 May 2025 18:33:26 +0200 Subject: [PATCH 2/2] fix: fix unjailedroot of nested jails if there are other wrappers in between Signed-off-by: Robin Appelman --- apps/files_sharing/lib/Cache.php | 2 +- lib/private/Files/Cache/Wrapper/CacheJail.php | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/files_sharing/lib/Cache.php b/apps/files_sharing/lib/Cache.php index ccc93eb0952..024df5d3f43 100644 --- a/apps/files_sharing/lib/Cache.php +++ b/apps/files_sharing/lib/Cache.php @@ -68,7 +68,7 @@ class Cache extends CacheJail { return $this->root; } - protected function getGetUnjailedRoot(): string { + public function getGetUnjailedRoot(): string { return $this->sourceRootInfo->getPath(); } diff --git a/lib/private/Files/Cache/Wrapper/CacheJail.php b/lib/private/Files/Cache/Wrapper/CacheJail.php index 24050dce0c9..5bc4ee8529d 100644 --- a/lib/private/Files/Cache/Wrapper/CacheJail.php +++ b/lib/private/Files/Cache/Wrapper/CacheJail.php @@ -31,10 +31,13 @@ class CacheJail extends CacheWrapper { ) { parent::__construct($cache, $dependencies); - if ($cache instanceof CacheJail) { - $this->unjailedRoot = $cache->getSourcePath($root); - } else { - $this->unjailedRoot = $root; + $this->unjailedRoot = $root; + $parent = $cache; + while ($parent instanceof CacheWrapper) { + if ($parent instanceof CacheJail) { + $this->unjailedRoot = $parent->getSourcePath($this->unjailedRoot); + } + $parent = $parent->getCache(); } }