aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2024-09-05 10:49:06 +0200
committerGitHub <noreply@github.com>2024-09-05 10:49:06 +0200
commit83e6649cfa502dcad5d9a65c2691b504abcbed09 (patch)
treea01fe6987cfa9867500415c156d69a4da2282910
parent9f9645503088eaac5cdc18e47ec4dbd595f06765 (diff)
parent05f79f23cd6333f957136ca32af771ffe96b65b7 (diff)
downloadnextcloud-server-83e6649cfa502dcad5d9a65c2691b504abcbed09.tar.gz
nextcloud-server-83e6649cfa502dcad5d9a65c2691b504abcbed09.zip
Merge pull request #47484 from nextcloud/backport/46013/stable30
[stable30] fix: write object to the correct urn when moving from another storage to object store
-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 389f744eab4..1d940b7e619 100644
--- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php
+++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php
@@ -594,6 +594,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);