summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2015-09-15 18:04:01 +0200
committerRobin Appelman <robin@icewind.nl>2015-09-15 18:04:01 +0200
commit9883d5b85d8ae1e2d1d58b345c96a0563e112b97 (patch)
tree8a641bdd10885e7a3c6df81bd783e988017bb187 /lib
parente545c2eec56c1f5c99485d4a29949d975961084c (diff)
parent9f11b277976663297e201d81a7051b166968cba0 (diff)
downloadnextcloud-server-9883d5b85d8ae1e2d1d58b345c96a0563e112b97.tar.gz
nextcloud-server-9883d5b85d8ae1e2d1d58b345c96a0563e112b97.zip
Merge pull request #18915 from owncloud/node-getfoldercontents-use-view-logic
Use the view logic for getFolderContent for the node api
Diffstat (limited to 'lib')
-rw-r--r--lib/private/files/node/folder.php77
-rw-r--r--lib/private/files/node/node.php4
2 files changed, 11 insertions, 70 deletions
diff --git a/lib/private/files/node/folder.php b/lib/private/files/node/folder.php
index 042b515fea1..23004fc3527 100644
--- a/lib/private/files/node/folder.php
+++ b/lib/private/files/node/folder.php
@@ -25,7 +25,7 @@
namespace OC\Files\Node;
-use OC\Files\Cache\Cache;
+use OCP\Files\FileInfo;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
@@ -77,76 +77,15 @@ class Folder extends Node implements \OCP\Files\Folder {
* @return Node[]
*/
public function getDirectoryListing() {
- $result = array();
-
- /**
- * @var \OC\Files\Storage\Storage $storage
- */
- list($storage, $internalPath) = $this->view->resolvePath($this->path);
- if ($storage) {
- $cache = $storage->getCache($internalPath);
-
- //trigger cache update check
- $this->view->getFileInfo($this->path);
-
- $files = $cache->getFolderContents($internalPath);
- } else {
- $files = array();
- }
-
- //add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders
- $mounts = $this->root->getMountsIn($this->path);
- $dirLength = strlen($this->path);
- foreach ($mounts as $mount) {
- $subStorage = $mount->getStorage();
- if ($subStorage) {
- $subCache = $subStorage->getCache('');
+ $folderContent = $this->view->getDirectoryContent($this->path);
- if ($subCache->getStatus('') === Cache::NOT_FOUND) {
- $subScanner = $subStorage->getScanner('');
- $subScanner->scanFile('');
- }
-
- $rootEntry = $subCache->get('');
- if ($rootEntry) {
- $relativePath = trim(substr($mount->getMountPoint(), $dirLength), '/');
- if ($pos = strpos($relativePath, '/')) {
- //mountpoint inside subfolder add size to the correct folder
- $entryName = substr($relativePath, 0, $pos);
- foreach ($files as &$entry) {
- if ($entry['name'] === $entryName) {
- if ($rootEntry['size'] >= 0) {
- $entry['size'] += $rootEntry['size'];
- } else {
- $entry['size'] = -1;
- }
- }
- }
- } else { //mountpoint in this folder, add an entry for it
- $rootEntry['name'] = $relativePath;
- $rootEntry['storageObject'] = $subStorage;
-
- //remove any existing entry with the same name
- foreach ($files as $i => $file) {
- if ($file['name'] === $rootEntry['name']) {
- $files[$i] = null;
- break;
- }
- }
- $files[] = $rootEntry;
- }
- }
- }
- }
-
- foreach ($files as $file) {
- if ($file) {
- $node = $this->createNode($this->path . '/' . $file['name'], $file);
- $result[] = $node;
+ return array_map(function(FileInfo $info) {
+ if ($info->getMimetype() === 'httpd/unix-directory') {
+ return new Folder($this->root, $this->view, $info->getPath(), $info);
+ } else {
+ return new File($this->root, $this->view, $info->getPath(), $info);
}
- }
-
- return $result;
+ }, $folderContent);
}
/**
diff --git a/lib/private/files/node/node.php b/lib/private/files/node/node.php
index b9bd785de5c..943d12122e6 100644
--- a/lib/private/files/node/node.php
+++ b/lib/private/files/node/node.php
@@ -56,11 +56,13 @@ class Node implements \OCP\Files\Node {
* @param \OC\Files\View $view
* @param \OC\Files\Node\Root $root
* @param string $path
+ * @param FileInfo $fileInfo
*/
- public function __construct($root, $view, $path) {
+ public function __construct($root, $view, $path, $fileInfo = null) {
$this->view = $view;
$this->root = $root;
$this->path = $path;
+ $this->fileInfo = $fileInfo;
}
/**