diff options
Diffstat (limited to 'apps/encryption')
-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)) { |