Skip to content

Commit c539ae5

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 4ac730e commit c539ae5

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
@@ -607,6 +607,31 @@ public function copyFromStorage(
607607
return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
608608
}
609609

610+
public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, ?ICacheEntry $sourceCacheEntry = null): bool {
611+
$sourceCache = $sourceStorage->getCache();
612+
if (!$sourceCacheEntry) {
613+
$sourceCacheEntry = $sourceCache->get($sourceInternalPath);
614+
}
615+
if ($sourceCacheEntry->getMimeType() === FileInfo::MIMETYPE_FOLDER) {
616+
foreach ($sourceCache->getFolderContents($sourceInternalPath) as $child) {
617+
$this->moveFromStorage($sourceStorage, $child->getPath(), $targetInternalPath . '/' . $child->getName());
618+
}
619+
$sourceStorage->rmdir($sourceInternalPath);
620+
} else {
621+
// move the cache entry before the contents so that we have the correct fileid/urn for the target
622+
$this->getCache()->moveFromCache($sourceCache, $sourceInternalPath, $targetInternalPath);
623+
try {
624+
$this->writeStream($targetInternalPath, $sourceStorage->fopen($sourceInternalPath, 'r'), $sourceCacheEntry->getSize());
625+
} catch (\Exception $e) {
626+
// restore the cache entry
627+
$sourceCache->moveFromCache($this->getCache(), $targetInternalPath, $sourceInternalPath);
628+
throw $e;
629+
}
630+
$sourceStorage->unlink($sourceInternalPath);
631+
}
632+
return true;
633+
}
634+
610635
public function copy($source, $target) {
611636
$source = $this->normalizePath($source);
612637
$target = $this->normalizePath($target);

0 commit comments

Comments
 (0)