Skip to content

Commit 05e1004

Browse files
committed
Allow getting the filepath when getting cached mounts by fileid
1 parent ae0789e commit 05e1004

7 files changed

Lines changed: 115 additions & 3 deletions

File tree

lib/composer/composer/autoload_classmap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
'OCP\\Files\\Cache\\IScanner' => $baseDir . '/lib/public/Files/Cache/IScanner.php',
117117
'OCP\\Files\\Cache\\IUpdater' => $baseDir . '/lib/public/Files/Cache/IUpdater.php',
118118
'OCP\\Files\\Cache\\IWatcher' => $baseDir . '/lib/public/Files/Cache/IWatcher.php',
119+
'OCP\\Files\\Config\\ICachedMountFileInfo' => $baseDir . '/lib/public/Files/Config/ICachedMountFieInfo.php',
119120
'OCP\\Files\\Config\\ICachedMountInfo' => $baseDir . '/lib/public/Files/Config/ICachedMountInfo.php',
120121
'OCP\\Files\\Config\\IHomeMountProvider' => $baseDir . '/lib/public/Files/Config/IHomeMountProvider.php',
121122
'OCP\\Files\\Config\\IMountProvider' => $baseDir . '/lib/public/Files/Config/IMountProvider.php',
@@ -577,6 +578,7 @@
577578
'OC\\Files\\Cache\\Wrapper\\CachePermissionsMask' => $baseDir . '/lib/private/Files/Cache/Wrapper/CachePermissionsMask.php',
578579
'OC\\Files\\Cache\\Wrapper\\CacheWrapper' => $baseDir . '/lib/private/Files/Cache/Wrapper/CacheWrapper.php',
579580
'OC\\Files\\Cache\\Wrapper\\JailPropagator' => $baseDir . '/lib/private/Files/Cache/Wrapper/JailPropagator.php',
581+
'OC\\Files\\Config\\CachedMountFileInfo' => $baseDir . '/lib/private/Files/Config/CachedMountFileInfo.php',
580582
'OC\\Files\\Config\\CachedMountInfo' => $baseDir . '/lib/private/Files/Config/CachedMountInfo.php',
581583
'OC\\Files\\Config\\LazyStorageMountInfo' => $baseDir . '/lib/private/Files/Config/LazyStorageMountInfo.php',
582584
'OC\\Files\\Config\\MountProviderCollection' => $baseDir . '/lib/private/Files/Config/MountProviderCollection.php',

lib/composer/composer/autoload_static.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
146146
'OCP\\Files\\Cache\\IScanner' => __DIR__ . '/../../..' . '/lib/public/Files/Cache/IScanner.php',
147147
'OCP\\Files\\Cache\\IUpdater' => __DIR__ . '/../../..' . '/lib/public/Files/Cache/IUpdater.php',
148148
'OCP\\Files\\Cache\\IWatcher' => __DIR__ . '/../../..' . '/lib/public/Files/Cache/IWatcher.php',
149+
'OCP\\Files\\Config\\ICachedMountFileInfo' => __DIR__ . '/../../..' . '/lib/public/Files/Config/ICachedMountFieInfo.php',
149150
'OCP\\Files\\Config\\ICachedMountInfo' => __DIR__ . '/../../..' . '/lib/public/Files/Config/ICachedMountInfo.php',
150151
'OCP\\Files\\Config\\IHomeMountProvider' => __DIR__ . '/../../..' . '/lib/public/Files/Config/IHomeMountProvider.php',
151152
'OCP\\Files\\Config\\IMountProvider' => __DIR__ . '/../../..' . '/lib/public/Files/Config/IMountProvider.php',
@@ -607,6 +608,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
607608
'OC\\Files\\Cache\\Wrapper\\CachePermissionsMask' => __DIR__ . '/../../..' . '/lib/private/Files/Cache/Wrapper/CachePermissionsMask.php',
608609
'OC\\Files\\Cache\\Wrapper\\CacheWrapper' => __DIR__ . '/../../..' . '/lib/private/Files/Cache/Wrapper/CacheWrapper.php',
609610
'OC\\Files\\Cache\\Wrapper\\JailPropagator' => __DIR__ . '/../../..' . '/lib/private/Files/Cache/Wrapper/JailPropagator.php',
611+
'OC\\Files\\Config\\CachedMountFileInfo' => __DIR__ . '/../../..' . '/lib/private/Files/Config/CachedMountFileInfo.php',
610612
'OC\\Files\\Config\\CachedMountInfo' => __DIR__ . '/../../..' . '/lib/private/Files/Config/CachedMountInfo.php',
611613
'OC\\Files\\Config\\LazyStorageMountInfo' => __DIR__ . '/../../..' . '/lib/private/Files/Config/LazyStorageMountInfo.php',
612614
'OC\\Files\\Config\\MountProviderCollection' => __DIR__ . '/../../..' . '/lib/private/Files/Config/MountProviderCollection.php',
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2017 Robin Appelman <robin@icewind.nl>
4+
*
5+
* @license GNU AGPL version 3 or any later version
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Affero General Public License as
9+
* published by the Free Software Foundation, either version 3 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Affero General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
*/
21+
22+
namespace OC\Files\Config;
23+
24+
25+
use OCP\Files\Config\ICachedMountFileInfo;
26+
use OCP\IUser;
27+
28+
class CachedMountFileInfo extends CachedMountInfo implements ICachedMountFileInfo {
29+
/** @var string */
30+
private $internalPath;
31+
32+
public function __construct(IUser $user, $storageId, $rootId, $mountPoint, $mountId = null, $rootInternalPath = '', $internalPath) {
33+
parent::__construct($user, $storageId, $rootId, $mountPoint, $mountId, $rootInternalPath);
34+
$this->internalPath = $internalPath;
35+
}
36+
37+
public function getInternalPath() {
38+
if ($this->getRootInternalPath()) {
39+
return substr($this->internalPath, strlen($this->getRootInternalPath()) + 1);
40+
} else {
41+
return $this->internalPath;
42+
}
43+
}
44+
45+
public function getPath() {
46+
return $this->getMountPoint() . $this->getInternalPath();
47+
}
48+
}

