diff --git a/core/Command/Encryption/MigrateKeyStorage.php b/core/Command/Encryption/MigrateKeyStorage.php index 8d9c7910769cd..d96bbe7171251 100644 --- a/core/Command/Encryption/MigrateKeyStorage.php +++ b/core/Command/Encryption/MigrateKeyStorage.php @@ -82,7 +82,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int protected function updateKeys(string $root, OutputInterface $output): bool { $output->writeln("Start to update the keys:"); - $this->updateSystemKeys($root); + $this->updateSystemKeys($root, $output); $this->updateUsersKeys($root, $output); $this->config->deleteSystemValue('encryption.key_storage_migrated'); return true; @@ -91,12 +91,12 @@ protected function updateKeys(string $root, OutputInterface $output): bool { /** * Move system key folder */ - protected function updateSystemKeys(string $root): void { + protected function updateSystemKeys(string $root, OutputInterface $output): void { if (!$this->rootView->is_dir($root . '/files_encryption')) { return; } - $this->traverseKeys($root . '/files_encryption', null); + $this->traverseKeys($root . '/files_encryption', null, $output); } private function traverseKeys(string $folder, ?string $uid) { @@ -115,6 +115,11 @@ private function traverseKeys(string $folder, ?string $uid) { $content = $this->rootView->file_get_contents($path); + if ($content === false) { + $output->writeln("Failed to open path $path"); + continue; + } + try { $this->crypto->decrypt($content); continue; @@ -138,7 +143,7 @@ private function traverseFileKeys(string $folder) { foreach ($listing as $node) { if ($node['mimetype'] === 'httpd/unix-directory') { - $this->traverseFileKeys($folder . '/' . $node['name']); + $this->traverseFileKeys($folder . '/' . $node['name'], $output); } else { $endsWith = function ($haystack, $needle) { $length = strlen($needle); @@ -157,6 +162,11 @@ private function traverseFileKeys(string $folder) { $content = $this->rootView->file_get_contents($path); + if ($content === false) { + $output->writeln("Failed to open path $path"); + continue; + } + try { $this->crypto->decrypt($content); continue; @@ -205,7 +215,7 @@ protected function updateUsersKeys(string $root, OutputInterface $output) { foreach ($users as $user) { $progress->advance(); $this->setupUserFS($user); - $this->updateUserKeys($root, $user); + $this->updateUserKeys($root, $user, $output); } $offset += $limit; } while (count($users) >= $limit); @@ -224,12 +234,12 @@ protected function updateUserKeys(string $root, string $user) { if ($this->userManager->userExists($user)) { $source = $root . '/' . $user . '/files_encryption/OC_DEFAULT_MODULE'; if ($this->rootView->is_dir($source)) { - $this->traverseKeys($source, $user); + $this->traverseKeys($source, $user, $output); } $source = $root . '/' . $user . '/files_encryption/keys'; if ($this->rootView->is_dir($source)) { - $this->traverseFileKeys($source); + $this->traverseFileKeys($source, $output); } } }