Skip to content

Commit 1d80351

Browse files
committed
fix: Show errors in encryption:migrate-key-storage-format and continue to other files
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent 6dfa09f commit 1d80351

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

core/Command/Encryption/MigrateKeyStorage.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5555
protected function updateKeys(string $root, OutputInterface $output): bool {
5656
$output->writeln('Start to update the keys:');
5757

58-
$this->updateSystemKeys($root);
58+
$this->updateSystemKeys($root, $output);
5959
$this->updateUsersKeys($root, $output);
6060
$this->config->deleteSystemValue('encryption.key_storage_migrated');
6161
return true;
@@ -64,15 +64,15 @@ protected function updateKeys(string $root, OutputInterface $output): bool {
6464
/**
6565
* Move system key folder
6666
*/
67-
protected function updateSystemKeys(string $root): void {
67+
protected function updateSystemKeys(string $root, OutputInterface $output): void {
6868
if (!$this->rootView->is_dir($root . '/files_encryption')) {
6969
return;
7070
}
7171

72-
$this->traverseKeys($root . '/files_encryption', null);
72+
$this->traverseKeys($root . '/files_encryption', null, $output);
7373
}
7474

75-
private function traverseKeys(string $folder, ?string $uid): void {
75+
private function traverseKeys(string $folder, ?string $uid, OutputInterface $output): void {
7676
$listing = $this->rootView->getDirectoryContent($folder);
7777

7878
foreach ($listing as $node) {
@@ -88,6 +88,11 @@ private function traverseKeys(string $folder, ?string $uid): void {
8888

8989
$content = $this->rootView->file_get_contents($path);
9090

91+
if ($content === false) {
92+
$output->writeln("<error>Failed to open path $path</error>");
93+
continue;
94+
}
95+
9196
try {
9297
$this->crypto->decrypt($content);
9398
continue;
@@ -106,12 +111,12 @@ private function traverseKeys(string $folder, ?string $uid): void {
106111
}
107112
}
108113

109-
private function traverseFileKeys(string $folder): void {
114+
private function traverseFileKeys(string $folder, OutputInterface $output): void {
110115
$listing = $this->rootView->getDirectoryContent($folder);
111116

112117
foreach ($listing as $node) {
113118
if ($node['mimetype'] === 'httpd/unix-directory') {
114-
$this->traverseFileKeys($folder . '/' . $node['name']);
119+
$this->traverseFileKeys($folder . '/' . $node['name'], $output);
115120
} else {
116121
$endsWith = function (string $haystack, string $needle): bool {
117122
$length = strlen($needle);
@@ -130,6 +135,11 @@ private function traverseFileKeys(string $folder): void {
130135

131136
$content = $this->rootView->file_get_contents($path);
132137

138+
if ($content === false) {
139+
$output->writeln("<error>Failed to open path $path</error>");
140+
continue;
141+
}
142+
133143
try {
134144
$this->crypto->decrypt($content);
135145
continue;
@@ -173,7 +183,7 @@ protected function updateUsersKeys(string $root, OutputInterface $output): void
173183
foreach ($users as $user) {
174184
$progress->advance();
175185
$this->setupUserFS($user);
176-
$this->updateUserKeys($root, $user);
186+
$this->updateUserKeys($root, $user, $output);
177187
}
178188
$offset += $limit;
179189
} while (count($users) >= $limit);
@@ -186,16 +196,16 @@ protected function updateUsersKeys(string $root, OutputInterface $output): void
186196
*
187197
* @throws \Exception
188198
*/
189-
protected function updateUserKeys(string $root, string $user): void {
199+
protected function updateUserKeys(string $root, string $user, OutputInterface $output): void {
190200
if ($this->userManager->userExists($user)) {
191201
$source = $root . '/' . $user . '/files_encryption/OC_DEFAULT_MODULE';
192202
if ($this->rootView->is_dir($source)) {
193-
$this->traverseKeys($source, $user);
203+
$this->traverseKeys($source, $user, $output);
194204
}
195205

196206
$source = $root . '/' . $user . '/files_encryption/keys';
197207
if ($this->rootView->is_dir($source)) {
198-
$this->traverseFileKeys($source);
208+
$this->traverseFileKeys($source, $output);
199209
}
200210
}
201211
}

0 commit comments

Comments
 (0)