Skip to content

Commit b13b3df

Browse files
authored
Merge pull request #63414 from nextcloud/backport/53733/stable30
[stable30] fix: give target file all permissions on copy
2 parents 8a34fdb + dd485a1 commit b13b3df

3 files changed

Lines changed: 8 additions & 28 deletions

File tree

lib/private/Files/Cache/Cache.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use OC\Files\Search\SearchQuery;
1515
use OC\Files\Storage\Wrapper\Encryption;
1616
use OC\SystemConfig;
17+
use OCP\Constants;
1718
use OCP\DB\QueryBuilder\IQueryBuilder;
1819
use OCP\EventDispatcher\IEventDispatcher;
1920
use OCP\Files\Cache\CacheEntryInsertedEvent;
@@ -1162,6 +1163,12 @@ public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, str
11621163
throw new \RuntimeException('Invalid source cache entry on copyFromCache');
11631164
}
11641165
$data = $this->cacheEntryToArray($sourceEntry);
1166+
// since we are essentially creating a new file, we don't have to obey the source permissions
1167+
if ($sourceEntry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE) {
1168+
$data['permissions'] = Constants::PERMISSION_ALL;
1169+
} else {
1170+
$data['permissions'] = Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE;
1171+
}
11651172

11661173
// when moving from an encrypted storage to a non-encrypted storage remove the `encrypted` mark
11671174
if ($sourceCache instanceof Cache && $sourceCache->hasEncryptionWrapper() && !$this->hasEncryptionWrapper()) {

lib/private/Files/ObjectStore/ObjectStoreStorage.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
3434
private string $objectPrefix = 'urn:oid:';
3535

3636
private LoggerInterface $logger;
37-
38-
private bool $handleCopiesAsOwned;
3937
protected bool $validateWrites = true;
4038
private bool $preserveCacheItemsOnDelete = false;
4139

@@ -60,7 +58,6 @@ public function __construct($params) {
6058
if (isset($params['validateWrites'])) {
6159
$this->validateWrites = (bool) $params['validateWrites'];
6260
}
63-
$this->handleCopiesAsOwned = (bool) ($params['handleCopiesAsOwned'] ?? false);
6461

6562
$this->logger = \OCP\Server::get(LoggerInterface::class);
6663
}
@@ -737,10 +734,6 @@ private function copyFile(ICacheEntry $sourceEntry, string $to) {
737734

738735
try {
739736
$this->objectStore->copyObject($sourceUrn, $targetUrn);
740-
if ($this->handleCopiesAsOwned) {
741-
// Copied the file thus we gain all permissions as we are the owner now ! warning while this aligns with local storage it should not be used and instead fix local storage !
742-
$cache->update($targetId, ['permissions' => \OCP\Constants::PERMISSION_ALL]);
743-
}
744737
} catch (\Exception $e) {
745738
$cache->remove($to);
746739

tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -226,28 +226,8 @@ public function testCopyBetweenJails() {
226226
$this->assertEquals('3', $this->instance->file_get_contents('b/target/sub/3.txt'));
227227
}
228228

229-
public function testCopyPreservesPermissions() {
230-
$cache = $this->instance->getCache();
231-
232-
$this->instance->file_put_contents('test.txt', 'foo');
233-
$this->assertTrue($cache->inCache('test.txt'));
234-
235-
$cache->update($cache->getId('test.txt'), ['permissions' => \OCP\Constants::PERMISSION_READ]);
236-
$this->assertEquals(\OCP\Constants::PERMISSION_READ, $this->instance->getPermissions('test.txt'));
237-
238-
$this->assertTrue($this->instance->copy('test.txt', 'new.txt'));
239-
240-
$this->assertTrue($cache->inCache('new.txt'));
241-
$this->assertEquals(\OCP\Constants::PERMISSION_READ, $this->instance->getPermissions('new.txt'));
242-
}
243-
244-
/**
245-
* Test that copying files will drop permissions like local storage does
246-
* TODO: Drop this and fix local storage
247-
*/
248229
public function testCopyGrantsPermissions() {
249230
$config['objectstore'] = $this->objectStorage;
250-
$config['handleCopiesAsOwned'] = true;
251231
$instance = new ObjectStoreStorageOverwrite($config);
252232

253233
$cache = $instance->getCache();
@@ -261,7 +241,7 @@ public function testCopyGrantsPermissions() {
261241
$this->assertTrue($instance->copy('test.txt', 'new.txt'));
262242

263243
$this->assertTrue($cache->inCache('new.txt'));
264-
$this->assertEquals(\OCP\Constants::PERMISSION_ALL, $instance->getPermissions('new.txt'));
244+
$this->assertEquals(\OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_CREATE, $instance->getPermissions('new.txt'));
265245
}
266246

267247
public function testCopyFolderSize(): void {

0 commit comments

Comments
 (0)