diff --git a/apps/dav/lib/BulkUpload/BulkUploadPlugin.php b/apps/dav/lib/BulkUpload/BulkUploadPlugin.php index 79a1561ef5bfb..9bd6d568d667d 100644 --- a/apps/dav/lib/BulkUpload/BulkUploadPlugin.php +++ b/apps/dav/lib/BulkUpload/BulkUploadPlugin.php @@ -33,14 +33,13 @@ use OCA\DAV\Connector\Sabre\MtimeSanitizer; class BulkUploadPlugin extends ServerPlugin { + private Folder $userFolder; + private LoggerInterface $logger; - /** @var Folder */ - private $userFolder; - - /** @var LoggerInterface */ - private $logger; - - public function __construct(Folder $userFolder, LoggerInterface $logger) { + public function __construct( + Folder $userFolder, + LoggerInterface $logger + ) { $this->userFolder = $userFolder; $this->logger = $logger; } @@ -96,8 +95,8 @@ public function httpPost(RequestInterface $request, ResponseInterface $response) $writtenFiles[$headers['x-file-path']] = [ "error" => false, "etag" => $node->getETag(), - "fileid" => $node->getFileId(), - "permissions" => $node->getDavPermissions(), + "fileid" => \OCP\Util::getDavFileId($node->getId()), + "permissions" => \OCP\Util::getDavPermissions($node->getFileInfo()), ]; } catch (\Exception $e) { $this->logger->error($e->getMessage(), ['path' => $headers['x-file-path']]); diff --git a/apps/dav/lib/Connector/Sabre/Node.php b/apps/dav/lib/Connector/Sabre/Node.php index 87f2fea394fdb..c4fc6282f8411 100644 --- a/apps/dav/lib/Connector/Sabre/Node.php +++ b/apps/dav/lib/Connector/Sabre/Node.php @@ -252,10 +252,8 @@ public function getId() { * @return string|null */ public function getFileId() { - if ($this->info->getId()) { - $instanceId = \OC_Util::getInstanceId(); - $id = sprintf('%08d', $this->info->getId()); - return $id . $instanceId; + if ($id = $this->info->getId()) { + return \OCP\Util::getDavFileId($id); } return null; @@ -381,35 +379,7 @@ public function getNoteFromShare($user) { * @return string */ public function getDavPermissions() { - $p = ''; - if ($this->info->isShared()) { - $p .= 'S'; - } - if ($this->info->isShareable()) { - $p .= 'R'; - } - if ($this->info->isMounted()) { - $p .= 'M'; - } - if ($this->info->isReadable()) { - $p .= 'G'; - } - if ($this->info->isDeletable()) { - $p .= 'D'; - } - if ($this->info->isUpdateable()) { - $p .= 'NV'; // Renameable, Moveable - } - if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { - if ($this->info->isUpdateable()) { - $p .= 'W'; - } - } else { - if ($this->info->isCreatable()) { - $p .= 'CK'; - } - } - return $p; + return \OCP\Util::getDavPermissions($this->info); } public function getOwner() { diff --git a/apps/dav/lib/Server.php b/apps/dav/lib/Server.php index 2cfcb3f539375..f98dba229256d 100644 --- a/apps/dav/lib/Server.php +++ b/apps/dav/lib/Server.php @@ -313,7 +313,10 @@ public function __construct(IRequest $request, string $baseUri) { $view )); $this->server->addPlugin( - new BulkUploadPlugin($userFolder, $logger) + new BulkUploadPlugin( + $userFolder, + $logger + ) ); } $this->server->addPlugin(new \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin( diff --git a/lib/public/Util.php b/lib/public/Util.php index 6cd3eaa7f8551..ac30e339b2b1e 100644 --- a/lib/public/Util.php +++ b/lib/public/Util.php @@ -628,4 +628,45 @@ public static function isFunctionEnabled(string $functionName): bool { } return true; } + + /** + * @param string $id Id of the file returned by FileInfo::getId + */ + public static function getDavFileId(string $id): string { + $instanceId = \OC_Util::getInstanceId(); + $id = sprintf('%08d', $id); + return $id . $instanceId; + } + + public static function getDavPermissions(\OCP\Files\FileInfo $info): string { + $p = ''; + if ($info->isShared()) { + $p .= 'S'; + } + if ($info->isShareable()) { + $p .= 'R'; + } + if ($info->isMounted()) { + $p .= 'M'; + } + if ($info->isReadable()) { + $p .= 'G'; + } + if ($info->isDeletable()) { + $p .= 'D'; + } + if ($info->isUpdateable()) { + $p .= 'NV'; // Renameable, Moveable + } + if ($info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { + if ($info->isUpdateable()) { + $p .= 'W'; + } + } else { + if ($info->isCreatable()) { + $p .= 'CK'; + } + } + return $p; + } }