Skip to content

Commit ae77cde

Browse files
committed
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 f56bca3 commit ae77cde

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lib/private/Files/ObjectStore/ObjectStoreStorage.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,30 @@ 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+
$this->getCache()->remove($targetInternalPath);
614+
throw $e;
615+
}
616+
$sourceStorage->unlink($sourceInternalPath);
617+
}
618+
return true;
619+
}
620+
597621
public function copy($source, $target) {
598622
$source = $this->normalizePath($source);
599623
$target = $this->normalizePath($target);

0 commit comments

Comments
 (0)