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
036eae6956
commit
6d8de960c9
|
@ -29,6 +29,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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,9 +62,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 @@
|
||||||
|
|
||||||
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 {
|
||||||
|
|
||||||
$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'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,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();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue