Browse Source

fix: permissions when copying from readonly storage

Signed-off-by: Claus-Justus Heine <himself@claus-justus-heine.de>
pull/53726/head
Claus-Justus Heine 3 months ago
parent
commit
4a3cd26f61
No known key found for this signature in database GPG Key ID: 5F2B6D7B9B3B0BCA
  1. 22
      lib/private/Files/Cache/Cache.php
  2. 10
      lib/private/Files/Cache/Updater.php

22
lib/private/Files/Cache/Cache.php

@ -1173,8 +1173,21 @@ class Cache implements ICache {
throw new \RuntimeException('Failed to copy to ' . $targetPath . ' from cache with source data ' . json_encode($data) . ' ');
}
if ($sourceEntry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE) {
if (($sourceEntry instanceof CacheEntry) && isset($sourceEntry['copy_from_storage_permissions'])) {
$permissionsToSet = $sourceEntry['copy_from_storage_permissions'];
} else {
$permissionsToSet = null;
}
$folderContent = $sourceCache->getFolderContentsById($sourceEntry->getId());
foreach ($folderContent as $subEntry) {
if ($permissionsToSet !== null) {
$perms = $permissionsToSet;
if ($subEntry->getMimeType() !== ICacheEntry::DIRECTORY_MIMETYPE) {
$perms &= ~\OCP\Constants::PERMISSION_CREATE;
}
$subEntry['copy_from_storage_permissions'] = $perms;
unset($subEntry['scan_permissions']);
}
$subTargetPath = $targetPath . '/' . $subEntry->getName();
$this->copyFromCache($sourceCache, $subEntry, $subTargetPath);
}
@ -1196,9 +1209,14 @@ class Cache implements ICache {
'upload_time' => $entry->getUploadTime(),
'metadata_etag' => $entry->getMetadataEtag(),
];
if ($entry instanceof CacheEntry && isset($entry['scan_permissions'])) {
$data['permissions'] = $entry['scan_permissions'];
if ($entry instanceof CacheEntry) {
if (isset($entry['copy_from_storage_permissions'])) {
$data['permissions'] = $entry['copy_from_storage_permissions'];
} elseif (isset($entry['scan_permissions'])) {
$data['permissions'] = $entry['scan_permissions'];
}
}
return $data;
}

10
lib/private/Files/Cache/Updater.php

@ -193,8 +193,18 @@ class Updater implements IUpdater {
if (!$parentInCache) {
$parentData = $this->scanner->scan($parent, Scanner::SCAN_SHALLOW, -1, false);
$parentInCache = $parentData !== null;
} else {
$parentData = $this->cache->get($parent);
}
if ($parentInCache) {
if ($sourceInfo instanceof CacheEntry) {
$permissionsToSet = $parentData->getPermissions();
if ($sourceInfo->getMimeType() !== ICacheEntry::DIRECTORY_MIMETYPE) {
$permissionsToSet &= ~\OCP\Constants::PERMISSION_CREATE;
}
$sourceInfo['copy_from_storage_permissions'] = $permissionsToSet;
unset($sourceInfo['scan_permissions']);
}
$this->cache->copyFromCache($sourceCache, $sourceInfo, $target);
}
});

Loading…
Cancel
Save