Improve cross storage copy between local storages
This commit is contained in:
parent
8575bb2cb9
commit
31e94708f8
|
@ -353,5 +353,41 @@ if (\OC_Util::runningOnWindows()) {
|
||||||
return parent::getETag($path);
|
return parent::getETag($path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \OCP\Files\Storage $sourceStorage
|
||||||
|
* @param string $sourceInternalPath
|
||||||
|
* @param string $targetInternalPath
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
|
||||||
|
if($sourceStorage->instanceOfStorage('\OC\Files\Storage\Local')){
|
||||||
|
/**
|
||||||
|
* @var \OC\Files\Storage\Local $sourceStorage
|
||||||
|
*/
|
||||||
|
$rootStorage = new Local(['datadir' => '/']);
|
||||||
|
return $rootStorage->copy($sourceStorage->getSourcePath($sourceInternalPath), $this->getSourcePath($targetInternalPath));
|
||||||
|
} else {
|
||||||
|
return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \OCP\Files\Storage $sourceStorage
|
||||||
|
* @param string $sourceInternalPath
|
||||||
|
* @param string $targetInternalPath
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
|
||||||
|
if ($sourceStorage->instanceOfStorage('\OC\Files\Storage\Local')) {
|
||||||
|
/**
|
||||||
|
* @var \OC\Files\Storage\Local $sourceStorage
|
||||||
|
*/
|
||||||
|
$rootStorage = new Local(['datadir' => '/']);
|
||||||
|
return $rootStorage->rename($sourceStorage->getSourcePath($sourceInternalPath), $this->getSourcePath($targetInternalPath));
|
||||||
|
} else {
|
||||||
|
return parent::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
namespace Test\Files;
|
namespace Test\Files;
|
||||||
|
|
||||||
use OC\Files\Cache\Watcher;
|
use OC\Files\Cache\Watcher;
|
||||||
|
use OC\Files\Storage\Common;
|
||||||
use OC\Files\Mount\MountPoint;
|
use OC\Files\Mount\MountPoint;
|
||||||
use OC\Files\Storage\Temporary;
|
use OC\Files\Storage\Temporary;
|
||||||
|
|
||||||
|
@ -17,6 +18,26 @@ class TemporaryNoTouch extends \OC\Files\Storage\Temporary {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TemporaryNoCross extends \OC\Files\Storage\Temporary {
|
||||||
|
public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
|
||||||
|
return Common::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
|
||||||
|
return Common::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TemporaryNoLocal extends \OC\Files\Storage\Temporary {
|
||||||
|
public function instanceOfStorage($className) {
|
||||||
|
if($className === '\OC\Files\Storage\Local') {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return parent::instanceOfStorage($className);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class View extends \Test\TestCase {
|
class View extends \Test\TestCase {
|
||||||
/**
|
/**
|
||||||
* @var \OC\Files\Storage\Storage[] $storages
|
* @var \OC\Files\Storage\Storage[] $storages
|
||||||
|
@ -291,9 +312,31 @@ class View extends \Test\TestCase {
|
||||||
/**
|
/**
|
||||||
* @medium
|
* @medium
|
||||||
*/
|
*/
|
||||||
function testCopyBetweenStorages() {
|
function testCopyBetweenStorageNoCross() {
|
||||||
|
$storage1 = $this->getTestStorage(true, '\Test\Files\TemporaryNoCross');
|
||||||
|
$storage2 = $this->getTestStorage(true, '\Test\Files\TemporaryNoCross');
|
||||||
|
$this->copyBetweenStorages($storage1, $storage2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @medium
|
||||||
|
*/
|
||||||
|
function testCopyBetweenStorageCross() {
|
||||||
$storage1 = $this->getTestStorage();
|
$storage1 = $this->getTestStorage();
|
||||||
$storage2 = $this->getTestStorage();
|
$storage2 = $this->getTestStorage();
|
||||||
|
$this->copyBetweenStorages($storage1, $storage2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @medium
|
||||||
|
*/
|
||||||
|
function testCopyBetweenStorageCrossNonLocal() {
|
||||||
|
$storage1 = $this->getTestStorage(true, '\Test\Files\TemporaryNoLocal');
|
||||||
|
$storage2 = $this->getTestStorage(true, '\Test\Files\TemporaryNoLocal');
|
||||||
|
$this->copyBetweenStorages($storage1, $storage2);
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyBetweenStorages($storage1, $storage2) {
|
||||||
\OC\Files\Filesystem::mount($storage1, array(), '/');
|
\OC\Files\Filesystem::mount($storage1, array(), '/');
|
||||||
\OC\Files\Filesystem::mount($storage2, array(), '/substorage');
|
\OC\Files\Filesystem::mount($storage2, array(), '/substorage');
|
||||||
|
|
||||||
|
@ -315,9 +358,31 @@ class View extends \Test\TestCase {
|
||||||
/**
|
/**
|
||||||
* @medium
|
* @medium
|
||||||
*/
|
*/
|
||||||
function testMoveBetweenStorages() {
|
function testMoveBetweenStorageNoCross() {
|
||||||
|
$storage1 = $this->getTestStorage(true, '\Test\Files\TemporaryNoCross');
|
||||||
|
$storage2 = $this->getTestStorage(true, '\Test\Files\TemporaryNoCross');
|
||||||
|
$this->moveBetweenStorages($storage1, $storage2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @medium
|
||||||
|
*/
|
||||||
|
function testMoveBetweenStorageCross() {
|
||||||
$storage1 = $this->getTestStorage();
|
$storage1 = $this->getTestStorage();
|
||||||
$storage2 = $this->getTestStorage();
|
$storage2 = $this->getTestStorage();
|
||||||
|
$this->moveBetweenStorages($storage1, $storage2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @medium
|
||||||
|
*/
|
||||||
|
function testMoveBetweenStorageCrossNonLocal() {
|
||||||
|
$storage1 = $this->getTestStorage(true, '\Test\Files\TemporaryNoLocal');
|
||||||
|
$storage2 = $this->getTestStorage(true, '\Test\Files\TemporaryNoLocal');
|
||||||
|
$this->moveBetweenStorages($storage1, $storage2);
|
||||||
|
}
|
||||||
|
|
||||||
|
function moveBetweenStorages($storage1, $storage2) {
|
||||||
\OC\Files\Filesystem::mount($storage1, array(), '/');
|
\OC\Files\Filesystem::mount($storage1, array(), '/');
|
||||||
\OC\Files\Filesystem::mount($storage2, array(), '/substorage');
|
\OC\Files\Filesystem::mount($storage2, array(), '/substorage');
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue