diff options
author | Julius Härtl <jus@bitgrid.net> | 2024-08-26 13:47:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-26 13:47:27 +0200 |
commit | 6d2253e69214d8fd0d7847408cdbe7c823c5bec2 (patch) | |
tree | b9846580face55e77e499a53526c1d9c8752b04c /lib/private | |
parent | e2b1de8bc1fc069d3ed385210753543f3f1e2934 (diff) | |
parent | bd740ac0b012da697085d4244b890f931a3b1fd2 (diff) | |
download | nextcloud-server-6d2253e69214d8fd0d7847408cdbe7c823c5bec2.tar.gz nextcloud-server-6d2253e69214d8fd0d7847408cdbe7c823c5bec2.zip |
Merge pull request #46013 from nextcloud/obj-store-move-from-storage-preserve-fileid
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 310b65ac939..228fc516677 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); |