Skip to content

Commit ca6e59c

Browse files
authored
Merge pull request nextcloud#52824 from nextcloud/backport/52775/stable30
[stable30] fix unjailedroot of nested jails if there are other wrappers in between
2 parents cc56c3b + 195358e commit ca6e59c

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

apps/files_sharing/lib/Cache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected function getRoot() {
7676
return $this->root;
7777
}
7878

79-
protected function getGetUnjailedRoot() {
79+
public function getGetUnjailedRoot() {
8080
return $this->sourceRootInfo->getPath();
8181
}
8282

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ public function __construct(
3535
parent::__construct($cache, $dependencies);
3636
$this->root = $root;
3737

38-
if ($cache instanceof CacheJail) {
39-
$this->unjailedRoot = $cache->getSourcePath($root);
40-
} else {
41-
$this->unjailedRoot = $root;
38+
$this->unjailedRoot = $root;
39+
$parent = $cache;
40+
while ($parent instanceof CacheWrapper) {
41+
if ($parent instanceof CacheJail) {
42+
$this->unjailedRoot = $parent->getSourcePath($this->unjailedRoot);
43+
}
44+
$parent = $parent->getCache();
4245
}
4346
}
4447

@@ -51,7 +54,7 @@ protected function getRoot() {
5154
*
5255
* @return string
5356
*/
54-
protected function getGetUnjailedRoot() {
57+
public function getGetUnjailedRoot() {
5558
return $this->unjailedRoot;
5659
}
5760

tests/lib/Files/Cache/Wrapper/CacheJailTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace Test\Files\Cache\Wrapper;
1010

1111
use OC\Files\Cache\Wrapper\CacheJail;
12+
use OC\Files\Cache\Wrapper\CacheWrapper;
1213
use OC\Files\Search\SearchComparison;
1314
use OC\Files\Search\SearchQuery;
1415
use OC\Files\Storage\Wrapper\Jail;
@@ -253,4 +254,14 @@ public function testWatcherAfterInnerWatcher() {
253254
$storage->getWatcher()->update('bar', ['mimetype' => 'text/plain']);
254255
$this->assertTrue($this->cache->inCache('bar'));
255256
}
257+
258+
public function testUnJailedRoot(): void {
259+
$jail1 = new CacheJail($this->sourceCache, 'foo');
260+
$jail2 = new CacheJail($jail1, 'bar');
261+
$this->assertEquals('foo/bar', $jail2->getGetUnjailedRoot());
262+
263+
$middleWrapper = new CacheWrapper($jail1);
264+
$jail3 = new CacheJail($middleWrapper, 'bar');
265+
$this->assertEquals('foo/bar', $jail3->getGetUnjailedRoot());
266+
}
256267
}

0 commit comments

Comments
 (0)