summaryrefslogtreecommitdiffstats
path: root/lib/private/Files
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2017-08-22 15:44:52 +0200
committerRobin Appelman <robin@icewind.nl>2017-12-12 14:11:40 +0100
commit3ec1bbbde88a9fbd0b3449ff94bf5dcf15c5a17a (patch)
tree1e169b472705585d95dae7a0edde8ecc683890ef /lib/private/Files
parentf44d5bde5604eab628a4194fb2d111aa84ca2082 (diff)
downloadnextcloud-server-3ec1bbbde88a9fbd0b3449ff94bf5dcf15c5a17a.tar.gz
nextcloud-server-3ec1bbbde88a9fbd0b3449ff94bf5dcf15c5a17a.zip
Allow getting the filepath when getting cached mounts by fileid
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Files')
-rw-r--r--lib/private/Files/Config/CachedMountFileInfo.php48
-rw-r--r--lib/private/Files/Config/UserMountCache.php17
2 files changed, 63 insertions, 2 deletions
diff --git a/lib/private/Files/Config/CachedMountFileInfo.php b/lib/private/Files/Config/CachedMountFileInfo.php
new file mode 100644
index 00000000000..e315493a693
--- /dev/null
+++ b/lib/private/Files/Config/CachedMountFileInfo.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();
+ }
+} \ No newline at end of file
diff --git a/lib/private/Files/Config/UserMountCache.php b/lib/private/Files/Config/UserMountCache.php
index 5829fdf512c..f33176b1e7b 100644
--- a/lib/private/Files/Config/UserMountCache.php
+++ b/lib/private/Files/Config/UserMountCache.php
@@ -26,6 +26,7 @@ namespace OC\Files\Config;
use OCA\Files_Sharing\SharedMount;
use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\Files\Config\ICachedMountFileInfo;
use OCP\Files\Config\ICachedMountInfo;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\Mount\IMountPoint;
@@ -285,7 +286,7 @@ class UserMountCache implements IUserMountCache {
/**
* @param int $fileId
* @param string|null $user optionally restrict the results to a single user
- * @return ICachedMountInfo[]
+ * @return ICachedMountFileInfo[]
* @since 9.0.0
*/
public function getMountsForFileId($fileId, $user = null) {
@@ -297,7 +298,7 @@ class UserMountCache implements IUserMountCache {
$mountsForStorage = $this->getMountsForStorageId($storageId, $user);
// 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()) {
return true;
}
@@ -305,6 +306,18 @@ class UserMountCache implements IUserMountCache {
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);
}
/**