Merge pull request #6220 from nextcloud/cached-mount-info-filepath
Allow getting the filepath when getting cached mounts by fileid
This commit is contained in:
commit
989a8a3668
|
@ -123,6 +123,7 @@ return array(
|
||||||
'OCP\\Files\\Cache\\IScanner' => $baseDir . '/lib/public/Files/Cache/IScanner.php',
|
'OCP\\Files\\Cache\\IScanner' => $baseDir . '/lib/public/Files/Cache/IScanner.php',
|
||||||
'OCP\\Files\\Cache\\IUpdater' => $baseDir . '/lib/public/Files/Cache/IUpdater.php',
|
'OCP\\Files\\Cache\\IUpdater' => $baseDir . '/lib/public/Files/Cache/IUpdater.php',
|
||||||
'OCP\\Files\\Cache\\IWatcher' => $baseDir . '/lib/public/Files/Cache/IWatcher.php',
|
'OCP\\Files\\Cache\\IWatcher' => $baseDir . '/lib/public/Files/Cache/IWatcher.php',
|
||||||
|
'OCP\\Files\\Config\\ICachedMountFileInfo' => $baseDir . '/lib/public/Files/Config/ICachedMountFieInfo.php',
|
||||||
'OCP\\Files\\Config\\ICachedMountInfo' => $baseDir . '/lib/public/Files/Config/ICachedMountInfo.php',
|
'OCP\\Files\\Config\\ICachedMountInfo' => $baseDir . '/lib/public/Files/Config/ICachedMountInfo.php',
|
||||||
'OCP\\Files\\Config\\IHomeMountProvider' => $baseDir . '/lib/public/Files/Config/IHomeMountProvider.php',
|
'OCP\\Files\\Config\\IHomeMountProvider' => $baseDir . '/lib/public/Files/Config/IHomeMountProvider.php',
|
||||||
'OCP\\Files\\Config\\IMountProvider' => $baseDir . '/lib/public/Files/Config/IMountProvider.php',
|
'OCP\\Files\\Config\\IMountProvider' => $baseDir . '/lib/public/Files/Config/IMountProvider.php',
|
||||||
|
@ -603,6 +604,7 @@ return array(
|
||||||
'OC\\Files\\Cache\\Wrapper\\CachePermissionsMask' => $baseDir . '/lib/private/Files/Cache/Wrapper/CachePermissionsMask.php',
|
'OC\\Files\\Cache\\Wrapper\\CachePermissionsMask' => $baseDir . '/lib/private/Files/Cache/Wrapper/CachePermissionsMask.php',
|
||||||
'OC\\Files\\Cache\\Wrapper\\CacheWrapper' => $baseDir . '/lib/private/Files/Cache/Wrapper/CacheWrapper.php',
|
'OC\\Files\\Cache\\Wrapper\\CacheWrapper' => $baseDir . '/lib/private/Files/Cache/Wrapper/CacheWrapper.php',
|
||||||
'OC\\Files\\Cache\\Wrapper\\JailPropagator' => $baseDir . '/lib/private/Files/Cache/Wrapper/JailPropagator.php',
|
'OC\\Files\\Cache\\Wrapper\\JailPropagator' => $baseDir . '/lib/private/Files/Cache/Wrapper/JailPropagator.php',
|
||||||
|
'OC\\Files\\Config\\CachedMountFileInfo' => $baseDir . '/lib/private/Files/Config/CachedMountFileInfo.php',
|
||||||
'OC\\Files\\Config\\CachedMountInfo' => $baseDir . '/lib/private/Files/Config/CachedMountInfo.php',
|
'OC\\Files\\Config\\CachedMountInfo' => $baseDir . '/lib/private/Files/Config/CachedMountInfo.php',
|
||||||
'OC\\Files\\Config\\LazyStorageMountInfo' => $baseDir . '/lib/private/Files/Config/LazyStorageMountInfo.php',
|
'OC\\Files\\Config\\LazyStorageMountInfo' => $baseDir . '/lib/private/Files/Config/LazyStorageMountInfo.php',
|
||||||
'OC\\Files\\Config\\MountProviderCollection' => $baseDir . '/lib/private/Files/Config/MountProviderCollection.php',
|
'OC\\Files\\Config\\MountProviderCollection' => $baseDir . '/lib/private/Files/Config/MountProviderCollection.php',
|
||||||
|
|
|
@ -153,6 +153,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
|
||||||
'OCP\\Files\\Cache\\IScanner' => __DIR__ . '/../../..' . '/lib/public/Files/Cache/IScanner.php',
|
'OCP\\Files\\Cache\\IScanner' => __DIR__ . '/../../..' . '/lib/public/Files/Cache/IScanner.php',
|
||||||
'OCP\\Files\\Cache\\IUpdater' => __DIR__ . '/../../..' . '/lib/public/Files/Cache/IUpdater.php',
|
'OCP\\Files\\Cache\\IUpdater' => __DIR__ . '/../../..' . '/lib/public/Files/Cache/IUpdater.php',
|
||||||
'OCP\\Files\\Cache\\IWatcher' => __DIR__ . '/../../..' . '/lib/public/Files/Cache/IWatcher.php',
|
'OCP\\Files\\Cache\\IWatcher' => __DIR__ . '/../../..' . '/lib/public/Files/Cache/IWatcher.php',
|
||||||
|
'OCP\\Files\\Config\\ICachedMountFileInfo' => __DIR__ . '/../../..' . '/lib/public/Files/Config/ICachedMountFieInfo.php',
|
||||||
'OCP\\Files\\Config\\ICachedMountInfo' => __DIR__ . '/../../..' . '/lib/public/Files/Config/ICachedMountInfo.php',
|
'OCP\\Files\\Config\\ICachedMountInfo' => __DIR__ . '/../../..' . '/lib/public/Files/Config/ICachedMountInfo.php',
|
||||||
'OCP\\Files\\Config\\IHomeMountProvider' => __DIR__ . '/../../..' . '/lib/public/Files/Config/IHomeMountProvider.php',
|
'OCP\\Files\\Config\\IHomeMountProvider' => __DIR__ . '/../../..' . '/lib/public/Files/Config/IHomeMountProvider.php',
|
||||||
'OCP\\Files\\Config\\IMountProvider' => __DIR__ . '/../../..' . '/lib/public/Files/Config/IMountProvider.php',
|
'OCP\\Files\\Config\\IMountProvider' => __DIR__ . '/../../..' . '/lib/public/Files/Config/IMountProvider.php',
|
||||||
|
@ -633,6 +634,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
|
||||||
'OC\\Files\\Cache\\Wrapper\\CachePermissionsMask' => __DIR__ . '/../../..' . '/lib/private/Files/Cache/Wrapper/CachePermissionsMask.php',
|
'OC\\Files\\Cache\\Wrapper\\CachePermissionsMask' => __DIR__ . '/../../..' . '/lib/private/Files/Cache/Wrapper/CachePermissionsMask.php',
|
||||||
'OC\\Files\\Cache\\Wrapper\\CacheWrapper' => __DIR__ . '/../../..' . '/lib/private/Files/Cache/Wrapper/CacheWrapper.php',
|
'OC\\Files\\Cache\\Wrapper\\CacheWrapper' => __DIR__ . '/../../..' . '/lib/private/Files/Cache/Wrapper/CacheWrapper.php',
|
||||||
'OC\\Files\\Cache\\Wrapper\\JailPropagator' => __DIR__ . '/../../..' . '/lib/private/Files/Cache/Wrapper/JailPropagator.php',
|
'OC\\Files\\Cache\\Wrapper\\JailPropagator' => __DIR__ . '/../../..' . '/lib/private/Files/Cache/Wrapper/JailPropagator.php',
|
||||||
|
'OC\\Files\\Config\\CachedMountFileInfo' => __DIR__ . '/../../..' . '/lib/private/Files/Config/CachedMountFileInfo.php',
|
||||||
'OC\\Files\\Config\\CachedMountInfo' => __DIR__ . '/../../..' . '/lib/private/Files/Config/CachedMountInfo.php',
|
'OC\\Files\\Config\\CachedMountInfo' => __DIR__ . '/../../..' . '/lib/private/Files/Config/CachedMountInfo.php',
|
||||||
'OC\\Files\\Config\\LazyStorageMountInfo' => __DIR__ . '/../../..' . '/lib/private/Files/Config/LazyStorageMountInfo.php',
|
'OC\\Files\\Config\\LazyStorageMountInfo' => __DIR__ . '/../../..' . '/lib/private/Files/Config/LazyStorageMountInfo.php',
|
||||||
'OC\\Files\\Config\\MountProviderCollection' => __DIR__ . '/../../..' . '/lib/private/Files/Config/MountProviderCollection.php',
|
'OC\\Files\\Config\\MountProviderCollection' => __DIR__ . '/../../..' . '/lib/private/Files/Config/MountProviderCollection.php',
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @copyright Copyright (c) 2017 Robin Appelman <robin@icewind.nl>
|
||||||
|
*
|
||||||
|
* @license GNU AGPL version 3 or any later version
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OC\Files\Config;
|
||||||
|
|
||||||
|
|
||||||
|
use OCP\Files\Config\ICachedMountFileInfo;
|
||||||
|
use OCP\IUser;
|
||||||
|
|
||||||
|
class CachedMountFileInfo extends CachedMountInfo implements ICachedMountFileInfo {
|
||||||
|
/** @var string */
|
||||||
|
private $internalPath;
|
||||||
|
|
||||||
|
public function __construct(IUser $user, $storageId, $rootId, $mountPoint, $mountId = null, $rootInternalPath = '', $internalPath) {
|
||||||
|
parent::__construct($user, $storageId, $rootId, $mountPoint, $mountId, $rootInternalPath);
|
||||||
|
$this->internalPath = $internalPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getInternalPath() {
|
||||||
|
if ($this->getRootInternalPath()) {
|
||||||
|
return substr($this->internalPath, strlen($this->getRootInternalPath()) + 1);
|
||||||
|
} else {
|
||||||
|
return $this->internalPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPath() {
|
||||||
|
return $this->getMountPoint() . $this->getInternalPath();
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,6 +28,7 @@ namespace OC\Files\Config;
|
||||||
use OC\DB\QueryBuilder\Literal;
|
use OC\DB\QueryBuilder\Literal;
|
||||||
use OCA\Files_Sharing\SharedMount;
|
use OCA\Files_Sharing\SharedMount;
|
||||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||||
|
use OCP\Files\Config\ICachedMountFileInfo;
|
||||||
use OCP\Files\Config\ICachedMountInfo;
|
use OCP\Files\Config\ICachedMountInfo;
|
||||||
use OCP\Files\Config\IUserMountCache;
|
use OCP\Files\Config\IUserMountCache;
|
||||||
use OCP\Files\Mount\IMountPoint;
|
use OCP\Files\Mount\IMountPoint;
|
||||||
|
@ -287,7 +288,7 @@ class UserMountCache implements IUserMountCache {
|
||||||
/**
|
/**
|
||||||
* @param int $fileId
|
* @param int $fileId
|
||||||
* @param string|null $user optionally restrict the results to a single user
|
* @param string|null $user optionally restrict the results to a single user
|
||||||
* @return ICachedMountInfo[]
|
* @return ICachedMountFileInfo[]
|
||||||
* @since 9.0.0
|
* @since 9.0.0
|
||||||
*/
|
*/
|
||||||
public function getMountsForFileId($fileId, $user = null) {
|
public function getMountsForFileId($fileId, $user = null) {
|
||||||
|
@ -299,7 +300,7 @@ class UserMountCache implements IUserMountCache {
|
||||||
$mountsForStorage = $this->getMountsForStorageId($storageId, $user);
|
$mountsForStorage = $this->getMountsForStorageId($storageId, $user);
|
||||||
|
|
||||||
// filter mounts that are from the same storage but a different directory
|
// filter mounts that are from the same storage but a different directory
|
||||||
return array_filter($mountsForStorage, function (ICachedMountInfo $mount) use ($internalPath, $fileId) {
|
$filteredMounts = array_filter($mountsForStorage, function (ICachedMountInfo $mount) use ($internalPath, $fileId) {
|
||||||
if ($fileId === $mount->getRootId()) {
|
if ($fileId === $mount->getRootId()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -307,6 +308,18 @@ class UserMountCache implements IUserMountCache {
|
||||||
|
|
||||||
return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath . '/';
|
return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath . '/';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return array_map(function (ICachedMountInfo $mount) use ($internalPath) {
|
||||||
|
return new CachedMountFileInfo(
|
||||||
|
$mount->getUser(),
|
||||||
|
$mount->getStorageId(),
|
||||||
|
$mount->getRootId(),
|
||||||
|
$mount->getMountPoint(),
|
||||||
|
$mount->getMountId(),
|
||||||
|
$mount->getRootInternalPath(),
|
||||||
|
$internalPath
|
||||||
|
);
|
||||||
|
}, $filteredMounts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @copyright Copyright (c) 2017 Robin Appelman <robin@icewind.nl>
|
||||||
|
*
|
||||||
|
* @license GNU AGPL version 3 or any later version
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OCP\Files\Config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds information about a mount for a user
|
||||||
|
*
|
||||||
|
* @since 13.0.0
|
||||||
|
*/
|
||||||
|
interface ICachedMountFileInfo extends ICachedMountInfo {
|
||||||
|
/**
|
||||||
|
* Return the path for the file within the cached mount
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @since 13.0.0
|
||||||
|
*/
|
||||||
|
public function getInternalPath();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
* @since 13.0.0
|
||||||
|
*/
|
||||||
|
public function getPath();
|
||||||
|
}
|
|
@ -74,7 +74,7 @@ interface IUserMountCache {
|
||||||
*
|
*
|
||||||
* @param int $fileId
|
* @param int $fileId
|
||||||
* @param string|null $user optionally restrict the results to a single user @since 12.0.0
|
* @param string|null $user optionally restrict the results to a single user @since 12.0.0
|
||||||
* @return ICachedMountInfo[]
|
* @return ICachedMountFileInfo[]
|
||||||
* @since 9.0.0
|
* @since 9.0.0
|
||||||
*/
|
*/
|
||||||
public function getMountsForFileId($fileId, $user = null);
|
public function getMountsForFileId($fileId, $user = null);
|
||||||
|
|
|
@ -380,6 +380,8 @@ class UserMountCacheTest extends TestCase {
|
||||||
$this->assertEquals($user1, $cachedMounts[0]->getUser());
|
$this->assertEquals($user1, $cachedMounts[0]->getUser());
|
||||||
$this->assertEquals($rootId, $cachedMounts[0]->getRootId());
|
$this->assertEquals($rootId, $cachedMounts[0]->getRootId());
|
||||||
$this->assertEquals(2, $cachedMounts[0]->getStorageId());
|
$this->assertEquals(2, $cachedMounts[0]->getStorageId());
|
||||||
|
$this->assertEquals('foo/bar', $cachedMounts[0]->getInternalPath());
|
||||||
|
$this->assertEquals('/foo/foo/bar', $cachedMounts[0]->getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetMountsForFileIdSubFolderMount() {
|
public function testGetMountsForFileIdSubFolderMount() {
|
||||||
|
@ -412,6 +414,8 @@ class UserMountCacheTest extends TestCase {
|
||||||
$this->assertEquals($folderId, $cachedMounts[0]->getRootId());
|
$this->assertEquals($folderId, $cachedMounts[0]->getRootId());
|
||||||
$this->assertEquals(2, $cachedMounts[0]->getStorageId());
|
$this->assertEquals(2, $cachedMounts[0]->getStorageId());
|
||||||
$this->assertEquals('foo', $cachedMounts[0]->getRootInternalPath());
|
$this->assertEquals('foo', $cachedMounts[0]->getRootInternalPath());
|
||||||
|
$this->assertEquals('bar', $cachedMounts[0]->getInternalPath());
|
||||||
|
$this->assertEquals('/bar', $cachedMounts[0]->getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetMountsForFileIdSubFolderMountOutside() {
|
public function testGetMountsForFileIdSubFolderMountOutside() {
|
||||||
|
|
Loading…
Reference in New Issue