Skip to content

Commit 21f558b

Browse files
authored
Merge pull request #46379 from nextcloud/fix/folder-search-owner
fix: `OCP\Files\Node\Folder::search` was not setting the owner
2 parents b9f35a7 + cf935e3 commit 21f558b

2 files changed

Lines changed: 35 additions & 4 deletions

File tree

lib/private/Files/Node/Folder.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use OC\Files\Search\SearchOrder;
1313
use OC\Files\Search\SearchQuery;
1414
use OC\Files\Utils\PathHelper;
15+
use OC\User\LazyUser;
1516
use OCP\Files\Cache\ICacheEntry;
1617
use OCP\Files\FileInfo;
1718
use OCP\Files\Mount\IMountPoint;
@@ -26,6 +27,9 @@
2627
use OCP\IUserManager;
2728

2829
class Folder extends Node implements \OCP\Files\Folder {
30+
31+
private ?IUserManager $userManager = null;
32+
2933
/**
3034
* Creates a Folder that represents a non-existing path
3135
*
@@ -245,7 +249,26 @@ private function cacheEntryToFileInfo(IMountPoint $mount, string $appendRoot, IC
245249
$cacheEntry['internalPath'] = $cacheEntry['path'];
246250
$cacheEntry['path'] = rtrim($appendRoot . $cacheEntry->getPath(), '/');
247251
$subPath = $cacheEntry['path'] !== '' ? '/' . $cacheEntry['path'] : '';
248-
return new \OC\Files\FileInfo($this->path . $subPath, $mount->getStorage(), $cacheEntry['internalPath'], $cacheEntry, $mount);
252+
$storage = $mount->getStorage();
253+
254+
$owner = null;
255+
$ownerId = $storage->getOwner($cacheEntry['internalPath']);
256+
if (!empty($ownerId)) {
257+
// Cache the user manager (for performance)
258+
if ($this->userManager === null) {
259+
$this->userManager = \OCP\Server::get(IUserManager::class);
260+
}
261+
$owner = new LazyUser($ownerId, $this->userManager);
262+
}
263+
264+
return new \OC\Files\FileInfo(
265+
$this->path . $subPath,
266+
$storage,
267+
$cacheEntry['internalPath'],
268+
$cacheEntry,
269+
$mount,
270+
$owner,
271+
);
249272
}
250273

251274
/**

tests/lib/Files/Node/FolderTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use OCP\Files\Search\ISearchComparison;
3030
use OCP\Files\Search\ISearchOrder;
3131
use OCP\Files\Storage;
32+
use PHPUnit\Framework\MockObject\MockObject;
3233

3334
/**
3435
* Class FolderTest
@@ -290,18 +291,25 @@ public function testSearch() {
290291
->getMock();
291292
$root->method('getUser')
292293
->willReturn($this->user);
293-
/** @var Storage\IStorage $storage */
294+
/** @var Storage\IStorage&MockObject $storage */
294295
$storage = $this->createMock(Storage\IStorage::class);
295296
$storage->method('getId')->willReturn('test::1');
296297
$cache = new Cache($storage);
297298

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

302+
$storage->expects($this->atLeastOnce())
303+
->method('getOwner')
304+
->with('qwerty')
305+
->willReturn(false);
306+
301307
$mount = $this->createMock(IMountPoint::class);
302-
$mount->method('getStorage')
308+
$mount->expects($this->atLeastOnce())
309+
->method('getStorage')
303310
->willReturn($storage);
304-
$mount->method('getInternalPath')
311+
$mount->expects($this->atLeastOnce())
312+
->method('getInternalPath')
305313
->willReturn('foo');
306314

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

0 commit comments

Comments
 (0)