diff options
-rw-r--r-- | apps/dav/lib/Connector/Sabre/Directory.php | 4 | ||||
-rw-r--r-- | apps/dav/lib/Connector/Sabre/Node.php | 14 | ||||
-rw-r--r-- | lib/private/Files/Node/Folder.php | 4 | ||||
-rw-r--r-- | lib/private/Files/View.php | 21 | ||||
-rw-r--r-- | tests/lib/Files/Node/FolderTest.php | 2 |
5 files changed, 29 insertions, 16 deletions
diff --git a/apps/dav/lib/Connector/Sabre/Directory.php b/apps/dav/lib/Connector/Sabre/Directory.php index 54ee14fdaf3..8b616b0cb8a 100644 --- a/apps/dav/lib/Connector/Sabre/Directory.php +++ b/apps/dav/lib/Connector/Sabre/Directory.php @@ -236,7 +236,7 @@ class Directory extends \OCA\DAV\Connector\Sabre\Node implements \Sabre\DAV\ICol throw new \Sabre\DAV\Exception\NotFound('File with name ' . $path . ' could not be located'); } - if ($info['mimetype'] === 'httpd/unix-directory') { + if ($info->getMimeType() === FileInfo::MIMETYPE_FOLDER) { $node = new \OCA\DAV\Connector\Sabre\Directory($this->fileView, $info, $this->tree, $this->shareManager); } else { $node = new \OCA\DAV\Connector\Sabre\File($this->fileView, $info, $this->shareManager); @@ -264,7 +264,7 @@ class Directory extends \OCA\DAV\Connector\Sabre\Node implements \Sabre\DAV\ICol // the caller believe that the collection itself does not exist throw new Forbidden('No read permissions'); } - $folderContent = $this->fileView->getDirectoryContent($this->path); + $folderContent = $this->getNode()->getDirectoryListing(); } catch (LockedException $e) { throw new Locked(); } diff --git a/apps/dav/lib/Connector/Sabre/Node.php b/apps/dav/lib/Connector/Sabre/Node.php index 79f1653c692..e4517068f42 100644 --- a/apps/dav/lib/Connector/Sabre/Node.php +++ b/apps/dav/lib/Connector/Sabre/Node.php @@ -78,7 +78,7 @@ abstract class Node implements \Sabre\DAV\INode { */ protected $shareManager; - protected \OC\Files\Node\Node $node; + protected \OCP\Files\Node $node; /** * Sets up the node, expects a full path name @@ -96,11 +96,15 @@ abstract class Node implements \Sabre\DAV\INode { } else { $this->shareManager = \OC::$server->getShareManager(); } - $root = \OC::$server->get(IRootFolder::class); - if ($info->getType()=== FileInfo::TYPE_FOLDER) { - $this->node = new Folder($root, $view, $this->path, $info); + if ($info instanceof Folder || $info instanceof File) { + $this->node = $info; } else { - $this->node = new File($root, $view, $this->path, $info); + $root = \OC::$server->get(IRootFolder::class); + if ($info->getType() === FileInfo::TYPE_FOLDER) { + $this->node = new Folder($root, $view, $this->path, $info); + } else { + $this->node = new File($root, $view, $this->path, $info); + } } } diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index d058805b20e..9c15f0edf41 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -97,10 +97,10 @@ class Folder extends Node implements \OCP\Files\Folder { * @throws \OCP\Files\NotFoundException */ public function getDirectoryListing() { - $folderContent = $this->view->getDirectoryContent($this->path); + $folderContent = $this->view->getDirectoryContent($this->path, '', $this->getFileInfo()); return array_map(function (FileInfo $info) { - if ($info->getMimetype() === 'httpd/unix-directory') { + if ($info->getMimetype() === FileInfo::MIMETYPE_FOLDER) { return new Folder($this->root, $this->view, $info->getPath(), $info); } else { return new File($this->root, $this->view, $info->getPath(), $info); diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index e23dd4312aa..eef87cc65f4 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -1431,7 +1431,7 @@ class View { * @param string $mimetype_filter limit returned content to this mimetype or mimepart * @return FileInfo[] */ - public function getDirectoryContent($directory, $mimetype_filter = '') { + public function getDirectoryContent($directory, $mimetype_filter = '', \OCP\Files\FileInfo $directoryInfo = null) { $this->assertPathLength($directory); if (!Filesystem::isValidPath($directory)) { return []; @@ -1449,14 +1449,21 @@ class View { $cache = $storage->getCache($internalPath); $user = \OC_User::getUser(); - $data = $this->getCacheEntry($storage, $internalPath, $directory); + if (!$directoryInfo) { + $data = $this->getCacheEntry($storage, $internalPath, $directory); + if (!$data instanceof ICacheEntry || !isset($data['fileid'])) { + return []; + } + } else { + $data = $directoryInfo; + } - if (!$data instanceof ICacheEntry || !isset($data['fileid']) || !($data->getPermissions() & Constants::PERMISSION_READ)) { - return []; - } + if (!($data->getPermissions() & Constants::PERMISSION_READ)) { + return []; + } - $folderId = $data['fileid']; - $contents = $cache->getFolderContentsById($folderId); //TODO: mimetype_filter + $folderId = $data->getId(); + $contents = $cache->getFolderContentsById($folderId); //TODO: mimetype_filter $sharingDisabled = \OCP\Util::isSharingDisabledForUser(); diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php index 05f546874ef..4cda92b6e83 100644 --- a/tests/lib/Files/Node/FolderTest.php +++ b/tests/lib/Files/Node/FolderTest.php @@ -78,6 +78,8 @@ class FolderTest extends NodeTest { new FileInfo('/bar/foo/asd', null, 'foo/asd', ['fileid' => 2, 'path' => '/bar/foo/asd', 'name' => 'asd', 'size' => 100, 'mtime' => 50, 'mimetype' => 'text/plain'], null), new FileInfo('/bar/foo/qwerty', null, 'foo/qwerty', ['fileid' => 3, 'path' => '/bar/foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'httpd/unix-directory'], null), ]); + $view->method('getFileInfo') + ->willReturn($this->createMock(FileInfo::class)); $node = new Folder($root, $view, '/bar/foo'); $children = $node->getDirectoryListing(); |