|
|
@ -1828,43 +1828,25 @@ class View { |
|
|
|
* @return string |
|
|
|
* @throws NotFoundException |
|
|
|
*/ |
|
|
|
public function getPath($id, ?int $storageId = null) { |
|
|
|
public function getPath($id, ?int $storageId = null): string { |
|
|
|
$id = (int)$id; |
|
|
|
$manager = Filesystem::getMountManager(); |
|
|
|
$mounts = $manager->findIn($this->fakeRoot); |
|
|
|
$mounts[] = $manager->find($this->fakeRoot); |
|
|
|
$mounts = array_filter($mounts); |
|
|
|
// reverse the array, so we start with the storage this view is in
|
|
|
|
// which is the most likely to contain the file we're looking for
|
|
|
|
$mounts = array_reverse($mounts); |
|
|
|
|
|
|
|
// put non-shared mounts in front of the shared mount
|
|
|
|
// this prevents unneeded recursion into shares
|
|
|
|
usort($mounts, function (IMountPoint $a, IMountPoint $b) { |
|
|
|
return $a instanceof SharedMount && (!$b instanceof SharedMount) ? 1 : -1; |
|
|
|
}); |
|
|
|
$rootFolder = Server::get(Files\IRootFolder::class); |
|
|
|
|
|
|
|
if (!is_null($storageId)) { |
|
|
|
$mounts = array_filter($mounts, function (IMountPoint $mount) use ($storageId) { |
|
|
|
return $mount->getNumericStorageId() === $storageId; |
|
|
|
}); |
|
|
|
$node = $rootFolder->getFirstNodeByIdInPath($id, $this->getRoot()); |
|
|
|
if ($node) { |
|
|
|
if ($storageId === null || $storageId === $node->getStorage()->getCache()->getNumericStorageId()) { |
|
|
|
return $this->getRelativePath($node->getPath()) ?? ''; |
|
|
|
} |
|
|
|
} else { |
|
|
|
throw new NotFoundException(sprintf('File with id "%s" has not been found.', $id)); |
|
|
|
} |
|
|
|
|
|
|
|
foreach ($mounts as $mount) { |
|
|
|
/** |
|
|
|
* @var \OC\Files\Mount\MountPoint $mount |
|
|
|
*/ |
|
|
|
if ($mount->getStorage()) { |
|
|
|
$cache = $mount->getStorage()->getCache(); |
|
|
|
$internalPath = $cache->getPathById($id); |
|
|
|
if (is_string($internalPath)) { |
|
|
|
$fullPath = $mount->getMountPoint() . $internalPath; |
|
|
|
if (!is_null($path = $this->getRelativePath($fullPath))) { |
|
|
|
return $path; |
|
|
|
} |
|
|
|
} |
|
|
|
foreach ($rootFolder->getByIdInPath($id, $this->getRoot()) as $node) { |
|
|
|
if ($storageId === $node->getStorage()->getCache()->getNumericStorageId()) { |
|
|
|
return $this->getRelativePath($node->getPath()) ?? ''; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
throw new NotFoundException(sprintf('File with id "%s" has not been found.', $id)); |
|
|
|
} |
|
|
|
|
|
|
|