Skip to content

Commit

Permalink
fix: write object to the correct urn when moving from another storage…
Browse files Browse the repository at this point in the history
… to object store

Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 authored and AndyScherzinger committed Sep 4, 2024
1 parent 4ac730e commit c539ae5
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/private/Files/ObjectStore/ObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,31 @@ public function copyFromStorage(
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);
Expand Down

0 comments on commit c539ae5

Please sign in to comment.