From 842b3f9e0a261536fb3bbd4b7ced301492a8f17b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 10 Mar 2026 11:56:31 +0100 Subject: [PATCH 1/2] fix(files): Fix FileInfo['path'] situation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously $fileInfo->getPath() and $fileInfo['path'] would return different things. The [] version was not consistent, being sometimes relative and sometimes kind of absolute, and sometimes plenty wrong (like when used from occ commands, because there is no user in session). So this is always returning absolute now. Signed-off-by: Côme Chilliet --- apps/files_sharing/tests/CacheTest.php | 16 ++++++++-------- lib/private/Files/FileInfo.php | 1 + lib/private/Files/View.php | 2 -- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/apps/files_sharing/tests/CacheTest.php b/apps/files_sharing/tests/CacheTest.php index 777f3b1d0c65a..0e4736ff25c2b 100644 --- a/apps/files_sharing/tests/CacheTest.php +++ b/apps/files_sharing/tests/CacheTest.php @@ -230,14 +230,14 @@ public function testGetFolderContentsInRoot(): void { [ [ 'name' => 'shareddir', - 'path' => 'files/shareddir', + 'path' => '/' . self::TEST_FILES_SHARING_API_USER2 . '/files/shareddir', 'mimetype' => 'httpd/unix-directory', 'uid_owner' => self::TEST_FILES_SHARING_API_USER1, 'displayname_owner' => 'User One', ], [ 'name' => 'shared single file.txt', - 'path' => 'files/shared single file.txt', + 'path' => '/' . self::TEST_FILES_SHARING_API_USER2 . '/files/shared single file.txt', 'mimetype' => 'text/plain', 'uid_owner' => self::TEST_FILES_SHARING_API_USER1, 'displayname_owner' => 'User One', @@ -254,21 +254,21 @@ public function testGetFolderContentsInSubdir(): void { [ [ 'name' => 'bar.txt', - 'path' => 'bar.txt', + 'path' => '/' . self::TEST_FILES_SHARING_API_USER2 . '/files/shareddir/bar.txt', 'mimetype' => 'text/plain', 'uid_owner' => self::TEST_FILES_SHARING_API_USER1, 'displayname_owner' => 'User One', ], [ 'name' => 'emptydir', - 'path' => 'emptydir', + 'path' => '/' . self::TEST_FILES_SHARING_API_USER2 . '/files/shareddir/emptydir', 'mimetype' => 'httpd/unix-directory', 'uid_owner' => self::TEST_FILES_SHARING_API_USER1, 'displayname_owner' => 'User One', ], [ 'name' => 'subdir', - 'path' => 'subdir', + 'path' => '/' . self::TEST_FILES_SHARING_API_USER2 . '/files/shareddir/subdir', 'mimetype' => 'httpd/unix-directory', 'uid_owner' => self::TEST_FILES_SHARING_API_USER1, 'displayname_owner' => 'User One', @@ -336,21 +336,21 @@ public function testGetFolderContentsWhenSubSubdirShared(): void { [ [ 'name' => 'another too.txt', - 'path' => 'another too.txt', + 'path' => '/' . self::TEST_FILES_SHARING_API_USER3 . '/files/subdir/another too.txt', 'mimetype' => 'text/plain', 'uid_owner' => self::TEST_FILES_SHARING_API_USER1, 'displayname_owner' => 'User One', ], [ 'name' => 'another.txt', - 'path' => 'another.txt', + 'path' => '/' . self::TEST_FILES_SHARING_API_USER3 . '/files/subdir/another.txt', 'mimetype' => 'text/plain', 'uid_owner' => self::TEST_FILES_SHARING_API_USER1, 'displayname_owner' => 'User One', ], [ 'name' => 'not a text file.xml', - 'path' => 'not a text file.xml', + 'path' => '/' . self::TEST_FILES_SHARING_API_USER3 . '/files/subdir/not a text file.xml', 'mimetype' => 'application/xml', 'uid_owner' => self::TEST_FILES_SHARING_API_USER1, 'displayname_owner' => 'User One', diff --git a/lib/private/Files/FileInfo.php b/lib/private/Files/FileInfo.php index d864ebe2a0913..a80e1e30a6611 100644 --- a/lib/private/Files/FileInfo.php +++ b/lib/private/Files/FileInfo.php @@ -82,6 +82,7 @@ public function offsetUnset($offset): void { public function offsetGet(mixed $offset): mixed { return match ($offset) { + 'path' => $this->getPath(), 'type' => $this->getType(), 'etag' => $this->getEtag(), 'size' => $this->getSize(), diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index 5e728d0a8d0a1..13e6a3995dccb 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -1642,8 +1642,6 @@ public function getDirectoryContent(string $directory, ?string $mimeTypeFilter = $rootEntry['permissions'] = $permissions & (Constants::PERMISSION_ALL - (Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE)); } - $rootEntry['path'] = substr(Filesystem::normalizePath($path . '/' . $rootEntry['name']), strlen($user) + 2); // full path without /$user/ - // if sharing was disabled for the user we remove the share permissions if ($sharingDisabled) { $rootEntry['permissions'] = $rootEntry['permissions'] & ~Constants::PERMISSION_SHARE; From 397454ff4a299a16a17c723fb1e62792ca9a7d8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 10 Mar 2026 12:34:50 +0100 Subject: [PATCH 2/2] fix: Adapt ViewTest to ['path'] being absolute MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- tests/lib/Files/ViewTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php index ce20ce7835a01..94d55b4e9c411 100644 --- a/tests/lib/Files/ViewTest.php +++ b/tests/lib/Files/ViewTest.php @@ -414,8 +414,8 @@ public function testSearch(): void { foreach ($results as $result) { $paths[] = $result['path']; } - $this->assertContains('/anotherstorage/folder/bar.txt', $paths); - $this->assertContains('/bar.txt', $paths); + $this->assertContains('/folder/anotherstorage/folder/bar.txt', $paths); + $this->assertContains('/folder/bar.txt', $paths); $results = $folderView->search('foo'); $this->assertCount(2, $results); @@ -423,8 +423,8 @@ public function testSearch(): void { foreach ($results as $result) { $paths[] = $result['path']; } - $this->assertContains('/anotherstorage/foo.txt', $paths); - $this->assertContains('/anotherstorage/foo.png', $paths); + $this->assertContains('/folder/anotherstorage/foo.txt', $paths); + $this->assertContains('/folder/anotherstorage/foo.png', $paths); $this->assertCount(6, $rootView->searchByMime('text')); $this->assertCount(3, $folderView->searchByMime('text'));