Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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;
Expand Down Expand Up @@ -1198,6 +1199,12 @@ public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, str
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
Expand Down
7 changes: 0 additions & 7 deletions lib/private/Files/ObjectStore/ObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,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;
private ?int $totalSizeLimit = null;
Expand All @@ -67,7 +65,6 @@ public function __construct(array $parameters) {
if (isset($parameters['validateWrites'])) {
$this->validateWrites = (bool)$parameters['validateWrites'];
}
$this->handleCopiesAsOwned = (bool)($parameters['handleCopiesAsOwned'] ?? false);
if (isset($parameters['totalSizeLimit'])) {
$this->totalSizeLimit = $parameters['totalSizeLimit'];
}
Expand Down Expand Up @@ -730,10 +727,6 @@ private function copyFile(ICacheEntry $sourceEntry, string $to) {

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);

Expand Down
22 changes: 1 addition & 21 deletions tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,28 +223,8 @@ public function testCopyBetweenJails(): void {
$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();
Expand All @@ -258,7 +238,7 @@ public function testCopyGrantsPermissions(): void {
$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 {
Expand Down
Loading