Signed-off-by: Robin Appelman <robin@icewind.nl>tags/v24.0.0beta3
@@ -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(); | |||
} |
@@ -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); | |||
} | |||
} | |||
} | |||
@@ -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); |
@@ -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(); | |||
@@ -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(); |