diff --git a/apps/files_sharing/lib/SharedStorage.php b/apps/files_sharing/lib/SharedStorage.php index 2d2f14fc55423..5aeabf83e0c55 100644 --- a/apps/files_sharing/lib/SharedStorage.php +++ b/apps/files_sharing/lib/SharedStorage.php @@ -124,12 +124,19 @@ private function init() { $this->initialized = true; try { Filesystem::initMountPoints($this->superShare->getShareOwner()); - $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); - list($this->nonMaskedStorage, $this->rootPath) = $this->ownerView->resolvePath($sourcePath); - $this->storage = new PermissionsMask([ - 'storage' => $this->nonMaskedStorage, - 'mask' => $this->superShare->getPermissions() - ]); + $this->rootPath = $this->getSourceRootInfo()->getPath(); + $mounts = $this->ownerView->getMountByNumericId($this->getSourceRootInfo()->getStorageId()); + if(!$mounts) { + $this->storage = new FailedStorage(['exception' => new \Exception('Mount for source storage not found')]); + $this->cache = new FailedCache(); + $this->rootPath = ''; + } else { + $this->nonMaskedStorage = $mounts[0]->getStorage(); + $this->storage = new PermissionsMask([ + 'storage' => $this->nonMaskedStorage, + 'mask' => $this->superShare->getPermissions() + ]); + } } catch (NotFoundException $e) { // original file not accessible or deleted, set FailedStorage $this->storage = new FailedStorage(['exception' => $e]); diff --git a/lib/private/Files/Mount/Manager.php b/lib/private/Files/Mount/Manager.php index 1293b8549a5f1..37223c8200f31 100644 --- a/lib/private/Files/Mount/Manager.php +++ b/lib/private/Files/Mount/Manager.php @@ -46,13 +46,17 @@ public function __construct() { $this->inPathCache = new CappedMemoryCache(); } + private function invalidateCaches() { + $this->pathCache->clear(); + $this->inPathCache->clear(); + } + /** * @param IMountPoint $mount */ public function addMount(IMountPoint $mount) { $this->mounts[$mount->getMountPoint()] = $mount; - $this->pathCache->clear(); - $this->inPathCache->clear(); + $this->invalidateCaches(); } /** @@ -64,8 +68,7 @@ public function removeMount(string $mountPoint) { $mountPoint .= '/'; } unset($this->mounts[$mountPoint]); - $this->pathCache->clear(); - $this->inPathCache->clear(); + $this->invalidateCaches(); } /** @@ -75,8 +78,7 @@ public function removeMount(string $mountPoint) { public function moveMount(string $mountPoint, string $target) { $this->mounts[$target] = $this->mounts[$mountPoint]; unset($this->mounts[$mountPoint]); - $this->pathCache->clear(); - $this->inPathCache->clear(); + $this->invalidateCaches(); } /** @@ -141,8 +143,7 @@ public function findIn(string $path): array { public function clear() { $this->mounts = []; - $this->pathCache->clear(); - $this->inPathCache->clear(); + $this->invalidateCaches(); } /** @@ -156,13 +157,10 @@ public function findByStorageId(string $id): array { if (\strlen($id) > 64) { $id = md5($id); } - $result = []; - foreach ($this->mounts as $mount) { - if ($mount->getStorageId() === $id) { - $result[] = $mount; - } - } - return $result; + $mounts = array_filter($this->mounts, function(IMountPoint $mountPoint) use ($id) { + return $mountPoint->getStorageId() === $id; + }); + return array_values($mounts); } /** @@ -179,8 +177,11 @@ public function getAll(): array { * @return MountPoint[] */ public function findByNumericId(int $id): array { - $storageId = \OC\Files\Cache\Storage::getStorageId($id); - return $this->findByStorageId($storageId); + \OC_Util::setupFS(); + $mounts = array_filter($this->mounts, function(IMountPoint $mountPoint) use ($id) { + return $mountPoint->getNumericStorageId() === $id; + }); + return array_values($mounts); } /** diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index 19e3871780344..4789a767346f5 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -213,6 +213,17 @@ public function getMount($path) { return Filesystem::getMountManager()->find($this->getAbsolutePath($path)); } + /** + * @param int $id + * @return IMountPoint[] + */ + public function getMountByNumericId($id) { + $mounts = Filesystem::getMountByNumericId($id); + return array_values(array_filter($mounts, function(IMountPoint $mountPoint) { + return $this->getRelativePath($mountPoint->getMountPoint()) || $mountPoint->getInternalPath($this->fakeRoot); + })); + } + /** * resolve a path to a storage and internal path *