summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2019-09-18 13:44:52 +0200
committerGitHub <noreply@github.com>2019-09-18 13:44:52 +0200
commit3efd9a12d7f3099925d36b7d13abee99d5b948f8 (patch)
treeaaa3ea6c446b1377118221e4271dbdf454b0aac0
parent6af36c8c6a1fa8b8d6b8bef26cd5553689437ea3 (diff)
parenta4ba2113b2e083ea8cf358d683b1b0a370cca385 (diff)
downloadnextcloud-server-3efd9a12d7f3099925d36b7d13abee99d5b948f8.tar.gz
nextcloud-server-3efd9a12d7f3099925d36b7d13abee99d5b948f8.zip
Merge pull request #17175 from nextcloud/feature/noid/make-getById-work-for-files-in-appdata
Fix getById for files in appdata and the root mount
-rw-r--r--lib/private/Files/Node/Folder.php44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php
index 8b2a93ffdc2..4a134cdcdbf 100644
--- a/lib/private/Files/Node/Folder.php
+++ b/lib/private/Files/Node/Folder.php
@@ -299,6 +299,9 @@ class Folder extends Node implements \OCP\Files\Folder {
}));
if (count($mountsContainingFile) === 0) {
+ if ($user === $this->getAppDataDirectoryName()) {
+ return $this->getByIdInRootMount((int) $id);
+ }
return [];
}
@@ -327,6 +330,47 @@ class Folder extends Node implements \OCP\Files\Folder {
});
}
+ protected function getAppDataDirectoryName(): string {
+ $instanceId = \OC::$server->getConfig()->getSystemValueString('instanceid');
+ return 'appdata_' . $instanceId;
+ }
+
+ /**
+ * In case the path we are currently in is inside the appdata_* folder,
+ * the original getById method does not work, because it can only look inside
+ * the user's mount points. But the user has no mount point for the root storage.
+ *
+ * So in that case we directly check the mount of the root if it contains
+ * the id. If it does we check if the path is inside the path we are working
+ * in.
+ *
+ * @param int $id
+ * @return array
+ */
+ protected function getByIdInRootMount(int $id): array {
+ $mount = $this->root->getMount('');
+ $cacheEntry = $mount->getStorage()->getCache($this->path)->get($id);
+ if (!$cacheEntry) {
+ return [];
+ }
+
+ $absolutePath = '/' . ltrim($cacheEntry->getPath(), '/');
+ $currentPath = rtrim($this->path, '/') . '/';
+
+ if (strpos($absolutePath, $currentPath) !== 0) {
+ return [];
+ }
+
+ return [$this->root->createNode(
+ $absolutePath, new \OC\Files\FileInfo(
+ $absolutePath,
+ $mount->getStorage(),
+ $cacheEntry->getPath(),
+ $cacheEntry,
+ $mount
+ ))];
+ }
+
public function getFreeSpace() {
return $this->view->free_space($this->path);
}