diff options
author | Robin Appelman <icewind@owncloud.com> | 2015-01-16 13:32:42 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2015-04-13 15:13:02 +0200 |
commit | 8575bb2cb9f57d2b7e6d9e9e48e7c85485a7c63b (patch) | |
tree | f9ef4eca310c8c9262a9b2755d0dfa97260d517f /lib/private/files/storage/common.php | |
parent | b302592a6435b4f9bf18719b04314d9f463d54da (diff) | |
download | nextcloud-server-8575bb2cb9f57d2b7e6d9e9e48e7c85485a7c63b.tar.gz nextcloud-server-8575bb2cb9f57d2b7e6d9e9e48e7c85485a7c63b.zip |
Move cross storage copy logic to the storage
Diffstat (limited to 'lib/private/files/storage/common.php')
-rw-r--r-- | lib/private/files/storage/common.php | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php index ed85d3c07cc..164225de3e8 100644 --- a/lib/private/files/storage/common.php +++ b/lib/private/files/storage/common.php @@ -525,4 +525,52 @@ abstract class Common implements Storage { public function getMountOption($name, $default = null) { return isset($this->mountOptions[$name]) ? $this->mountOptions[$name] : $default; } + /** + * @param \OCP\Files\Storage $sourceStorage + * @param string $sourceInternalPath + * @param string $targetInternalPath + * @param bool $preserveMtime + * @return bool + */ + public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) { + if ($sourceStorage->is_dir($sourceInternalPath)) { + $dh = $sourceStorage->opendir($sourceInternalPath); + $result = $this->mkdir($targetInternalPath); + if (is_resource($dh)) { + while (($file = readdir($dh)) !== false) { + if (!Filesystem::isIgnoredDir($file)) { + $result &= $this->copyFromStorage($sourceStorage, $sourceInternalPath . '/' . $file, $targetInternalPath . '/' . $file); + } + } + } + } else { + $source = $sourceStorage->fopen($sourceInternalPath, 'r'); + $target = $this->fopen($targetInternalPath, 'w'); + list(, $result) = \OC_Helper::streamCopy($source, $target); + if ($preserveMtime) { + $this->touch($targetInternalPath, $sourceStorage->filemtime($sourceInternalPath)); + } + fclose($source); + fclose($target); + } + return $result; + } + + /** + * @param \OCP\Files\Storage $sourceStorage + * @param string $sourceInternalPath + * @param string $targetInternalPath + * @return bool + */ + public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + $result = $this->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath, true); + if ($result) { + if ($sourceStorage->is_dir($sourceInternalPath)) { + $sourceStorage->rmdir($sourceInternalPath); + } else { + $sourceStorage->unlink($sourceInternalPath); + } + } + return $result; + } } |