]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix encryption:fix-encrypted-version command when encrypted is set to 0
authorCôme Chilliet <come.chilliet@nextcloud.com>
Tue, 2 Aug 2022 10:47:26 +0000 (12:47 +0200)
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>
Mon, 22 Aug 2022 09:16:16 +0000 (09:16 +0000)
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
apps/encryption/lib/Command/FixEncryptedVersion.php

index b3c0d8c4d1692597bdf55321fb3a8bbccfd101ee..d4c5eddbfe5ab845ecb8552c1c8fb7ac31b72301 100644 (file)
@@ -175,6 +175,22 @@ class FixEncryptedVersion extends Command {
                        $handle = $this->view->fopen($path, 'rb');
 
                        if (\fread($handle, 9001) !== false) {
+                               $fileInfo = $this->view->getFileInfo($path);
+                               if (!$fileInfo) {
+                                       $output->writeln("<warning>File info not found for file: \"$path\"</warning>");
+                                       return true;
+                               }
+                               $encryptedVersion = $fileInfo->getEncryptedVersion();
+                               $stat = $this->view->stat($path);
+                               if (($encryptedVersion == 0) && isset($stat['hasHeader']) && ($stat['hasHeader'] == true)) {
+                                       // The file has encrypted to false but has an encryption header
+                                       if ($ignoreCorrectEncVersionCall === true) {
+                                               // Lets rectify the file by correcting encrypted version
+                                               $output->writeln("<info>Attempting to fix the path: \"$path\"</info>");
+                                               return $this->correctEncryptedVersion($path, $output);
+                                       }
+                                       return false;
+                               }
                                $output->writeln("<info>The file \"$path\" is: OK</info>");
                        }