Skip to content

Commit

Permalink
fix: OCP\Files\Node\Folder::search was not setting the owner
Browse files Browse the repository at this point in the history
The owner was not set on the file info causing e.g. webdav searches to never return the known owner.

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux authored and backportbot[bot] committed Jul 30, 2024
1 parent 339a010 commit 264074c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
25 changes: 24 additions & 1 deletion lib/private/Files/Node/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use OC\Files\Search\SearchOrder;
use OC\Files\Search\SearchQuery;
use OC\Files\Utils\PathHelper;
use OC\User\LazyUser;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\FileInfo;
use OCP\Files\Mount\IMountPoint;
Expand All @@ -51,6 +52,9 @@
use OCP\IUserManager;

class Folder extends Node implements \OCP\Files\Folder {

private ?IUserManager $userManager = null;

/**
* Creates a Folder that represents a non-existing path
*
Expand Down Expand Up @@ -270,7 +274,26 @@ private function cacheEntryToFileInfo(IMountPoint $mount, string $appendRoot, IC
$cacheEntry['internalPath'] = $cacheEntry['path'];
$cacheEntry['path'] = rtrim($appendRoot . $cacheEntry->getPath(), '/');
$subPath = $cacheEntry['path'] !== '' ? '/' . $cacheEntry['path'] : '';
return new \OC\Files\FileInfo($this->path . $subPath, $mount->getStorage(), $cacheEntry['internalPath'], $cacheEntry, $mount);
$storage = $mount->getStorage();

$owner = null;
$ownerId = $storage->getOwner($cacheEntry['internalPath']);
if (!empty($ownerId)) {
// Cache the user manager (for performance)
if ($this->userManager === null) {
$this->userManager = \OCP\Server::get(IUserManager::class);
}
$owner = new LazyUser($ownerId, $this->userManager);
}

return new \OC\Files\FileInfo(
$this->path . $subPath,
$storage,
$cacheEntry['internalPath'],
$cacheEntry,
$mount,
$owner,
);
}

/**
Expand Down
14 changes: 11 additions & 3 deletions tests/lib/Files/Node/FolderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OCP\Files\Search\ISearchComparison;
use OCP\Files\Search\ISearchOrder;
use OCP\Files\Storage;
use PHPUnit\Framework\MockObject\MockObject;

/**
* Class FolderTest
Expand Down Expand Up @@ -291,18 +292,25 @@ public function testSearch() {
->getMock();
$root->method('getUser')
->willReturn($this->user);
/** @var Storage\IStorage $storage */
/** @var Storage\IStorage&MockObject $storage */
$storage = $this->createMock(Storage\IStorage::class);
$storage->method('getId')->willReturn('test::1');
$cache = new Cache($storage);

$storage->method('getCache')
->willReturn($cache);

$storage->expects($this->atLeastOnce())
->method('getOwner')
->with('qwerty')
->willReturn(false);

$mount = $this->createMock(IMountPoint::class);
$mount->method('getStorage')
$mount->expects($this->atLeastOnce())
->method('getStorage')
->willReturn($storage);
$mount->method('getInternalPath')
$mount->expects($this->atLeastOnce())
->method('getInternalPath')
->willReturn('foo');

$cache->insert('foo', ['size' => 200, 'mtime' => 55, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
Expand Down

0 comments on commit 264074c

Please sign in to comment.