Skip to content

Commit 5bbf5f0

Browse files
hamza221backportbot[bot]
authored andcommitted
fix(encryption): limit oprhaned keys scan to one user
Signed-off-by: Hamza <hamzamahjoubi221@gmail.com>
1 parent 1a18fe5 commit 5bbf5f0

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

apps/encryption/lib/Command/CleanOrphanedKeys.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Symfony\Component\Console\Command\Command;
2323
use Symfony\Component\Console\Helper\ProgressBar;
2424
use Symfony\Component\Console\Helper\QuestionHelper;
25+
use Symfony\Component\Console\Input\InputArgument;
2526
use Symfony\Component\Console\Input\InputInterface;
2627
use Symfony\Component\Console\Output\OutputInterface;
2728
use Symfony\Component\Console\Question\ConfirmationQuestion;
@@ -45,10 +46,28 @@ public function __construct(
4546
protected function configure(): void {
4647
$this
4748
->setName('encryption:clean-orphaned-keys')
48-
->setDescription('Scan the keys storage for orphaned keys and remove them');
49+
->setDescription('Scan the keys storage for orphaned keys and remove them')
50+
->addArgument(
51+
'user',
52+
InputArgument::OPTIONAL,
53+
'The id of the user for whom the scan should be performed. If not provided, all users will be scanned.'
54+
);
4955
}
5056

5157
protected function execute(InputInterface $input, OutputInterface $output): int {
58+
$users = [];
59+
$userId = $input->getArgument('user');
60+
if ($userId !== null) {
61+
$user = $this->userManager->get($userId);
62+
if (!$user) {
63+
$output->writeln("<error>User $userId not found</error>");
64+
return self::FAILURE;
65+
}
66+
$users[] = $user;
67+
} else {
68+
$users = $this->userManager->getSeenUsers();
69+
}
70+
5271
$orphanedKeys = [];
5372
$headline = 'Scanning all keys for file parity';
5473
$output->writeln($headline);
@@ -57,16 +76,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5776
$progress = new ProgressBar($output);
5877
$progress->setFormat(" %message% \n [%bar%]");
5978

60-
foreach ($this->userManager->getSeenUsers() as $user) {
79+
foreach ($users as $user) {
6180
$uid = $user->getUID();
6281
$progress->setMessage('Scanning all keys for: ' . $uid);
6382
$progress->advance();
6483
$this->setupUserFileSystem($user);
6584
$root = $this->encryptionUtil->getKeyStorageRoot() . '/' . $uid . '/files_encryption/keys';
6685
$userOrphanedKeys = $this->scanFolder($output, $root, $uid);
6786
$orphanedKeys = array_merge($orphanedKeys, $userOrphanedKeys);
87+
$progress->setMessage('Scanned orphaned keys for user: ' . $uid);
6888
}
69-
$progress->setMessage('Scanned orphaned keys for all users');
7089
$progress->finish();
7190
$output->writeln("\n");
7291
foreach ($orphanedKeys as $keyPath) {
@@ -79,7 +98,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7998
if ($this->questionHelper->ask($input, $output, $question)) {
8099
$this->deleteAll($orphanedKeys, $output);
81100
} else {
82-
83101
$question = new ConfirmationQuestion('Do you want to delete specific keys? (y/n) ', false);
84102
if ($this->questionHelper->ask($input, $output, $question)) {
85103
$this->deleteSpecific($input, $output, $orphanedKeys);

0 commit comments

Comments
 (0)