diff --git a/lib/private/Files/Cache/Updater.php b/lib/private/Files/Cache/Updater.php index 597631aa7f814..88ca3dc1bcf89 100644 --- a/lib/private/Files/Cache/Updater.php +++ b/lib/private/Files/Cache/Updater.php @@ -200,8 +200,14 @@ private function copyOrRenameFromStorage(IStorage $sourceStorage, string $source $sourceInfo = $sourceCache->get($source); if ($sourceInfo !== false) { + // Remove existing cache entry to no reuse the fileId. if ($this->cache->inCache($target)) { - $this->cache->remove($target); + $existingCacheInfo = $this->cache->get($target); + // Do not remove the existing target if it has just been created. + // It was probably created by the same operation and we want to keep the fileId. + if (time() - $existingCacheInfo->getMTime() > 1) { + $this->cache->remove($target); + } } $operation($sourceCache, $sourceInfo);