lib/private/Files/Config/UserMountCache.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use OC\DB\QueryBuilder\Literal;
2828
use OCA\Files_Sharing\SharedMount;
2929
use OCP\DB\QueryBuilder\IQueryBuilder;
30+
use OCP\Files\Config\ICachedMountFileInfo;
3031
use OCP\Files\Config\ICachedMountInfo;
3132
use OCP\Files\Config\IUserMountCache;
3233
use OCP\Files\Mount\IMountPoint;
@@ -282,7 +283,7 @@ private function getCacheInfoFromFileId($fileId) {
282283
/**
283284
* @param int $fileId
284285
* @param string|null $user optionally restrict the results to a single user
285-
* @return ICachedMountInfo[]
286+
* @return ICachedMountFileInfo[]
286287
* @since 9.0.0
287288
*/
288289
public function getMountsForFileId($fileId, $user = null) {
@@ -294,14 +295,26 @@ public function getMountsForFileId($fileId, $user = null) {
294295
$mountsForStorage = $this->getMountsForStorageId($storageId, $user);
295296

296297
// filter mounts that are from the same storage but a different directory
297-
return array_filter($mountsForStorage, function (ICachedMountInfo $mount) use ($internalPath, $fileId) {
298+
$filteredMounts = array_filter($mountsForStorage, function (ICachedMountInfo $mount) use ($internalPath, $fileId) {
298299
if ($fileId === $mount->getRootId()) {
299300
return true;
300301
}
301302
$internalMountPath = $mount->getRootInternalPath();
302303

303304
return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath . '/';
304305
});
306+
307+
return array_map(function (ICachedMountInfo $mount) use ($internalPath) {
308+
return new CachedMountFileInfo(
309+
$mount->getUser(),
310+
$mount->getStorageId(),
311+
$mount->getRootId(),
312+
$mount->getMountPoint(),
313+
$mount->getMountId(),
314+
$mount->getRootInternalPath(),
315+
$internalPath
316+
);
317+
}, $filteredMounts);
305318
}
306319

307320
/**
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2017 Robin Appelman <robin@icewind.nl>
4+
*
5+
* @license GNU AGPL version 3 or any later version
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Affero General Public License as
9+
* published by the Free Software Foundation, either version 3 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Affero General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
*/
21+
22+
namespace OCP\Files\Config;
23+
24+
/**
25+
* Holds information about a mount for a user
26+
*
27+
* @since 13.0.0
28+
*/
29+
interface ICachedMountFileInfo extends ICachedMountInfo {
30+
/**
31+
* Return the path for the file within the cached mount
32+
*
33+
* @return string
34+
* @since 13.0.0
35+
*/
36+
public function getInternalPath();
37+
38+
/**
39+
* @return string
40+
* @since 13.0.0
41+
*/
42+
public function getPath();
43+
}

lib/public/Files/Config/IUserMountCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function getMountsForRootId($rootFileId);
7373
*
7474
* @param int $fileId
7575
* @param string|null $user optionally restrict the results to a single user @since 12.0.0
76-
* @return ICachedMountInfo[]
76+
* @return ICachedMountFileInfo[]
7777
* @since 9.0.0
7878
*/
7979
public function getMountsForFileId($fileId, $user = null);

tests/lib/Files/Config/UserMountCacheTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ public function testGetMountsForFileIdSubFolder() {
380380
$this->assertEquals($user1, $cachedMounts[0]->getUser());
381381
$this->assertEquals($rootId, $cachedMounts[0]->getRootId());
382382
$this->assertEquals(2, $cachedMounts[0]->getStorageId());
383+
$this->assertEquals('foo/bar', $cachedMounts[0]->getInternalPath());
384+
$this->assertEquals('/foo/foo/bar', $cachedMounts[0]->getPath());
383385
}
384386

385387
public function testGetMountsForFileIdSubFolderMount() {
@@ -412,6 +414,8 @@ public function testGetMountsForFileIdSubFolderMount() {
412414
$this->assertEquals($folderId, $cachedMounts[0]->getRootId());
413415
$this->assertEquals(2, $cachedMounts[0]->getStorageId());
414416
$this->assertEquals('foo', $cachedMounts[0]->getRootInternalPath());
417+
$this->assertEquals('bar', $cachedMounts[0]->getInternalPath());
418+
$this->assertEquals('/bar', $cachedMounts[0]->getPath());
415419
}
416420

417421
public function testGetMountsForFileIdSubFolderMountOutside() {

0 commit comments

Comments
 (0)