From af78da59bcd45b4d4f3bec3f7547f93ea5ca55eb Mon Sep 17 00:00:00 2001 From: Josh Date: Tue, 10 Mar 2026 19:21:47 -0400 Subject: [PATCH 1/3] refactor(View): improve readability of getLocalFile and resolvePath Signed-off-by: Josh --- lib/private/Files/View.php | 45 +++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index 21265b7d0483b..e85cd68037196 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -185,33 +185,42 @@ public function getMount($path): IMountPoint { } /** - * Resolve a path to a storage and internal path + * Resolve a path to a storage and internal path. * - * @param string $path - * @return array{?IStorage, string} an array consisting of the storage and the internal path + * Accepts both: + * - relative paths (interpreted relative to this view root), and + * - absolute paths in Nextcloud's virtual filesystem (leading '/'). + * + * @param string $path Relative path, or absolute virtual filesystem path + * @return array{?IStorage, string} An array containing [storage, internalPath] */ - public function resolvePath($path): array { - $a = $this->getAbsolutePath($path); - $p = Filesystem::normalizePath($a); - return Filesystem::resolvePath($p); + public function resolvePath(string $path): array { + $absolutePath = $this->getAbsolutePath($path); + $normalizedPath = Filesystem::normalizePath($absolutePath); + return Filesystem::resolvePath($normalizedPath); } /** - * Return the path to a local version of the file - * we need this because we can't know if a file is stored local or not from - * outside the filestorage and for some purposes a local file is needed + * Return the path to a local representation of a file. * - * @param string $path + * For local storages this is usually the real on-disk path. + * For non-local storages this may be a temporary local file. + * + * @param string $path Path relative to this view, or absolute virtual filesystem path + * @return string|false Local file path, or false if unavailable */ - public function getLocalFile($path): string|false { - $parent = substr($path, 0, strrpos($path, '/') ?: 0); - $path = $this->getAbsolutePath($path); - [$storage, $internalPath] = Filesystem::resolvePath($path); - if (Filesystem::isValidPath($parent) && $storage) { - return $storage->getLocalFile($internalPath); - } else { + public function getLocalFile(string $path): string|false { + $parentPath = dirname($path); + if (!Filesystem::isValidPath($parentPath)) { return false; } + + [$storage, $internalPath] = $this->resolvePath($path); + if (!$storage) { + return false; + } + + return $storage->getLocalFile($internalPath); } /** From 14e837ce1152e8022cd91f7498085d7c47fe3776 Mon Sep 17 00:00:00 2001 From: Josh Date: Tue, 10 Mar 2026 19:42:16 -0400 Subject: [PATCH 2/3] refactor(View): add typing to getAbsolutePath and clarify contract Signed-off-by: Josh --- lib/private/Files/View.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index e85cd68037196..5917eb53cb0ea 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -96,12 +96,15 @@ public function __construct(string $root = '') { } /** - * @param ?string $path + * Returns an absolute path in Nextcloud's virtual filesystem for this view. + * + * The returned path is scoped by this view's fake root. + * * @psalm-template S as string|null * @psalm-param S $path * @psalm-return (S is string ? string : null) */ - public function getAbsolutePath($path = '/'): ?string { + public function getAbsolutePath(?string $path = '/'): ?string { if ($path === null) { return null; } From 0a7420d0a4bfdf5c2f3c53d9fecc515ba43991c8 Mon Sep 17 00:00:00 2001 From: Josh Date: Tue, 10 Mar 2026 21:40:44 -0400 Subject: [PATCH 3/3] chore(View): fixup for php-cs Signed-off-by: Josh --- lib/private/Files/View.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index 5917eb53cb0ea..94abe8caa4cb9 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -97,7 +97,7 @@ public function __construct(string $root = '') { /** * Returns an absolute path in Nextcloud's virtual filesystem for this view. - * + * * The returned path is scoped by this view's fake root. * * @psalm-template S as string|null