Skip to content

Commit

Permalink
Merge pull request #39958 from nextcloud/dav-permissions-perf
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv authored Aug 22, 2023
2 parents 39d5f69 + e98e8f1 commit b11532c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
22 changes: 5 additions & 17 deletions lib/private/Files/FileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
*/
namespace OC\Files;

use OCA\Files_Sharing\ISharedStorage;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\IHomeStorage;
use OCP\Files\Mount\IMountPoint;
use OCP\IUser;

Expand Down Expand Up @@ -313,27 +315,13 @@ public function isShareable() {
* @return bool
*/
public function isShared() {
$sid = $this->getStorage()->getId();
if (!is_null($sid)) {
$sid = explode(':', $sid);
return ($sid[0] === 'shared');
}

return false;
$storage = $this->getStorage();
return $storage->instanceOfStorage(ISharedStorage::class);
}

public function isMounted() {
$storage = $this->getStorage();
if ($storage->instanceOfStorage('\OCP\Files\IHomeStorage')) {
return false;
}
$sid = $storage->getId();
if (!is_null($sid)) {
$sid = explode(':', $sid);
return ($sid[0] !== 'home' and $sid[0] !== 'shared');
}

return false;
return !($storage->instanceOfStorage(IHomeStorage::class) || $storage->instanceOfStorage(ISharedStorage::class));
}

/**
Expand Down
13 changes: 7 additions & 6 deletions lib/public/Files/DavUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,24 @@ public static function getDavFileId(int $id): string {
* @since 25.0.0
*/
public static function getDavPermissions(FileInfo $info): string {
$permissions = $info->getPermissions();
$p = '';
if ($info->isShared()) {
$p .= 'S';
}
if ($info->isShareable()) {
if ($permissions & Constants::PERMISSION_SHARE) {
$p .= 'R';
}
if ($info->isMounted()) {
$p .= 'M';
}
if ($info->isReadable()) {
if ($permissions & Constants::PERMISSION_READ) {
$p .= 'G';
}
if ($info->isDeletable()) {
if ($permissions & Constants::PERMISSION_DELETE) {
$p .= 'D';
}
if ($info->isUpdateable()) {
if ($permissions & Constants::PERMISSION_UPDATE) {
$p .= 'NV'; // Renameable, Movable
}

Expand All @@ -86,15 +87,15 @@ public static function getDavPermissions(FileInfo $info): string {
$rootEntry = $storage->getCache()->get('');
$isWritable = $rootEntry->getPermissions() & Constants::PERMISSION_UPDATE;
} else {
$isWritable = $info->isUpdateable();
$isWritable = $permissions & Constants::PERMISSION_UPDATE;
}

if ($info->getType() === FileInfo::TYPE_FILE) {
if ($isWritable) {
$p .= 'W';
}
} else {
if ($info->isCreatable()) {
if ($permissions & Constants::PERMISSION_CREATE) {
$p .= 'CK';
}
}
Expand Down

0 comments on commit b11532c

Please sign in to comment.