Skip to content

Commit 4a3cd26

Browse files
committed
fix: permissions when copying from readonly storage
Signed-off-by: Claus-Justus Heine <himself@claus-justus-heine.de>
1 parent 1fd2d4d commit 4a3cd26

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

lib/private/Files/Cache/Cache.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,8 +1173,21 @@ public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, str
11731173
throw new \RuntimeException('Failed to copy to ' . $targetPath . ' from cache with source data ' . json_encode($data) . ' ');
11741174
}
11751175
if ($sourceEntry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE) {
1176+
if (($sourceEntry instanceof CacheEntry) && isset($sourceEntry['copy_from_storage_permissions'])) {
1177+
$permissionsToSet = $sourceEntry['copy_from_storage_permissions'];
1178+
} else {
1179+
$permissionsToSet = null;
1180+
}
11761181
$folderContent = $sourceCache->getFolderContentsById($sourceEntry->getId());
11771182
foreach ($folderContent as $subEntry) {
1183+
if ($permissionsToSet !== null) {
1184+
$perms = $permissionsToSet;
1185+
if ($subEntry->getMimeType() !== ICacheEntry::DIRECTORY_MIMETYPE) {
1186+
$perms &= ~\OCP\Constants::PERMISSION_CREATE;
1187+
}
1188+
$subEntry['copy_from_storage_permissions'] = $perms;
1189+
unset($subEntry['scan_permissions']);
1190+
}
11781191
$subTargetPath = $targetPath . '/' . $subEntry->getName();
11791192
$this->copyFromCache($sourceCache, $subEntry, $subTargetPath);
11801193
}
@@ -1196,9 +1209,14 @@ private function cacheEntryToArray(ICacheEntry $entry): array {
11961209
'upload_time' => $entry->getUploadTime(),
11971210
'metadata_etag' => $entry->getMetadataEtag(),
11981211
];
1199-
if ($entry instanceof CacheEntry && isset($entry['scan_permissions'])) {
1200-
$data['permissions'] = $entry['scan_permissions'];
1212+
if ($entry instanceof CacheEntry) {
1213+
if (isset($entry['copy_from_storage_permissions'])) {
1214+
$data['permissions'] = $entry['copy_from_storage_permissions'];
1215+
} elseif (isset($entry['scan_permissions'])) {
1216+
$data['permissions'] = $entry['scan_permissions'];
1217+
}
12011218
}
1219+
12021220
return $data;
12031221
}
12041222

lib/private/Files/Cache/Updater.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,18 @@ public function copyFromStorage(IStorage $sourceStorage, string $source, string
193193
if (!$parentInCache) {
194194
$parentData = $this->scanner->scan($parent, Scanner::SCAN_SHALLOW, -1, false);
195195
$parentInCache = $parentData !== null;
196+
} else {
197+
$parentData = $this->cache->get($parent);
196198
}
197199
if ($parentInCache) {
200+
if ($sourceInfo instanceof CacheEntry) {
201+
$permissionsToSet = $parentData->getPermissions();
202+
if ($sourceInfo->getMimeType() !== ICacheEntry::DIRECTORY_MIMETYPE) {
203+
$permissionsToSet &= ~\OCP\Constants::PERMISSION_CREATE;
204+
}
205+
$sourceInfo['copy_from_storage_permissions'] = $permissionsToSet;
206+
unset($sourceInfo['scan_permissions']);
207+
}
198208
$this->cache->copyFromCache($sourceCache, $sourceInfo, $target);
199209
}
200210
});

0 commit comments

Comments
 (0)