Skip to content

Commit

Permalink
apply object store copy optimization when 'cross storage' copy is wit…
Browse files Browse the repository at this point in the history
…hin the same object store

Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Feb 19, 2021
1 parent 9464308 commit 69c485e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
13 changes: 13 additions & 0 deletions lib/private/Files/ObjectStore/ObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@
use Icewind\Streams\IteratorDirectory;
use OC\Files\Cache\CacheEntry;
use OC\Files\Storage\PolyFill\CopyDirectory;
use OC\Files\Storage\Wrapper\Jail;
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;
Expand Down Expand Up @@ -530,6 +532,17 @@ public function getObjectStore(): IObjectStore {
return $this->objectStore;
}

public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) {
if ($sourceStorage->instanceOfStorage(ObjectStoreStorage::class)) {
if ($sourceStorage->getObjectStore()->getStorageId() === $this->getObjectStore()->getStorageId()) {
$sourceEntry = $sourceStorage->getCache()->get($sourceInternalPath);
$this->copyInner($sourceEntry, $targetInternalPath);
}
}

return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
}

public function copy($path1, $path2) {
$path1 = $this->normalizePath($path1);
$path2 = $this->normalizePath($path2);
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Storage/Wrapper/Jail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

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;

Expand Down Expand Up @@ -204,4 +205,27 @@ public function testDeleteObjectFailureKeepCache() {
$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'));
}
}

0 comments on commit 69c485e

Please sign in to comment.