Merge pull request #58847 from nextcloud/backport/53733/stable32
Some checks are pending
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
Integration sqlite / changes (push) Waiting to run
Integration sqlite / integration-sqlite (stable32, 8.1, stable32, --tags ~@large files_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable32, 8.1, stable32, capabilities_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable32, 8.1, stable32, collaboration_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable32, 8.1, stable32, comments_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable32, 8.1, stable32, dav_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable32, 8.1, stable32, features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable32, 8.1, stable32, federation_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable32, 8.1, stable32, file_conversions) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable32, 8.1, stable32, files_reminders) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable32, 8.1, stable32, filesdrop_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable32, 8.1, stable32, ldap_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable32, 8.1, stable32, openldap_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable32, 8.1, stable32, openldap_numerical_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable32, 8.1, stable32, remoteapi_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable32, 8.1, stable32, routing_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable32, 8.1, stable32, setup_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable32, 8.1, stable32, sharees_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable32, 8.1, stable32, sharing_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable32, 8.1, stable32, theming_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable32, 8.1, stable32, videoverification_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite-summary (push) Blocked by required conditions
Psalm static code analysis / static-code-analysis (push) Waiting to run
Psalm static code analysis / static-code-analysis-security (push) Waiting to run
Psalm static code analysis / static-code-analysis-ocp (push) Waiting to run
Psalm static code analysis / static-code-analysis-ncu (push) Waiting to run

[stable32] fix: give target file all permissions on copy
This commit is contained in:
Carl Schwan 2026-03-12 09:45:05 +01:00 committed by GitHub
commit 7f53bfae6c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 28 deletions

View file

@ -15,6 +15,7 @@ use OC\Files\Search\SearchComparison;
use OC\Files\Search\SearchQuery;
use OC\Files\Storage\Wrapper\Encryption;
use OC\SystemConfig;
use OCP\Constants;
use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\EventDispatcher\IEventDispatcher;
@ -1185,6 +1186,12 @@ class Cache implements ICache {
throw new \RuntimeException('Invalid source cache entry on copyFromCache');
}
$data = $this->cacheEntryToArray($sourceEntry);
// since we are essentially creating a new file, we don't have to obey the source permissions
if ($sourceEntry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE) {
$data['permissions'] = Constants::PERMISSION_ALL;
} else {
$data['permissions'] = Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE;
}
// when moving from an encrypted storage to a non-encrypted storage remove the `encrypted` mark
if ($sourceCache instanceof Cache

View file

@ -36,8 +36,6 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
private string $objectPrefix = 'urn:oid:';
private LoggerInterface $logger;
private bool $handleCopiesAsOwned;
protected bool $validateWrites = true;
private bool $preserveCacheItemsOnDelete = false;
@ -62,7 +60,6 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
if (isset($parameters['validateWrites'])) {
$this->validateWrites = (bool)$parameters['validateWrites'];
}
$this->handleCopiesAsOwned = (bool)($parameters['handleCopiesAsOwned'] ?? false);
$this->logger = \OCP\Server::get(LoggerInterface::class);
}
@ -722,10 +719,6 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
try {
$this->objectStore->copyObject($sourceUrn, $targetUrn);
if ($this->handleCopiesAsOwned) {
// 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 !
$cache->update($targetId, ['permissions' => \OCP\Constants::PERMISSION_ALL]);
}
} catch (\Exception $e) {
$cache->remove($to);

View file

@ -225,28 +225,8 @@ class ObjectStoreStorageTest extends Storage {
$this->assertEquals('3', $this->instance->file_get_contents('b/target/sub/3.txt'));
}
public function testCopyPreservesPermissions(): void {
$cache = $this->instance->getCache();
$this->instance->file_put_contents('test.txt', 'foo');
$this->assertTrue($cache->inCache('test.txt'));
$cache->update($cache->getId('test.txt'), ['permissions' => Constants::PERMISSION_READ]);
$this->assertEquals(Constants::PERMISSION_READ, $this->instance->getPermissions('test.txt'));
$this->assertTrue($this->instance->copy('test.txt', 'new.txt'));
$this->assertTrue($cache->inCache('new.txt'));
$this->assertEquals(Constants::PERMISSION_READ, $this->instance->getPermissions('new.txt'));
}
/**
* Test that copying files will drop permissions like local storage does
* TODO: Drop this and fix local storage
*/
public function testCopyGrantsPermissions(): void {
$config['objectstore'] = $this->objectStorage;
$config['handleCopiesAsOwned'] = true;
$instance = new ObjectStoreStorageOverwrite($config);
$cache = $instance->getCache();
@ -260,7 +240,7 @@ class ObjectStoreStorageTest extends Storage {
$this->assertTrue($instance->copy('test.txt', 'new.txt'));
$this->assertTrue($cache->inCache('new.txt'));
$this->assertEquals(Constants::PERMISSION_ALL, $instance->getPermissions('new.txt'));
$this->assertEquals(Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE, $instance->getPermissions('new.txt'));
}
public function testCopyFolderSize(): void {