diff options
author | Robin Appelman <robin@icewind.nl> | 2024-06-20 15:57:59 +0200 |
---|---|---|
committer | Andy Scherzinger <info@andy-scherzinger.de> | 2024-09-04 23:17:04 +0200 |
commit | 05f79f23cd6333f957136ca32af771ffe96b65b7 (patch) | |
tree | 1587ba8639fde4b4245573eed17575308f1f1c51 /lib/private/Files | |
parent | 125e18d78b7e831698358573c05dcdb66b748d89 (diff) | |
download | nextcloud-server-05f79f23cd6333f957136ca32af771ffe96b65b7.tar.gz nextcloud-server-05f79f23cd6333f957136ca32af771ffe96b65b7.zip |
fix: write object to the correct urn when moving from another storage to object store
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Files')
-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 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); |