Skip to content

Commit 7bf1126

Browse files
Merge pull request nextcloud#49657 from nextcloud/backport/48769/stable30
[stable30] Fix incorrect permissions when copying shared files
2 parents 0c7ddb3 + 449ac36 commit 7bf1126

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

apps/files_sharing/tests/SharedStorageTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use OCA\Files_Sharing\SharedStorage;
1111
use OCA\Files_Trashbin\AppInfo\Application;
1212
use OCP\AppFramework\Bootstrap\IBootContext;
13+
use OCP\Constants;
1314
use OCP\Files\NotFoundException;
1415
use OCP\Share\IShare;
1516

@@ -579,4 +580,30 @@ public function testInitWithNotFoundSource() {
579580
$this->assertInstanceOf(\OC\Files\Storage\FailedStorage::class, $storage->getSourceStorage());
580581
$this->assertInstanceOf(\OC\Files\Cache\FailedCache::class, $storage->getCache());
581582
}
583+
584+
public function testCopyPermissions(): void {
585+
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
586+
587+
$share = $this->share(
588+
IShare::TYPE_USER,
589+
$this->filename,
590+
self::TEST_FILES_SHARING_API_USER1,
591+
self::TEST_FILES_SHARING_API_USER2,
592+
Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE - Constants::PERMISSION_DELETE
593+
);
594+
595+
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
596+
$view = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
597+
$this->assertTrue($view->file_exists($this->filename));
598+
599+
$this->assertTrue($view->copy($this->filename, '/target.txt'));
600+
601+
$this->assertTrue($view->file_exists('/target.txt'));
602+
603+
$info = $view->getFileInfo('/target.txt');
604+
$this->assertEquals(Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE, $info->getPermissions());
605+
606+
$this->view->unlink($this->filename);
607+
$this->shareManager->deleteShare($share);
608+
}
582609
}

lib/private/Files/Cache/Cache.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ public static function cacheEntryFromData($data, IMimeTypeLoader $mimetypeLoader
168168
if ($data['storage_mtime'] == 0) {
169169
$data['storage_mtime'] = $data['mtime'];
170170
}
171+
if (isset($data['f_permissions'])) {
172+
$data['scan_permissions'] = $data['f_permissions'];
173+
}
171174
$data['permissions'] = (int)$data['permissions'];
172175
if (isset($data['creation_time'])) {
173176
$data['creation_time'] = (int)$data['creation_time'];
@@ -1183,7 +1186,7 @@ public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, str
11831186
}
11841187

11851188
private function cacheEntryToArray(ICacheEntry $entry): array {
1186-
return [
1189+
$data = [
11871190
'size' => $entry->getSize(),
11881191
'mtime' => $entry->getMTime(),
11891192
'storage_mtime' => $entry->getStorageMTime(),
@@ -1196,6 +1199,10 @@ private function cacheEntryToArray(ICacheEntry $entry): array {
11961199
'upload_time' => $entry->getUploadTime(),
11971200
'metadata_etag' => $entry->getMetadataEtag(),
11981201
];
1202+
if ($entry instanceof CacheEntry && isset($entry['scan_permissions'])) {
1203+
$data['permissions'] = $entry['scan_permissions'];
1204+
}
1205+
return $data;
11991206
}
12001207

12011208
public function getQueryFilterForStorage(): ISearchOperator {

0 commit comments

Comments
 (0)