Skip to content

Commit c32cb6b

Browse files
authored
Merge pull request #7385 from nextcloud/shared-delay-root
delay calculating the shared cache root until it's used
2 parents de8fefe + c87d689 commit c32cb6b

2 files changed

Lines changed: 41 additions & 26 deletions

File tree

apps/files_sharing/lib/Cache.php

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,29 @@ public function __construct($storage, ICacheEntry $sourceRootInfo) {
6464
$this->sourceRootInfo = $sourceRootInfo;
6565
$this->numericId = $sourceRootInfo->getStorageId();
6666

67-
$absoluteRoot = $this->sourceRootInfo->getPath();
68-
69-
// the sourceRootInfo path is the absolute path of the folder in the "real" storage
70-
// in the case where a folder is shared from a Jail we need to ensure that the share Jail
71-
// has it's root set relative to the source Jail
72-
$currentStorage = $storage->getSourceStorage();
73-
if ($currentStorage->instanceOfStorage(Jail::class)) {
74-
/** @var Jail $currentStorage */
75-
$absoluteRoot = $currentStorage->getJailedPath($absoluteRoot);
76-
}
77-
7867
parent::__construct(
7968
null,
80-
$absoluteRoot
69+
null
8170
);
8271
}
8372

73+
protected function getRoot() {
74+
if (is_null($this->root)) {
75+
$absoluteRoot = $this->sourceRootInfo->getPath();
76+
77+
// the sourceRootInfo path is the absolute path of the folder in the "real" storage
78+
// in the case where a folder is shared from a Jail we need to ensure that the share Jail
79+
// has it's root set relative to the source Jail
80+
$currentStorage = $this->storage->getSourceStorage();
81+
if ($currentStorage->instanceOfStorage(Jail::class)) {
82+
/** @var Jail $currentStorage */
83+
$absoluteRoot = $currentStorage->getJailedPath($absoluteRoot);
84+
}
85+
$this->root = $absoluteRoot;
86+
}
87+
return $this->root;
88+
}
89+
8490
public function getCache() {
8591
if (is_null($this->cache)) {
8692
$sourceStorage = $this->storage->getSourceStorage();
@@ -104,7 +110,7 @@ public function getNumericStorageId() {
104110

105111
public function get($file) {
106112
if ($this->rootUnchanged && ($file === '' || $file === $this->sourceRootInfo->getId())) {
107-
return $this->formatCacheEntry(clone $this->sourceRootInfo);
113+
return $this->formatCacheEntry(clone $this->sourceRootInfo, '');
108114
}
109115
return parent::get($file);
110116
}
@@ -129,16 +135,20 @@ public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath,
129135
return parent::moveFromCache($sourceCache, $sourcePath, $targetPath);
130136
}
131137

132-
protected function formatCacheEntry($entry) {
133-
$path = isset($entry['path']) ? $entry['path'] : '';
134-
$entry = parent::formatCacheEntry($entry);
138+
protected function formatCacheEntry($entry, $path = null) {
139+
if (is_null($path)) {
140+
$path = isset($entry['path']) ? $entry['path'] : '';
141+
$entry['path'] = $this->getJailedPath($path);
142+
} else {
143+
$entry['path'] = $path;
144+
}
135145
$sharePermissions = $this->storage->getPermissions($path);
136146
if (isset($entry['permissions'])) {
137147
$entry['permissions'] &= $sharePermissions;
138148
} else {
139149
$entry['permissions'] = $sharePermissions;
140150
}
141-
$entry['uid_owner'] = $this->storage->getOwner($path);
151+
$entry['uid_owner'] = $this->storage->getOwner('');
142152
$entry['displayname_owner'] = $this->getOwnerDisplayName();
143153
if ($path === '') {
144154
$entry['is_share_mount_point'] = true;

lib/private/Files/Cache/Wrapper/CacheJail.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
*/
2828

2929
namespace OC\Files\Cache\Wrapper;
30+
3031
use OC\Files\Cache\Cache;
3132
use OCP\Files\Cache\ICacheEntry;
3233
use OCP\Files\Search\ISearchQuery;
@@ -49,11 +50,15 @@ public function __construct($cache, $root) {
4950
$this->root = $root;
5051
}
5152

53+
protected function getRoot() {
54+
return $this->root;
55+
}
56+
5257
protected function getSourcePath($path) {
5358
if ($path === '') {
54-
return $this->root;
59+
return $this->getRoot();
5560
} else {
56-
return $this->root . '/' . ltrim($path, '/');
61+
return $this->getRoot() . '/' . ltrim($path, '/');
5762
}
5863
}
5964

@@ -62,13 +67,13 @@ protected function getSourcePath($path) {
6267
* @return null|string the jailed path or null if the path is outside the jail
6368
*/
6469
protected function getJailedPath($path) {
65-
if ($this->root === '') {
70+
if ($this->getRoot() === '') {
6671
return $path;
6772
}
68-
$rootLength = strlen($this->root) + 1;
69-
if ($path === $this->root) {
73+
$rootLength = strlen($this->getRoot()) + 1;
74+
if ($path === $this->getRoot()) {
7075
return '';
71-
} else if (substr($path, 0, $rootLength) === $this->root . '/') {
76+
} else if (substr($path, 0, $rootLength) === $this->getRoot() . '/') {
7277
return substr($path, $rootLength);
7378
} else {
7479
return null;
@@ -87,8 +92,8 @@ protected function formatCacheEntry($entry) {
8792
}
8893

8994
protected function filterCacheEntry($entry) {
90-
$rootLength = strlen($this->root) + 1;
91-
return ($entry['path'] === $this->root) or (substr($entry['path'], 0, $rootLength) === $this->root . '/');
95+
$rootLength = strlen($this->getRoot()) + 1;
96+
return ($entry['path'] === $this->getRoot()) or (substr($entry['path'], 0, $rootLength) === $this->getRoot() . '/');
9297
}
9398

9499
/**
@@ -190,7 +195,7 @@ protected function getMoveInfo($path) {
190195
* remove all entries for files that are stored on the storage from the cache
191196
*/
192197
public function clear() {
193-
$this->getCache()->remove($this->root);
198+
$this->getCache()->remove($this->getRoot());
194199
}
195200

196201
/**

0 commit comments

Comments
 (0)