Use the correct root for shared jail when the source storage is also a jail
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
c7e5bc0f9a
commit
56fd462718
3 changed files with 64 additions and 1 deletions
|
@ -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
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue