Skip to content

Commit

Permalink
save filesystem node in dav node
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Apr 6, 2022
1 parent ef9890f commit 9b1abd6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
9 changes: 8 additions & 1 deletion apps/dav/lib/Connector/Sabre/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use OCA\DAV\Connector\Sabre\Exception\Forbidden;
use OCA\DAV\Connector\Sabre\Exception\InvalidPath;
use OCP\Files\FileInfo;
use OCP\Files\Folder;
use OCP\Files\ForbiddenException;
use OCP\Files\InvalidPathException;
use OCP\Files\NotPermittedException;
Expand Down Expand Up @@ -144,7 +145,9 @@ public function createFile($name, $data = null) {
$info = $this->fileView->getFileInfo($this->path . '/' . $name);
if (!$info) {
// use a dummy FileInfo which is acceptable here since it will be refreshed after the put is complete
$info = new \OC\Files\FileInfo($path, null, null, [], null);
$info = new \OC\Files\FileInfo($path, null, null, [
'type' => FileInfo::TYPE_FILE
], null);
}
$node = new \OCA\DAV\Connector\Sabre\File($this->fileView, $info);

Expand Down Expand Up @@ -474,4 +477,8 @@ public function copyInto($targetName, $sourcePath, INode $sourceNode) {

return false;
}

public function getNode(): Folder {
return $this->node;
}
}
4 changes: 4 additions & 0 deletions apps/dav/lib/Connector/Sabre/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -753,4 +753,8 @@ protected function header($string) {
public function hash(string $type) {
return $this->fileView->hash($type, $this->path);
}

public function getNode(): \OCP\Files\File {
return $this->node;
}
}
21 changes: 21 additions & 0 deletions apps/dav/lib/Connector/Sabre/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@
namespace OCA\DAV\Connector\Sabre;

use OC\Files\Mount\MoveableMount;
use OC\Files\Node\File;
use OC\Files\Node\Folder;
use OC\Files\View;
use OCA\DAV\Connector\Sabre\Exception\InvalidPath;
use OCP\Files\FileInfo;
use OCP\Files\IRootFolder;
use OCP\Files\StorageNotAvailableException;
use OCP\Share\IShare;
use OCP\Share\Exceptions\ShareNotFound;
Expand Down Expand Up @@ -75,6 +78,8 @@ abstract class Node implements \Sabre\DAV\INode {
*/
protected $shareManager;

protected \OC\Files\Node\Node $node;

/**
* Sets up the node, expects a full path name
*
Expand All @@ -91,10 +96,22 @@ public function __construct(View $view, FileInfo $info, IManager $shareManager =
} 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);
} else {
$this->node = new File($root, $view, $this->path, $info);
}
}

protected function refreshInfo() {
$this->info = $this->fileView->getFileInfo($this->path);
$root = \OC::$server->get(IRootFolder::class);
if ($this->info->getType() === FileInfo::TYPE_FOLDER) {
$this->node = new Folder($root, $this->fileView, $this->path, $this->info);
} else {
$this->node = new File($root, $this->fileView, $this->path, $this->info);
}
}

/**
Expand Down Expand Up @@ -403,6 +420,10 @@ public function getFileInfo() {
return $this->info;
}

public function getNode(): \OCP\Files\Node {
return $this->node;
}

protected function sanitizeMtime($mtimeFromRequest) {
return MtimeSanitizer::sanitizeMtime($mtimeFromRequest);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/FileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public function getPermissions() {
*/
public function getType() {
if (!isset($this->data['type'])) {
$this->data['type'] = ($this->getMimetype() === 'httpd/unix-directory') ? self::TYPE_FOLDER : self::TYPE_FILE;
$this->data['type'] = ($this->getMimetype() === self::MIMETYPE_FOLDER) ? self::TYPE_FOLDER : self::TYPE_FILE;
}
return $this->data['type'];
}
Expand Down

0 comments on commit 9b1abd6

Please sign in to comment.