Skip to content

Commit 71b793f

Browse files
authored
Merge pull request #26091 from nextcloud/backport/25722/stable20
[stable20] apply object store copy optimization when 'cross storage' copy is wit…
2 parents c4da8d4 + 5827a15 commit 71b793f

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

lib/private/Files/ObjectStore/ObjectStoreStorage.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
use OCP\Files\FileInfo;
4040
use OCP\Files\NotFoundException;
4141
use OCP\Files\ObjectStore\IObjectStore;
42+
use OCP\Files\Storage\IStorage;
4243

4344
class ObjectStoreStorage extends \OC\Files\Storage\Common {
4445
use CopyDirectory;
@@ -530,6 +531,19 @@ public function getObjectStore(): IObjectStore {
530531
return $this->objectStore;
531532
}
532533

534+
public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) {
535+
if ($sourceStorage->instanceOfStorage(ObjectStoreStorage::class)) {
536+
/** @var ObjectStoreStorage $sourceStorage */
537+
if ($sourceStorage->getObjectStore()->getStorageId() === $this->getObjectStore()->getStorageId()) {
538+
$sourceEntry = $sourceStorage->getCache()->get($sourceInternalPath);
539+
$this->copyInner($sourceEntry, $targetInternalPath);
540+
return true;
541+
}
542+
}
543+
544+
return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
545+
}
546+
533547
public function copy($path1, $path2) {
534548
$path1 = $this->normalizePath($path1);
535549
$path2 = $this->normalizePath($path2);

lib/private/Files/Storage/Wrapper/Jail.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Jail extends Wrapper {
4545
protected $rootPath;
4646

4747
/**
48-
* @param array $arguments ['storage' => $storage, 'mask' => $root]
48+
* @param array $arguments ['storage' => $storage, 'root' => $root]
4949
*
5050
* $storage: The storage that will be wrapper
5151
* $root: The folder in the wrapped storage that will become the root folder of the wrapped storage

tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
use OC\Files\ObjectStore\StorageObjectStore;
2424
use OC\Files\Storage\Temporary;
25+
use OC\Files\Storage\Wrapper\Jail;
2526
use OCP\Files\ObjectStore\IObjectStore;
2627
use Test\Files\Storage\Storage;
2728

@@ -204,4 +205,27 @@ public function testDeleteObjectFailureKeepCache() {
204205
$this->assertTrue($cache->inCache('foo'));
205206
$this->assertTrue($cache->inCache('foo/test.txt'));
206207
}
208+
209+
public function testCopyBetweenJails() {
210+
$this->instance->mkdir('a');
211+
$this->instance->mkdir('b');
212+
$jailA = new Jail([
213+
'storage' => $this->instance,
214+
'root' => 'a'
215+
]);
216+
$jailB = new Jail([
217+
'storage' => $this->instance,
218+
'root' => 'b'
219+
]);
220+
$jailA->mkdir('sub');
221+
$jailA->file_put_contents('1.txt', '1');
222+
$jailA->file_put_contents('sub/2.txt', '2');
223+
$jailA->file_put_contents('sub/3.txt', '3');
224+
225+
$jailB->copyFromStorage($jailA, '', 'target');
226+
227+
$this->assertEquals('1', $this->instance->file_get_contents('b/target/1.txt'));
228+
$this->assertEquals('2', $this->instance->file_get_contents('b/target/sub/2.txt'));
229+
$this->assertEquals('3', $this->instance->file_get_contents('b/target/sub/3.txt'));
230+
}
207231
}

0 commit comments

Comments
 (0)