diff options
author | Andy Scherzinger <info@andy-scherzinger.de> | 2024-09-05 16:23:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-05 16:23:10 +0200 |
commit | 473c9d82490a31c4298aedca8d56682e862e11c8 (patch) | |
tree | 990b855ed786012d99720cdbdf17c6f29c57c87a /lib/private | |
parent | 3fbca06e199494a876e554b0a758db8640c29157 (diff) | |
parent | 8a539df3a8dca5413f901edd02a849533b82e09c (diff) | |
download | nextcloud-server-473c9d82490a31c4298aedca8d56682e862e11c8.tar.gz nextcloud-server-473c9d82490a31c4298aedca8d56682e862e11c8.zip |
Merge pull request #47486 from nextcloud/backport/46013/stable29
[stable29] fix: write object to the correct urn when moving from another storage to object store
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Files/ObjectStore/ObjectStoreStorage.php | 25 |
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); |