summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2014-08-05 16:58:10 +0200
committerRobin Appelman <icewind@owncloud.com>2014-08-05 16:58:10 +0200
commitbf8f910a32ca20d9d2cdadfec9f46694b9a53190 (patch)
treedd9452b7667ebb37437a7ef02b4d56d7abf6ef49 /lib/private
parent54030f4eefa751478b64b277614c0db89435f18f (diff)
downloadnextcloud-server-bf8f910a32ca20d9d2cdadfec9f46694b9a53190.tar.gz
nextcloud-server-bf8f910a32ca20d9d2cdadfec9f46694b9a53190.zip
Fix Folder::getById
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/files/node/folder.php38
-rw-r--r--lib/private/files/node/root.php26
2 files changed, 25 insertions, 39 deletions
diff --git a/lib/private/files/node/folder.php b/lib/private/files/node/folder.php
index 3e23f5c2c94..f5211d5d748 100644
--- a/lib/private/files/node/folder.php
+++ b/lib/private/files/node/folder.php
@@ -34,15 +34,13 @@ class Folder extends Node implements \OCP\Files\Folder {
if ($this->path === '' or $this->path === '/') {
return $this->normalizePath($path);
}
- if (strpos($path, $this->path) !== 0) {
+ if ($path === $this->path) {
+ return '/';
+ } else if (strpos($path, $this->path . '/') !== 0) {
throw new NotFoundException();
} else {
$path = substr($path, strlen($this->path));
- if (strlen($path) === 0) {
- return '/';
- } else {
- return $this->normalizePath($path);
- }
+ return $this->normalizePath($path);
}
}
@@ -295,15 +293,29 @@ class Folder extends Node implements \OCP\Files\Folder {
* @return \OC\Files\Node\Node[]
*/
public function getById($id) {
- $nodes = $this->root->getById($id);
- $result = array();
- foreach ($nodes as $node) {
- $pathPart = substr($node->getPath(), 0, strlen($this->getPath()) + 1);
- if ($this->path === '/' or $pathPart === $this->getPath() . '/') {
- $result[] = $node;
+ $mounts = $this->root->getMountsIn($this->path);
+ $mounts[] = $this->root->getMount($this->path);
+ // reverse the array so we start with the storage this view is in
+ // which is the most likely to contain the file we're looking for
+ $mounts = array_reverse($mounts);
+
+ $nodes = array();
+ foreach ($mounts as $mount) {
+ /**
+ * @var \OC\Files\Mount\Mount $mount
+ */
+ if ($mount->getStorage()) {
+ $cache = $mount->getStorage()->getCache();
+ $internalPath = $cache->getPathById($id);
+ if (is_string($internalPath)) {
+ $fullPath = $mount->getMountPoint() . $internalPath;
+ if (!is_null($path = $this->getRelativePath($fullPath))) {
+ $nodes[] = $this->get($path);
+ }
+ }
}
}
- return $result;
+ return $nodes;
}
public function getFreeSpace() {
diff --git a/lib/private/files/node/root.php b/lib/private/files/node/root.php
index 70135285b0d..2172d474efb 100644
--- a/lib/private/files/node/root.php
+++ b/lib/private/files/node/root.php
@@ -169,32 +169,6 @@ class Root extends Folder implements Emitter {
}
}
- /**
- * search file by id
- *
- * An array is returned because in the case where a single storage is mounted in different places the same file
- * can exist in different places
- *
- * @param int $id
- * @throws \OCP\Files\NotFoundException
- * @return Node[]
- */
- public function getById($id) {
- $result = Cache::getById($id);
- if (is_null($result)) {
- throw new NotFoundException();
- } else {
- list($storageId, $internalPath) = $result;
- $nodes = array();
- $mounts = $this->mountManager->findByStorageId($storageId);
- foreach ($mounts as $mount) {
- $nodes[] = $this->get($mount->getMountPoint() . $internalPath);
- }
- return $nodes;
- }
-
- }
-
//most operations cant be done on the root
/**