summaryrefslogtreecommitdiffstats
path: root/lib/private/Files/ObjectStore/ObjectStoreStorage.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Files/ObjectStore/ObjectStoreStorage.php')
-rw-r--r--lib/private/Files/ObjectStore/ObjectStoreStorage.php64
1 files changed, 62 insertions, 2 deletions
diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php
index 3a48efcb31e..060a249b9c6 100644
--- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php
+++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php
@@ -33,10 +33,15 @@ use Icewind\Streams\CallbackWrapper;
use Icewind\Streams\CountWrapper;
use Icewind\Streams\IteratorDirectory;
use OC\Files\Cache\CacheEntry;
+use OC\Files\Storage\PolyFill\CopyDirectory;
+use OCP\Files\Cache\ICacheEntry;
+use OCP\Files\FileInfo;
use OCP\Files\NotFoundException;
use OCP\Files\ObjectStore\IObjectStore;
class ObjectStoreStorage extends \OC\Files\Storage\Common {
+ use CopyDirectory;
+
/**
* @var \OCP\Files\ObjectStore\IObjectStore $objectStore
*/
@@ -309,7 +314,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
} else {
return false;
}
- // no break
+ // no break
case 'w':
case 'wb':
case 'w+':
@@ -464,7 +469,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
if ($size === null) {
$countStream = CountWrapper::wrap($stream, function ($writtenSize) use ($fileId, &$size) {
$this->getCache()->update($fileId, [
- 'size' => $writtenSize
+ 'size' => $writtenSize,
]);
$size = $writtenSize;
});
@@ -513,4 +518,59 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
public function getObjectStore(): IObjectStore {
return $this->objectStore;
}
+
+ public function copy($path1, $path2) {
+ $path1 = $this->normalizePath($path1);
+ $path2 = $this->normalizePath($path2);
+
+ $cache = $this->getCache();
+ $sourceEntry = $cache->get($path1);
+ if (!$sourceEntry) {
+ throw new NotFoundException('Source object not found');
+ }
+
+ $this->copyInner($sourceEntry, $path2);
+
+ return true;
+ }
+
+ private function copyInner(ICacheEntry $sourceEntry, string $to) {
+ $cache = $this->getCache();
+
+ if ($sourceEntry->getMimeType() === FileInfo::MIMETYPE_FOLDER) {
+ if ($cache->inCache($to)) {
+ $cache->remove($to);
+ }
+ $this->mkdir($to);
+
+ foreach ($cache->getFolderContentsById($sourceEntry->getId()) as $child) {
+ $this->copyInner($child, $to . '/' . $child->getName());
+ }
+ } else {
+ $this->copyFile($sourceEntry, $to);
+ }
+ }
+
+ private function copyFile(ICacheEntry $sourceEntry, string $to) {
+ $cache = $this->getCache();
+
+ $sourceUrn = $this->getURN($sourceEntry->getId());
+
+ $cache->copyFromCache($cache, $sourceEntry, $to);
+ $targetEntry = $cache->get($to);
+
+ if (!$targetEntry) {
+ throw new \Exception('Target not in cache after copy');
+ }
+
+ $targetUrn = $this->getURN($targetEntry->getId());
+
+ try {
+ $this->objectStore->copyObject($sourceUrn, $targetUrn);
+ } catch (\Exception $e) {
+ $cache->remove($to);
+
+ throw $e;
+ }
+ }
}