diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2023-05-11 11:24:16 +0200 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2023-05-11 11:24:16 +0200 |
commit | 36fc5dc8ae989f0694ca97c9175ee0debbc36142 (patch) | |
tree | b25681da5e910c380e3a9d5ff7f9c22ff4bc033f | |
parent | 725403cb0da4a78e0c0a28feb22e1bb8d1e2430b (diff) | |
download | nextcloud-server-36fc5dc8ae989f0694ca97c9175ee0debbc36142.tar.gz nextcloud-server-36fc5dc8ae989f0694ca97c9175ee0debbc36142.zip |
Copy data back instead of renaming to avoid changing the fileid
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
-rw-r--r-- | apps/encryption/lib/Command/FixLegacyFileKey.php | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/apps/encryption/lib/Command/FixLegacyFileKey.php b/apps/encryption/lib/Command/FixLegacyFileKey.php index 7ea28f2babe..7b0b4ccfb73 100644 --- a/apps/encryption/lib/Command/FixLegacyFileKey.php +++ b/apps/encryption/lib/Command/FixLegacyFileKey.php @@ -128,8 +128,17 @@ class FixLegacyFileKey extends Command { try { $this->rootView->copy($source, $target); - $this->rootView->touch($target, $fileInfo->getMTime()); - $this->rootView->rename($target, $source); + $copyResource = $this->rootView->fopen($target, 'r'); + $sourceResource = $this->rootView->fopen($source, 'w'); + if ($copyResource === false || $sourceResource === false) { + throw new DecryptionFailedException('Failed to open '.$source.' or '.$target); + } + if (stream_copy_to_stream($copyResource, $sourceResource) === false) { + $output->writeln('<error>Failed to copy '.$target.' data into '.$source.'</error>'); + $output->writeln('<error>Leaving both files in there to avoid data loss</error>'); + return; + } + $this->rootView->touch($source, $fileInfo->getMTime()); $output->writeln('<info>Migrated ' . $source . '</info>', OutputInterface::VERBOSITY_VERBOSE); } catch (DecryptionFailedException $e) { if ($this->rootView->file_exists($target)) { |