Skip to content

Commit 036fd8c

Browse files
committed
Move Dav fileid and permissions logic into OCP\Util to be able to use it for BulkUpload
Signed-off-by: Côme Chilliet <[email protected]>
1 parent e34f2c4 commit 036fd8c

4 files changed

Lines changed: 56 additions & 43 deletions

File tree

apps/dav/lib/BulkUpload/BulkUploadPlugin.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,13 @@
3333
use OCA\DAV\Connector\Sabre\MtimeSanitizer;
3434

3535
class BulkUploadPlugin extends ServerPlugin {
36+
private Folder $userFolder;
37+
private LoggerInterface $logger;
3638

37-
/** @var Folder */
38-
private $userFolder;
39-
40-
/** @var LoggerInterface */
41-
private $logger;
42-
43-
public function __construct(Folder $userFolder, LoggerInterface $logger) {
39+
public function __construct(
40+
Folder $userFolder,
41+
LoggerInterface $logger
42+
) {
4443
$this->userFolder = $userFolder;
4544
$this->logger = $logger;
4645
}
@@ -96,8 +95,8 @@ public function httpPost(RequestInterface $request, ResponseInterface $response)
9695
$writtenFiles[$headers['x-file-path']] = [
9796
"error" => false,
9897
"etag" => $node->getETag(),
99-
"fileid" => $node->getFileId(),
100-
"permissions" => $node->getDavPermissions(),
98+
"fileid" => \OCP\Util::getDavFileId($node->getId()),
99+
"permissions" => \OCP\Util::getDavPermissions($node->getFileInfo()),
101100
];
102101
} catch (\Exception $e) {
103102
$this->logger->error($e->getMessage(), ['path' => $headers['x-file-path']]);

apps/dav/lib/Connector/Sabre/Node.php

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,8 @@ public function getId() {
252252
* @return string|null
253253
*/
254254
public function getFileId() {
255-
if ($this->info->getId()) {
256-
$instanceId = \OC_Util::getInstanceId();
257-
$id = sprintf('%08d', $this->info->getId());
258-
return $id . $instanceId;
255+
if ($id = $this->info->getId()) {
256+
return \OCP\Util::getDavFileId($id);
259257
}
260258

261259
return null;
@@ -381,35 +379,7 @@ public function getNoteFromShare($user) {
381379
* @return string
382380
*/
383381
public function getDavPermissions() {
384-
$p = '';
385-
if ($this->info->isShared()) {
386-
$p .= 'S';
387-
}
388-
if ($this->info->isShareable()) {
389-
$p .= 'R';
390-
}
391-
if ($this->info->isMounted()) {
392-
$p .= 'M';
393-
}
394-
if ($this->info->isReadable()) {
395-
$p .= 'G';
396-
}
397-
if ($this->info->isDeletable()) {
398-
$p .= 'D';
399-
}
400-
if ($this->info->isUpdateable()) {
401-
$p .= 'NV'; // Renameable, Moveable
402-
}
403-
if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) {
404-
if ($this->info->isUpdateable()) {
405-
$p .= 'W';
406-
}
407-
} else {
408-
if ($this->info->isCreatable()) {
409-
$p .= 'CK';
410-
}
411-
}
412-
return $p;
382+
return \OCP\Util::getDavPermissions($this->info);
413383
}
414384

415385
public function getOwner() {

apps/dav/lib/Server.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,10 @@ public function __construct(IRequest $request, string $baseUri) {
313313
$view
314314
));
315315
$this->server->addPlugin(
316-
new BulkUploadPlugin($userFolder, $logger)
316+
new BulkUploadPlugin(
317+
$userFolder,
318+
$logger
319+
)
317320
);
318321
}
319322
$this->server->addPlugin(new \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin(

lib/public/Util.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,4 +628,45 @@ public static function isFunctionEnabled(string $functionName): bool {
628628
}
629629
return true;
630630
}
631+
632+
/**
633+
* @param string $id Id of the file returned by FileInfo::getId
634+
*/
635+
public static getDavFileId(string $id): string {
636+
$instanceId = \OC_Util::getInstanceId();
637+
$id = sprintf('%08d', $id);
638+
return $id . $instanceId;
639+
}
640+
641+
public static getDavPermissions(\OCP\Files\FileInfo $info): string {
642+
$p = '';
643+
if ($info->isShared()) {
644+
$p .= 'S';
645+
}
646+
if ($info->isShareable()) {
647+
$p .= 'R';
648+
}
649+
if ($info->isMounted()) {
650+
$p .= 'M';
651+
}
652+
if ($info->isReadable()) {
653+
$p .= 'G';
654+
}
655+
if ($info->isDeletable()) {
656+
$p .= 'D';
657+
}
658+
if ($info->isUpdateable()) {
659+
$p .= 'NV'; // Renameable, Moveable
660+
}
661+
if ($info->getType() === \OCP\Files\FileInfo::TYPE_FILE) {
662+
if ($info->isUpdateable()) {
663+
$p .= 'W';
664+
}
665+
} else {
666+
if ($info->isCreatable()) {
667+
$p .= 'CK';
668+
}
669+
}
670+
return $p;
671+
}
631672
}

0 commit comments

Comments
 (0)