Merge pull request #58827 from nextcloud/fix/fix-fileinfo-path

fix(files): Fix FileInfo['path'] situation
This commit is contained in:
Côme Chilliet 2026-03-10 15:01:17 +01:00 committed by GitHub
commit c98244a79e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 13 additions and 14 deletions

View file

@ -230,14 +230,14 @@ class CacheTest extends TestCase {
[
[
'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 @@ class CacheTest extends TestCase {
[
[
'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 @@ class CacheTest extends TestCase {
[
[
'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',

View file

@ -82,6 +82,7 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
public function offsetGet(mixed $offset): mixed {
return match ($offset) {
'path' => $this->getPath(),
'type' => $this->getType(),
'etag' => $this->getEtag(),
'size' => $this->getSize(),

View file

@ -1642,8 +1642,6 @@ class View {
$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;

View file

@ -414,8 +414,8 @@ class ViewTest extends \Test\TestCase {
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 @@ class ViewTest extends \Test\TestCase {
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'));