Skip to content

Commit 0746fa3

Browse files
icewind1991AndyScherzinger
authored andcommitted
fix: write object to the correct urn when moving from another storage to object store
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent f81a349 commit 0746fa3

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

lib/private/Files/ObjectStore/ObjectStoreStorage.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,31 @@ public function copyFromStorage(
594594
return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
595595
}
596596

597+
public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, ?ICacheEntry $sourceCacheEntry = null): bool {
598+
$sourceCache = $sourceStorage->getCache();
599+
if (!$sourceCacheEntry) {
600+
$sourceCacheEntry = $sourceCache->get($sourceInternalPath);
601+
}
602+
if ($sourceCacheEntry->getMimeType() === FileInfo::MIMETYPE_FOLDER) {
603+
foreach ($sourceCache->getFolderContents($sourceInternalPath) as $child) {
604+
$this->moveFromStorage($sourceStorage, $child->getPath(), $targetInternalPath . '/' . $child->getName());
605+
}
606+
$sourceStorage->rmdir($sourceInternalPath);
607+
} else {
608+
// move the cache entry before the contents so that we have the correct fileid/urn for the target
609+
$this->getCache()->moveFromCache($sourceCache, $sourceInternalPath, $targetInternalPath);
610+
try {
611+
$this->writeStream($targetInternalPath, $sourceStorage->fopen($sourceInternalPath, 'r'), $sourceCacheEntry->getSize());
612+
} catch (\Exception $e) {
613+
// restore the cache entry
614+
$sourceCache->moveFromCache($this->getCache(), $targetInternalPath, $sourceInternalPath);
615+
throw $e;
616+
}
617+
$sourceStorage->unlink($sourceInternalPath);
618+
}
619+
return true;
620+
}
621+
597622
public function copy($source, $target) {
598623
$source = $this->normalizePath($source);
599624
$target = $this->normalizePath($target);

0 commit comments

Comments
 (0)