Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2021-03-12 19:10:18 +0300
committerGitHub <noreply@github.com>2021-03-12 19:10:18 +0300
commit32551b9ff7978395ec7777f11320056ab8413432 (patch)
tree54061bf67246637f3661c07fcecaead8b4de2712
parentbf39adb49b5f102ef898feed6520df672612d15e (diff)
parentc87b1a50d908f0d99622d4c71534d47af1ab9218 (diff)
Merge pull request #25722 from nextcloud/objectstore-copy-cross
apply object store copy optimization when 'cross storage' copy is wit…
-rw-r--r--lib/private/Files/ObjectStore/ObjectStoreStorage.php14
-rw-r--r--lib/private/Files/Storage/Wrapper/Jail.php2
-rw-r--r--tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php24
3 files changed, 39 insertions, 1 deletions
diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php
index 3378f00c4dd..23483b3ab21 100644
--- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php
+++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php
@@ -39,6 +39,7 @@ use OCP\Files\Cache\ICacheEntry;
use OCP\Files\FileInfo;
use OCP\Files\NotFoundException;
use OCP\Files\ObjectStore\IObjectStore;
+use OCP\Files\Storage\IStorage;
class ObjectStoreStorage extends \OC\Files\Storage\Common {
use CopyDirectory;
@@ -530,6 +531,19 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
return $this->objectStore;
}
+ public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) {
+ if ($sourceStorage->instanceOfStorage(ObjectStoreStorage::class)) {
+ /** @var ObjectStoreStorage $sourceStorage */
+ if ($sourceStorage->getObjectStore()->getStorageId() === $this->getObjectStore()->getStorageId()) {
+ $sourceEntry = $sourceStorage->getCache()->get($sourceInternalPath);
+ $this->copyInner($sourceEntry, $targetInternalPath);
+ return true;
+ }
+ }
+
+ return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
+ }
+
public function copy($path1, $path2) {
$path1 = $this->normalizePath($path1);
$path2 = $this->normalizePath($path2);
diff --git a/lib/private/Files/Storage/Wrapper/Jail.php b/lib/private/Files/Storage/Wrapper/Jail.php
index b7933708da8..276f00af33c 100644
--- a/lib/private/Files/Storage/Wrapper/Jail.php
+++ b/lib/private/Files/Storage/Wrapper/Jail.php
@@ -48,7 +48,7 @@ class Jail extends Wrapper {
protected $rootPath;
/**
- * @param array $arguments ['storage' => $storage, 'mask' => $root]
+ * @param array $arguments ['storage' => $storage, 'root' => $root]
*
* $storage: The storage that will be wrapper
* $root: The folder in the wrapped storage that will become the root folder of the wrapped storage
diff --git a/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php b/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php
index fa8ec535061..85a68be3daf 100644
--- a/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php
+++ b/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php
@@ -22,6 +22,7 @@ namespace Test\Files\ObjectStore;
use OC\Files\ObjectStore\StorageObjectStore;
use OC\Files\Storage\Temporary;
+use OC\Files\Storage\Wrapper\Jail;
use OCP\Files\ObjectStore\IObjectStore;
use Test\Files\Storage\Storage;
@@ -204,4 +205,27 @@ class ObjectStoreStorageTest extends Storage {
$this->assertTrue($cache->inCache('foo'));
$this->assertTrue($cache->inCache('foo/test.txt'));
}
+
+ public function testCopyBetweenJails() {
+ $this->instance->mkdir('a');
+ $this->instance->mkdir('b');
+ $jailA = new Jail([
+ 'storage' => $this->instance,
+ 'root' => 'a'
+ ]);
+ $jailB = new Jail([
+ 'storage' => $this->instance,
+ 'root' => 'b'
+ ]);
+ $jailA->mkdir('sub');
+ $jailA->file_put_contents('1.txt', '1');
+ $jailA->file_put_contents('sub/2.txt', '2');
+ $jailA->file_put_contents('sub/3.txt', '3');
+
+ $jailB->copyFromStorage($jailA, '', 'target');
+
+ $this->assertEquals('1', $this->instance->file_get_contents('b/target/1.txt'));
+ $this->assertEquals('2', $this->instance->file_get_contents('b/target/sub/2.txt'));
+ $this->assertEquals('3', $this->instance->file_get_contents('b/target/sub/3.txt'));
+ }
}