diff options
author | Robin Appelman <robin@icewind.nl> | 2017-12-04 15:16:39 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2017-12-04 15:16:39 +0100 |
commit | c87d6892531c75c7d34bd4493f4569c8ab828c0e (patch) | |
tree | f37c99cdb0521c70d90d146dc69b72b72aaddae7 | |
parent | 567757c793faed6925a538571a9e4f5b8b396bfd (diff) | |
download | nextcloud-server-c87d6892531c75c7d34bd4493f4569c8ab828c0e.tar.gz nextcloud-server-c87d6892531c75c7d34bd4493f4569c8ab828c0e.zip |
delay calculating the shared cache root until it's used
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r-- | apps/files_sharing/lib/Cache.php | 44 | ||||
-rw-r--r-- | lib/private/Files/Cache/Wrapper/CacheJail.php | 23 |
2 files changed, 41 insertions, 26 deletions
diff --git a/apps/files_sharing/lib/Cache.php b/apps/files_sharing/lib/Cache.php index e08da0d73e5..352001ecbd4 100644 --- a/apps/files_sharing/lib/Cache.php +++ b/apps/files_sharing/lib/Cache.php @@ -64,23 +64,29 @@ class Cache extends CacheJail { $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, - $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() { if (is_null($this->cache)) { $sourceStorage = $this->storage->getSourceStorage(); @@ -104,7 +110,7 @@ class Cache extends CacheJail { public function get($file) { if ($this->rootUnchanged && ($file === '' || $file === $this->sourceRootInfo->getId())) { - return $this->formatCacheEntry(clone $this->sourceRootInfo); + return $this->formatCacheEntry(clone $this->sourceRootInfo, ''); } return parent::get($file); } @@ -129,16 +135,20 @@ class Cache extends CacheJail { return parent::moveFromCache($sourceCache, $sourcePath, $targetPath); } - protected function formatCacheEntry($entry) { - $path = isset($entry['path']) ? $entry['path'] : ''; - $entry = parent::formatCacheEntry($entry); + protected function formatCacheEntry($entry, $path = null) { + if (is_null($path)) { + $path = isset($entry['path']) ? $entry['path'] : ''; + $entry['path'] = $this->getJailedPath($path); + } else { + $entry['path'] = $path; + } $sharePermissions = $this->storage->getPermissions($path); if (isset($entry['permissions'])) { $entry['permissions'] &= $sharePermissions; } else { $entry['permissions'] = $sharePermissions; } - $entry['uid_owner'] = $this->storage->getOwner($path); + $entry['uid_owner'] = $this->storage->getOwner(''); $entry['displayname_owner'] = $this->getOwnerDisplayName(); if ($path === '') { $entry['is_share_mount_point'] = true; diff --git a/lib/private/Files/Cache/Wrapper/CacheJail.php b/lib/private/Files/Cache/Wrapper/CacheJail.php index f14166ae840..357851bedd5 100644 --- a/lib/private/Files/Cache/Wrapper/CacheJail.php +++ b/lib/private/Files/Cache/Wrapper/CacheJail.php @@ -27,6 +27,7 @@ */ namespace OC\Files\Cache\Wrapper; + use OC\Files\Cache\Cache; use OCP\Files\Cache\ICacheEntry; use OCP\Files\Search\ISearchQuery; @@ -49,11 +50,15 @@ class CacheJail extends CacheWrapper { $this->root = $root; } + protected function getRoot() { + return $this->root; + } + protected function getSourcePath($path) { if ($path === '') { - return $this->root; + return $this->getRoot(); } else { - return $this->root . '/' . ltrim($path, '/'); + return $this->getRoot() . '/' . ltrim($path, '/'); } } @@ -62,13 +67,13 @@ class CacheJail extends CacheWrapper { * @return null|string the jailed path or null if the path is outside the jail */ protected function getJailedPath($path) { - if ($this->root === '') { + if ($this->getRoot() === '') { return $path; } - $rootLength = strlen($this->root) + 1; - if ($path === $this->root) { + $rootLength = strlen($this->getRoot()) + 1; + if ($path === $this->getRoot()) { return ''; - } else if (substr($path, 0, $rootLength) === $this->root . '/') { + } else if (substr($path, 0, $rootLength) === $this->getRoot() . '/') { return substr($path, $rootLength); } else { return null; @@ -87,8 +92,8 @@ class CacheJail extends CacheWrapper { } protected function filterCacheEntry($entry) { - $rootLength = strlen($this->root) + 1; - return ($entry['path'] === $this->root) or (substr($entry['path'], 0, $rootLength) === $this->root . '/'); + $rootLength = strlen($this->getRoot()) + 1; + return ($entry['path'] === $this->getRoot()) or (substr($entry['path'], 0, $rootLength) === $this->getRoot() . '/'); } /** @@ -190,7 +195,7 @@ class CacheJail extends CacheWrapper { * remove all entries for files that are stored on the storage from the cache */ public function clear() { - $this->getCache()->remove($this->root); + $this->getCache()->remove($this->getRoot()); } /** |