From 146284f170d3da88709ec76007f6f7b5ad975d39 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=B4me=20Chilliet?= Date: Thu, 4 May 2023 17:21:05 +0200 Subject: [PATCH] Fix fopen mode MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- apps/encryption/lib/Command/FixLegacyFileKey.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/encryption/lib/Command/FixLegacyFileKey.php b/apps/encryption/lib/Command/FixLegacyFileKey.php index fd3221a6c1f..7a17e637d41 100644 --- a/apps/encryption/lib/Command/FixLegacyFileKey.php +++ b/apps/encryption/lib/Command/FixLegacyFileKey.php @@ -112,12 +112,17 @@ class FixLegacyFileKey extends Command { /* If that did not throw and filekey is not empty, a legacy filekey is used */ $clean = false; $output->writeln($path . ' is using a legacy filekey, migrating'); - $file = $this->rootView->fopen($path, 'w+'); + $file = $this->rootView->fopen($path, 'r+'); if ($file) { - fwrite($file, ''); + $firstByte = fread($file, 1); + if ($firstByte === false) { + $output->writeln('failed to read ' . $path . ''); + continue; + } + fwrite($file, $firstByte); fclose($file); } else { - $output->writeln('failed to open' . $path . ''); + $output->writeln('failed to open ' . $path . ''); } } } -- 2.39.5