summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2024-06-20 15:57:59 +0200
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2024-08-26 12:24:38 +0000
commit8a539df3a8dca5413f901edd02a849533b82e09c (patch)
tree319a041e5bcca2c54a5c4538b19c20c145e7ed54
parent4415c6c195d3b98dbc84004af2847ab94aa96e8c (diff)
downloadnextcloud-server-8a539df3a8dca5413f901edd02a849533b82e09c.tar.gz
nextcloud-server-8a539df3a8dca5413f901edd02a849533b82e09c.zip
fix: write object to the correct urn when moving from another storage to object store
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r--lib/private/Files/ObjectStore/ObjectStoreStorage.php25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php
index ef4d2f7ca13..8b770ee19c5 100644
--- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php
+++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php
@@ -617,6 +617,31 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
}
+ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, ?ICacheEntry $sourceCacheEntry = null): bool {
+ $sourceCache = $sourceStorage->getCache();
+ if (!$sourceCacheEntry) {
+ $sourceCacheEntry = $sourceCache->get($sourceInternalPath);
+ }
+ if ($sourceCacheEntry->getMimeType() === FileInfo::MIMETYPE_FOLDER) {
+ foreach ($sourceCache->getFolderContents($sourceInternalPath) as $child) {
+ $this->moveFromStorage($sourceStorage, $child->getPath(), $targetInternalPath . '/' . $child->getName());
+ }
+ $sourceStorage->rmdir($sourceInternalPath);
+ } else {
+ // move the cache entry before the contents so that we have the correct fileid/urn for the target
+ $this->getCache()->moveFromCache($sourceCache, $sourceInternalPath, $targetInternalPath);
+ try {
+ $this->writeStream($targetInternalPath, $sourceStorage->fopen($sourceInternalPath, 'r'), $sourceCacheEntry->getSize());
+ } catch (\Exception $e) {
+ // restore the cache entry
+ $sourceCache->moveFromCache($this->getCache(), $targetInternalPath, $sourceInternalPath);
+ throw $e;
+ }
+ $sourceStorage->unlink($sourceInternalPath);
+ }
+ return true;
+ }
+
public function copy($source, $target) {
$source = $this->normalizePath($source);
$target = $this->normalizePath($target);