summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2014-08-07 13:40:17 +0200
committerRobin Appelman <icewind@owncloud.com>2014-08-07 13:40:17 +0200
commitf1091280de5bca203e3233206e75c0c7421065c1 (patch)
treea9b4165a405bff7d57de84607e996bddcb534a9b /lib
parent9e6b65fabe959706cca4342d650dc1a028d06ac3 (diff)
parenteb8683e6eeb0baa81395118f261cbfe6f002f411 (diff)
downloadnextcloud-server-f1091280de5bca203e3233206e75c0c7421065c1.tar.gz
nextcloud-server-f1091280de5bca203e3233206e75c0c7421065c1.zip
Merge pull request #10184 from owncloud/getbyid-node
Fix Folder::getById
Diffstat (limited to 'lib')
-rw-r--r--lib/private/files/node/folder.php41
-rw-r--r--lib/private/files/node/root.php28
2 files changed, 27 insertions, 42 deletions
diff --git a/lib/private/files/node/folder.php b/lib/private/files/node/folder.php
index 3e23f5c2c94..8c7acc339ae 100644
--- a/lib/private/files/node/folder.php
+++ b/lib/private/files/node/folder.php
@@ -27,22 +27,19 @@ class Folder extends Node implements \OCP\Files\Folder {
/**
* @param string $path
- * @throws \OCP\Files\NotFoundException
* @return string
*/
public function getRelativePath($path) {
if ($this->path === '' or $this->path === '/') {
return $this->normalizePath($path);
}
- if (strpos($path, $this->path) !== 0) {
- throw new NotFoundException();
+ if ($path === $this->path) {
+ return '/';
+ } else if (strpos($path, $this->path . '/') !== 0) {
+ return null;
} else {
$path = substr($path, strlen($this->path));
- if (strlen($path) === 0) {
- return '/';
- } else {
- return $this->normalizePath($path);
- }
+ return $this->normalizePath($path);
}
}
@@ -295,15 +292,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..18e7a6b681a 100644
--- a/lib/private/files/node/root.php
+++ b/lib/private/files/node/root.php
@@ -162,39 +162,13 @@ class Root extends Folder implements Emitter {
if ($this->view->file_exists($fullPath)) {
return $this->createNode($fullPath);
} else {
- throw new NotFoundException();
+ throw new NotFoundException($path);
}
} else {
throw new NotPermittedException();
}
}
- /**
- * 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
/**