diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2024-03-28 17:30:22 +0100 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2024-03-28 17:44:28 +0100 |
commit | 15c83d24429742a8877ef323c9b5171e30315e4e (patch) | |
tree | bfcdc7c42fafc26ba827ef6c7b0c85fbb9a985ee | |
parent | 98362bd0bc6beaaad7f4f18ae32b82722f6f8997 (diff) | |
download | nextcloud-server-backport/44555/stable27.tar.gz nextcloud-server-backport/44555/stable27.zip |
fix: Show errors in encryption:migrate-key-storage-format and continue to other filesbackport/44555/stable27
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
-rw-r--r-- | core/Command/Encryption/MigrateKeyStorage.php | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/core/Command/Encryption/MigrateKeyStorage.php b/core/Command/Encryption/MigrateKeyStorage.php index 8d9c7910769..a0aa901d047 100644 --- a/core/Command/Encryption/MigrateKeyStorage.php +++ b/core/Command/Encryption/MigrateKeyStorage.php @@ -82,7 +82,7 @@ class MigrateKeyStorage extends Command { 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,15 +91,15 @@ class MigrateKeyStorage extends Command { /** * 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) { + private function traverseKeys(string $folder, ?string $uid, OutputInterface $output) { $listing = $this->rootView->getDirectoryContent($folder); foreach ($listing as $node) { @@ -115,6 +115,11 @@ class MigrateKeyStorage extends Command { $content = $this->rootView->file_get_contents($path); + if ($content === false) { + $output->writeln("<error>Failed to open path $path</error>"); + continue; + } + try { $this->crypto->decrypt($content); continue; @@ -133,12 +138,12 @@ class MigrateKeyStorage extends Command { } } - private function traverseFileKeys(string $folder) { + private function traverseFileKeys(string $folder, OutputInterface $output) { $listing = $this->rootView->getDirectoryContent($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 @@ class MigrateKeyStorage extends Command { $content = $this->rootView->file_get_contents($path); + if ($content === false) { + $output->writeln("<error>Failed to open path $path</error>"); + continue; + } + try { $this->crypto->decrypt($content); continue; @@ -205,7 +215,7 @@ class MigrateKeyStorage extends Command { foreach ($users as $user) { $progress->advance(); $this->setupUserFS($user); - $this->updateUserKeys($root, $user); + $this->updateUserKeys($root, $user, $output); } $offset += $limit; } while (count($users) >= $limit); @@ -220,16 +230,16 @@ class MigrateKeyStorage extends Command { * @param string $user * @throws \Exception */ - protected function updateUserKeys(string $root, string $user) { + protected function updateUserKeys(string $root, string $user, OutputInterface $output) { 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); } } } |