-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[stable26] fix: write object to the correct urn when moving from another storage to object store #47488
Open
backportbot
wants to merge
4
commits into
stable26
Choose a base branch
from
backport/46013/stable26
base: stable26
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+254
−0
Open
[stable26] fix: write object to the correct urn when moving from another storage to object store #47488
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bb61efb
fix: write object to the correct urn when moving from another storage…
icewind1991 37e8452
perf(ObjectStoreStorage): Improve (slow) move on same object bucket
71c3b50
fix(tests): Fix most obvious errors in ObjectStore tests
come-nc 4c95ba9
fix: rework move into object store to better preserve fileids
icewind1991 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
tests/lib/Files/ObjectStore/ObjectStoreStoragesDifferentBucketTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
/** | ||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc. | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace Test\Files\ObjectStore; | ||
|
||
use OC\Files\ObjectStore\StorageObjectStore; | ||
use OC\Files\Storage\Temporary; | ||
use Test\Files\Storage\StoragesTest; | ||
|
||
/** | ||
* @group DB | ||
*/ | ||
class ObjectStoreStoragesDifferentBucketTest extends StoragesTest { | ||
/** | ||
* @var \OCP\Files\ObjectStore\IObjectStore | ||
*/ | ||
private $objectStore1; | ||
|
||
/** | ||
* @var \OCP\Files\ObjectStore\IObjectStore | ||
*/ | ||
private $objectStore2; | ||
|
||
protected function setUp(): void { | ||
parent::setUp(); | ||
|
||
$baseStorage1 = new Temporary(); | ||
$this->objectStore1 = new StorageObjectStore($baseStorage1); | ||
$config['objectstore'] = $this->objectStore1; | ||
$this->storage1 = new ObjectStoreStorageOverwrite($config); | ||
|
||
$baseStorage2 = new Temporary(); | ||
$this->objectStore2 = new StorageObjectStore($baseStorage2); | ||
$config['objectstore'] = $this->objectStore2; | ||
$this->storage2 = new ObjectStoreStorageOverwrite($config); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
tests/lib/Files/ObjectStore/ObjectStoreStoragesSameBucketTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
/** | ||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc. | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace Test\Files\ObjectStore; | ||
|
||
use OC\Files\ObjectStore\StorageObjectStore; | ||
use OC\Files\Storage\Temporary; | ||
use Test\Files\Storage\StoragesTest; | ||
|
||
/** | ||
* @group DB | ||
*/ | ||
class ObjectStoreStoragesSameBucketTest extends StoragesTest { | ||
/** | ||
* @var \OCP\Files\ObjectStore\IObjectStore | ||
*/ | ||
private $objectStore; | ||
|
||
protected function setUp(): void { | ||
parent::setUp(); | ||
|
||
$baseStorage = new Temporary(); | ||
$this->objectStore = new StorageObjectStore($baseStorage); | ||
$config['objectstore'] = $this->objectStore; | ||
// storage1 and storage2 share the same object store. | ||
$this->storage1 = new ObjectStoreStorageOverwrite($config); | ||
$this->storage2 = new ObjectStoreStorageOverwrite($config); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
/** | ||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc. | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace Test\Files\Storage; | ||
|
||
use Test\TestCase; | ||
|
||
abstract class StoragesTest extends TestCase { | ||
/** | ||
* @var \OC\Files\Storage\Storage | ||
*/ | ||
protected $storage1; | ||
|
||
/** | ||
* @var \OC\Files\Storage\Storage | ||
*/ | ||
protected $storage2; | ||
|
||
protected function tearDown(): void { | ||
if (is_null($this->storage1) && is_null($this->storage2)) { | ||
return; | ||
} | ||
$this->storage1->getCache()->clear(); | ||
$this->storage2->getCache()->clear(); | ||
|
||
parent::tearDown(); | ||
} | ||
|
||
public function testMoveFileFromStorage() { | ||
$source = 'source.txt'; | ||
$target = 'target.txt'; | ||
$this->storage2->file_put_contents($source, 'foo'); | ||
|
||
$this->storage1->moveFromStorage($this->storage2, $source, $target); | ||
|
||
$this->assertTrue($this->storage1->file_exists($target), $target.' was not created'); | ||
$this->assertFalse($this->storage2->file_exists($source), $source.' still exists'); | ||
$this->assertEquals('foo', $this->storage1->file_get_contents($target)); | ||
} | ||
|
||
public function testMoveDirectoryFromStorage() { | ||
$this->storage2->mkdir('source'); | ||
$this->storage2->file_put_contents('source/test1.txt', 'foo'); | ||
$this->storage2->file_put_contents('source/test2.txt', 'qwerty'); | ||
$this->storage2->mkdir('source/subfolder'); | ||
$this->storage2->file_put_contents('source/subfolder/test.txt', 'bar'); | ||
|
||
$this->storage1->moveFromStorage($this->storage2, 'source', 'target'); | ||
|
||
$this->assertTrue($this->storage1->file_exists('target')); | ||
$this->assertTrue($this->storage1->file_exists('target/test1.txt')); | ||
$this->assertTrue($this->storage1->file_exists('target/test2.txt')); | ||
$this->assertTrue($this->storage1->file_exists('target/subfolder')); | ||
$this->assertTrue($this->storage1->file_exists('target/subfolder/test.txt')); | ||
|
||
$this->assertFalse($this->storage2->file_exists('source')); | ||
$this->assertFalse($this->storage2->file_exists('source/test1.txt')); | ||
$this->assertFalse($this->storage2->file_exists('source/test2.txt')); | ||
$this->assertFalse($this->storage2->file_exists('source/subfolder')); | ||
$this->assertFalse($this->storage2->file_exists('source/subfolder/test.txt')); | ||
|
||
$this->assertEquals('foo', $this->storage1->file_get_contents('target/test1.txt')); | ||
$this->assertEquals('qwerty', $this->storage1->file_get_contents('target/test2.txt')); | ||
$this->assertEquals('bar', $this->storage1->file_get_contents('target/subfolder/test.txt')); | ||
} | ||
|
||
public function testCopyFileFromStorage() { | ||
$source = 'source.txt'; | ||
$target = 'target.txt'; | ||
$this->storage2->file_put_contents($source, 'foo'); | ||
|
||
$this->storage1->copyFromStorage($this->storage2, $source, $target); | ||
|
||
$this->assertTrue($this->storage1->file_exists($target), $target.' was not created'); | ||
$this->assertTrue($this->storage2->file_exists($source), $source.' was deleted'); | ||
$this->assertEquals('foo', $this->storage1->file_get_contents($target)); | ||
} | ||
|
||
public function testCopyDirectoryFromStorage() { | ||
$this->storage2->mkdir('source'); | ||
$this->storage2->file_put_contents('source/test1.txt', 'foo'); | ||
$this->storage2->file_put_contents('source/test2.txt', 'qwerty'); | ||
$this->storage2->mkdir('source/subfolder'); | ||
$this->storage2->file_put_contents('source/subfolder/test.txt', 'bar'); | ||
|
||
$this->storage1->copyFromStorage($this->storage2, 'source', 'target'); | ||
|
||
$this->assertTrue($this->storage1->file_exists('target')); | ||
$this->assertTrue($this->storage1->file_exists('target/test1.txt')); | ||
$this->assertTrue($this->storage1->file_exists('target/test2.txt')); | ||
$this->assertTrue($this->storage1->file_exists('target/subfolder')); | ||
$this->assertTrue($this->storage1->file_exists('target/subfolder/test.txt')); | ||
|
||
$this->assertTrue($this->storage2->file_exists('source')); | ||
$this->assertTrue($this->storage2->file_exists('source/test1.txt')); | ||
$this->assertTrue($this->storage2->file_exists('source/test2.txt')); | ||
$this->assertTrue($this->storage2->file_exists('source/subfolder')); | ||
$this->assertTrue($this->storage2->file_exists('source/subfolder/test.txt')); | ||
|
||
$this->assertEquals('foo', $this->storage1->file_get_contents('target/test1.txt')); | ||
$this->assertEquals('qwerty', $this->storage1->file_get_contents('target/test2.txt')); | ||
$this->assertEquals('bar', $this->storage1->file_get_contents('target/subfolder/test.txt')); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / Psalm
UndefinedMethod Error