Skip to content

Commit

Permalink
fix: rework move into object store to better preserve fileids
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <[email protected]>

[skip ci]
  • Loading branch information
icewind1991 authored and backportbot[bot] committed Oct 1, 2024
1 parent a8c237c commit e27b6f4
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions lib/private/Files/ObjectStore/ObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -634,23 +634,15 @@ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t
$this->moveFromStorage($sourceStorage, $child->getPath(), $targetInternalPath . '/' . $child->getName());
}
$sourceStorage->rmdir($sourceInternalPath);
$sourceStorage->getCache()->remove($sourceInternalPath);
} else {
$sourceStream = $sourceStorage->fopen($sourceInternalPath, 'r');
if (!$sourceStream) {
return false;
}
// 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, $sourceStream, $sourceCacheEntry->getSize());
} catch (\Exception $e) {
// restore the cache entry
$sourceCache->moveFromCache($this->getCache(), $targetInternalPath, $sourceInternalPath);
throw $e;
}
$sourceStorage->unlink($sourceInternalPath);
}
if ($sourceStorage->instanceOfStorage(ObjectStoreStorage::class)) {
/** @var ObjectStoreStorage $sourceStorage */
$sourceStorage->setPreserveCacheOnDelete(false);
}
$this->getCache()->moveFromCache($sourceCache, $sourceInternalPath, $targetInternalPath);

return true;
}

Expand Down

0 comments on commit e27b6f4

Please sign in to comment.