diff options
author | Robin Appelman <robin@icewind.nl> | 2017-11-10 17:02:35 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2017-11-10 17:03:27 +0100 |
commit | 56fd462718f2a60d1f9fa2955db28fdc1a5e39b9 (patch) | |
tree | b1e5f33ede62671a46614eb06dcbed611f82764c | |
parent | c7e5bc0f9ab6f58bf9a47dd0c3795e1183419652 (diff) | |
download | nextcloud-server-56fd462718f2a60d1f9fa2955db28fdc1a5e39b9.tar.gz nextcloud-server-56fd462718f2a60d1f9fa2955db28fdc1a5e39b9.zip |
Use the correct root for shared jail when the source storage is also a jail
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r-- | apps/files_sharing/lib/Cache.php | 15 | ||||
-rw-r--r-- | apps/files_sharing/tests/CacheTest.php | 39 | ||||
-rw-r--r-- | lib/private/Files/Storage/Wrapper/Jail.php | 11 |
3 files changed, 64 insertions, 1 deletions
diff --git a/apps/files_sharing/lib/Cache.php b/apps/files_sharing/lib/Cache.php index b3366b29ee3..e08da0d73e5 100644 --- a/apps/files_sharing/lib/Cache.php +++ b/apps/files_sharing/lib/Cache.php @@ -30,6 +30,7 @@ namespace OCA\Files_Sharing; use OC\Files\Cache\FailedCache; use OC\Files\Cache\Wrapper\CacheJail; +use OC\Files\Storage\Wrapper\Jail; use OCP\Files\Cache\ICacheEntry; /** @@ -62,9 +63,21 @@ class Cache extends CacheJail { $this->storage = $storage; $this->sourceRootInfo = $sourceRootInfo; $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( null, - $this->sourceRootInfo->getPath() + $absoluteRoot ); } diff --git a/apps/files_sharing/tests/CacheTest.php b/apps/files_sharing/tests/CacheTest.php index 82f4ad62f67..5d5de433ee4 100644 --- a/apps/files_sharing/tests/CacheTest.php +++ b/apps/files_sharing/tests/CacheTest.php @@ -30,6 +30,8 @@ namespace OCA\Files_Sharing\Tests; +use OC\Files\Storage\Temporary; +use OC\Files\Storage\Wrapper\Jail; use OCA\Files_Sharing\SharedStorage; /** @@ -552,4 +554,41 @@ class CacheTest extends TestCase { $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')); + } } diff --git a/lib/private/Files/Storage/Wrapper/Jail.php b/lib/private/Files/Storage/Wrapper/Jail.php index d477678c277..adee8ced772 100644 --- a/lib/private/Files/Storage/Wrapper/Jail.php +++ b/lib/private/Files/Storage/Wrapper/Jail.php @@ -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() { return parent::getId(); } |