Skip to content
Snippets Groups Projects
Unverified Commit 56fd4627 authored by Robin Appelman's avatar Robin Appelman
Browse files

Use the correct root for shared jail when the source storage is also a jail


Signed-off-by: default avatarRobin Appelman <robin@icewind.nl>
parent c7e5bc0f
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,7 @@ namespace OCA\Files_Sharing; ...@@ -30,6 +30,7 @@ namespace OCA\Files_Sharing;
use OC\Files\Cache\FailedCache; use OC\Files\Cache\FailedCache;
use OC\Files\Cache\Wrapper\CacheJail; use OC\Files\Cache\Wrapper\CacheJail;
use OC\Files\Storage\Wrapper\Jail;
use OCP\Files\Cache\ICacheEntry; use OCP\Files\Cache\ICacheEntry;
/** /**
...@@ -62,9 +63,21 @@ class Cache extends CacheJail { ...@@ -62,9 +63,21 @@ class Cache extends CacheJail {
$this->storage = $storage; $this->storage = $storage;
$this->sourceRootInfo = $sourceRootInfo; $this->sourceRootInfo = $sourceRootInfo;
$this->numericId = $sourceRootInfo->getStorageId(); $this->numericId = $sourceRootInfo->getStorageId();
$absoluteRoot = $this->sourceRootInfo->getPath();
// the sourceRootInfo path is the absolute path of the folder in the "real" storage
// in the case where a folder is shared from a Jail we need to ensure that the share Jail
// has it's root set relative to the source Jail
$currentStorage = $storage->getSourceStorage();
if ($currentStorage->instanceOfStorage(Jail::class)) {
/** @var Jail $currentStorage */
$absoluteRoot = $currentStorage->getJailedPath($absoluteRoot);
}
parent::__construct( parent::__construct(
null, null,
$this->sourceRootInfo->getPath() $absoluteRoot
); );
} }
......
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
namespace OCA\Files_Sharing\Tests; namespace OCA\Files_Sharing\Tests;
use OC\Files\Storage\Temporary;
use OC\Files\Storage\Wrapper\Jail;
use OCA\Files_Sharing\SharedStorage; use OCA\Files_Sharing\SharedStorage;
/** /**
...@@ -552,4 +554,41 @@ class CacheTest extends TestCase { ...@@ -552,4 +554,41 @@ class CacheTest extends TestCase {
$this->assertEquals($sourceStorage->getCache()->getNumericStorageId(), $sharedStorage->getCache()->getNumericStorageId()); $this->assertEquals($sourceStorage->getCache()->getNumericStorageId(), $sharedStorage->getCache()->getNumericStorageId());
} }
public function testShareJailedStorage() {
$sourceStorage = new Temporary();
$sourceStorage->mkdir('jail');
$sourceStorage->mkdir('jail/sub');
$sourceStorage->file_put_contents('jail/sub/foo.txt', 'foo');
$jailedSource = new Jail([
'storage' => $sourceStorage,
'root' => 'jail'
]);
$sourceStorage->getScanner()->scan('');
$this->registerMount(self::TEST_FILES_SHARING_API_USER1, $jailedSource, '/' . 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/sub');
$share = $this->shareManager->newShare();
$share->setNode($node)
->setShareType(\OCP\Share::SHARE_TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setPermissions(\OCP\Constants::PERMISSION_ALL);
$this->shareManager->createShare($share);
\OC_Util::tearDownFS();
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$this->assertEquals('foo', \OC\Files\Filesystem::file_get_contents('/sub/foo.txt'));
\OC\Files\Filesystem::file_put_contents('/sub/bar.txt', 'bar');
/** @var SharedStorage $sharedStorage */
list($sharedStorage) = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/sub');
$this->assertTrue($sharedStorage->getCache()->inCache('bar.txt'));
$this->assertTrue($sourceStorage->getCache()->inCache('jail/sub/bar.txt'));
}
} }
...@@ -60,6 +60,17 @@ class Jail extends Wrapper { ...@@ -60,6 +60,17 @@ class Jail extends Wrapper {
} }
} }
public function getJailedPath($path) {
$root = rtrim($this->rootPath, '/') . '/';
if (strpos($path, $root) !== 0) {
return null;
} else {
$path = substr($path, strlen($this->rootPath));
return trim($path, '/');
}
}
public function getId() { public function getId() {
return parent::getId(); return parent::getId();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment