delay calculating the shared cache root until it's used
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
6d8de960c9
commit
4144580167
|
@ -63,23 +63,29 @@ class Cache extends CacheJail {
|
||||||
$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,
|
||||||
$absoluteRoot
|
null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getRoot() {
|
||||||
|
if (is_null($this->root)) {
|
||||||
|
$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 = $this->storage->getSourceStorage();
|
||||||
|
if ($currentStorage->instanceOfStorage(Jail::class)) {
|
||||||
|
/** @var Jail $currentStorage */
|
||||||
|
$absoluteRoot = $currentStorage->getJailedPath($absoluteRoot);
|
||||||
|
}
|
||||||
|
$this->root = $absoluteRoot;
|
||||||
|
}
|
||||||
|
return $this->root;
|
||||||
|
}
|
||||||
|
|
||||||
public function getCache() {
|
public function getCache() {
|
||||||
if (is_null($this->cache)) {
|
if (is_null($this->cache)) {
|
||||||
$sourceStorage = $this->storage->getSourceStorage();
|
$sourceStorage = $this->storage->getSourceStorage();
|
||||||
|
@ -103,7 +109,7 @@ class Cache extends CacheJail {
|
||||||
|
|
||||||
public function get($file) {
|
public function get($file) {
|
||||||
if ($this->rootUnchanged && ($file === '' || $file === $this->sourceRootInfo->getId())) {
|
if ($this->rootUnchanged && ($file === '' || $file === $this->sourceRootInfo->getId())) {
|
||||||
return $this->formatCacheEntry(clone $this->sourceRootInfo);
|
return $this->formatCacheEntry(clone $this->sourceRootInfo, '');
|
||||||
}
|
}
|
||||||
return parent::get($file);
|
return parent::get($file);
|
||||||
}
|
}
|
||||||
|
@ -128,16 +134,20 @@ class Cache extends CacheJail {
|
||||||
return parent::moveFromCache($sourceCache, $sourcePath, $targetPath);
|
return parent::moveFromCache($sourceCache, $sourcePath, $targetPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function formatCacheEntry($entry) {
|
protected function formatCacheEntry($entry, $path = null) {
|
||||||
$path = isset($entry['path']) ? $entry['path'] : '';
|
if (is_null($path)) {
|
||||||
$entry = parent::formatCacheEntry($entry);
|
$path = isset($entry['path']) ? $entry['path'] : '';
|
||||||
|
$entry['path'] = $this->getJailedPath($path);
|
||||||
|
} else {
|
||||||
|
$entry['path'] = $path;
|
||||||
|
}
|
||||||
$sharePermissions = $this->storage->getPermissions($path);
|
$sharePermissions = $this->storage->getPermissions($path);
|
||||||
if (isset($entry['permissions'])) {
|
if (isset($entry['permissions'])) {
|
||||||
$entry['permissions'] &= $sharePermissions;
|
$entry['permissions'] &= $sharePermissions;
|
||||||
} else {
|
} else {
|
||||||
$entry['permissions'] = $sharePermissions;
|
$entry['permissions'] = $sharePermissions;
|
||||||
}
|
}
|
||||||
$entry['uid_owner'] = $this->storage->getOwner($path);
|
$entry['uid_owner'] = $this->storage->getOwner('');
|
||||||
$entry['displayname_owner'] = $this->getOwnerDisplayName();
|
$entry['displayname_owner'] = $this->getOwnerDisplayName();
|
||||||
if ($path === '') {
|
if ($path === '') {
|
||||||
$entry['is_share_mount_point'] = true;
|
$entry['is_share_mount_point'] = true;
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace OC\Files\Cache\Wrapper;
|
namespace OC\Files\Cache\Wrapper;
|
||||||
|
|
||||||
use OC\Files\Cache\Cache;
|
use OC\Files\Cache\Cache;
|
||||||
use OCP\Files\Cache\ICacheEntry;
|
use OCP\Files\Cache\ICacheEntry;
|
||||||
use OCP\Files\Search\ISearchQuery;
|
use OCP\Files\Search\ISearchQuery;
|
||||||
|
@ -48,11 +49,15 @@ class CacheJail extends CacheWrapper {
|
||||||
$this->root = $root;
|
$this->root = $root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getRoot() {
|
||||||
|
return $this->root;
|
||||||
|
}
|
||||||
|
|
||||||
protected function getSourcePath($path) {
|
protected function getSourcePath($path) {
|
||||||
if ($path === '') {
|
if ($path === '') {
|
||||||
return $this->root;
|
return $this->getRoot();
|
||||||
} else {
|
} else {
|
||||||
return $this->root . '/' . ltrim($path, '/');
|
return $this->getRoot() . '/' . ltrim($path, '/');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,13 +66,13 @@ class CacheJail extends CacheWrapper {
|
||||||
* @return null|string the jailed path or null if the path is outside the jail
|
* @return null|string the jailed path or null if the path is outside the jail
|
||||||
*/
|
*/
|
||||||
protected function getJailedPath($path) {
|
protected function getJailedPath($path) {
|
||||||
if ($this->root === '') {
|
if ($this->getRoot() === '') {
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
$rootLength = strlen($this->root) + 1;
|
$rootLength = strlen($this->getRoot()) + 1;
|
||||||
if ($path === $this->root) {
|
if ($path === $this->getRoot()) {
|
||||||
return '';
|
return '';
|
||||||
} else if (substr($path, 0, $rootLength) === $this->root . '/') {
|
} else if (substr($path, 0, $rootLength) === $this->getRoot() . '/') {
|
||||||
return substr($path, $rootLength);
|
return substr($path, $rootLength);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
@ -86,8 +91,8 @@ class CacheJail extends CacheWrapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function filterCacheEntry($entry) {
|
protected function filterCacheEntry($entry) {
|
||||||
$rootLength = strlen($this->root) + 1;
|
$rootLength = strlen($this->getRoot()) + 1;
|
||||||
return ($entry['path'] === $this->root) or (substr($entry['path'], 0, $rootLength) === $this->root . '/');
|
return ($entry['path'] === $this->getRoot()) or (substr($entry['path'], 0, $rootLength) === $this->getRoot() . '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -189,7 +194,7 @@ class CacheJail extends CacheWrapper {
|
||||||
* remove all entries for files that are stored on the storage from the cache
|
* remove all entries for files that are stored on the storage from the cache
|
||||||
*/
|
*/
|
||||||
public function clear() {
|
public function clear() {
|
||||||
$this->getCache()->remove($this->root);
|
$this->getCache()->remove($this->getRoot());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue