-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(files): files:scan error ouput when user_id is not found + return correct exit status on error #49412
Open
joshtrichards
wants to merge
1
commit into
master
Choose a base branch
from
jtr/desc-and-help-plus-minor-fixes-files-scan
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix(files): files:scan error ouput when user_id is not found + return correct exit status on error #49412
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -55,48 +55,109 @@ protected function configure(): void { | |||||
|
||||||
$this | ||||||
->setName('files:scan') | ||||||
->setDescription('rescan filesystem') | ||||||
->setDescription('Scans the filesystem for new files and updates the file cache') | ||||||
->setHelp('You can rescan all files or only those of select user(s) or a select path. Statistics will be shown at the end of the scan by default.') | ||||||
->addArgument( | ||||||
'user_id', | ||||||
InputArgument::OPTIONAL | InputArgument::IS_ARRAY, | ||||||
'will rescan all files of the given user(s)' | ||||||
'Rescan all files of the specified user(s)' | ||||||
) | ||||||
->addOption( | ||||||
'path', | ||||||
'p', | ||||||
InputOption::VALUE_REQUIRED, | ||||||
'limit rescan to this path, eg. --path="/alice/files/Music", the user_id is determined by the path and the user_id parameter and --all are ignored' | ||||||
'Limit rescan to the specified path, eg. --path="/alice/files/Music". Overrides the user_id and --all parameters; the user_id is determined from the path.' | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
) | ||||||
->addOption( | ||||||
'generate-metadata', | ||||||
null, | ||||||
InputOption::VALUE_OPTIONAL, | ||||||
'Generate metadata for all scanned files; if specified only generate for named value', | ||||||
'Generate metadata for all scanned files; if specified only generate for named value.', | ||||||
'' | ||||||
) | ||||||
->addOption( | ||||||
'all', | ||||||
null, | ||||||
InputOption::VALUE_NONE, | ||||||
'will rescan all files of all known users' | ||||||
'Rescan all files of all known users' | ||||||
)->addOption( | ||||||
'unscanned', | ||||||
null, | ||||||
InputOption::VALUE_NONE, | ||||||
'only scan files which are marked as not fully scanned' | ||||||
'Only scan files which are marked as not fully scanned' | ||||||
)->addOption( | ||||||
'shallow', | ||||||
null, | ||||||
InputOption::VALUE_NONE, | ||||||
'do not scan folders recursively' | ||||||
'Do not scan folders recursively' | ||||||
)->addOption( | ||||||
'home-only', | ||||||
null, | ||||||
InputOption::VALUE_NONE, | ||||||
'only scan the home storage, ignoring any mounted external storage or share' | ||||||
'Only scan the home storage, ignoring any mounted external storage or share' | ||||||
); | ||||||
} | ||||||
|
||||||
protected function execute(InputInterface $input, OutputInterface $output): int { | ||||||
$inputPath = $input->getOption('path'); | ||||||
if ($inputPath) { | ||||||
$inputPath = '/' . trim($inputPath, '/'); | ||||||
[, $user,] = explode('/', $inputPath, 3); | ||||||
$users = [$user]; | ||||||
} elseif ($input->getOption('all')) { | ||||||
$users = $this->userManager->search(''); | ||||||
} else { | ||||||
$users = $input->getArgument('user_id'); | ||||||
} | ||||||
|
||||||
# check quantity of users to be process and show it on the command line | ||||||
$users_total = count($users); | ||||||
if ($users_total === 0) { | ||||||
$output->writeln('<error>Please specify the user id to scan, --all to scan for all users or --path=...</error>'); | ||||||
return self::FAILURE; | ||||||
} | ||||||
|
||||||
$this->initTools($output); | ||||||
|
||||||
// getOption() logic on VALUE_OPTIONAL | ||||||
$metadata = null; // null if --generate-metadata is not set, empty if option have no value, value if set | ||||||
if ($input->getOption('generate-metadata') !== '') { | ||||||
$metadata = $input->getOption('generate-metadata') ?? ''; | ||||||
} | ||||||
|
||||||
$user_count = 0; | ||||||
foreach ($users as $user) { | ||||||
if (is_object($user)) { | ||||||
$user = $user->getUID(); | ||||||
} | ||||||
$path = $inputPath ?: '/' . $user; | ||||||
++$user_count; | ||||||
if ($this->userManager->userExists($user)) { | ||||||
$output->writeln("Starting scan for user $user_count out of $users_total ($user)"); | ||||||
$this->scanFiles($user, $path, $metadata, $output, $input->getOption('unscanned'), !$input->getOption('shallow'), $input->getOption('home-only')); | ||||||
$output->writeln('', OutputInterface::VERBOSITY_VERBOSE); | ||||||
} else { | ||||||
$output->writeln("<error>User $user_count out of $users_total not found ($user)</error>"); | ||||||
$output->writeln('', OutputInterface::VERBOSITY_VERBOSE); | ||||||
++$this->errorsCounter; | ||||||
} | ||||||
|
||||||
try { | ||||||
$this->abortIfInterrupted(); | ||||||
} catch (InterruptedException $e) { | ||||||
break; | ||||||
} | ||||||
} | ||||||
|
||||||
$this->presentStats($output); | ||||||
|
||||||
if ($this->errorsCounter > 0) { | ||||||
return self::FAILURE; | ||||||
} | ||||||
|
||||||
return self::SUCCESS; | ||||||
} | ||||||
|
||||||
protected function scanFiles(string $user, string $path, ?string $scanMetadata, OutputInterface $output, bool $backgroundScan = false, bool $recursive = true, bool $homeOnly = false): void { | ||||||
$connection = $this->reconnectToDatabase($output); | ||||||
$scanner = new Scanner( | ||||||
|
@@ -176,60 +237,6 @@ public function filterHomeMount(IMountPoint $mountPoint): bool { | |||||
return substr_count($mountPoint->getMountPoint(), '/') <= 3; | ||||||
} | ||||||
|
||||||
protected function execute(InputInterface $input, OutputInterface $output): int { | ||||||
$inputPath = $input->getOption('path'); | ||||||
if ($inputPath) { | ||||||
$inputPath = '/' . trim($inputPath, '/'); | ||||||
[, $user,] = explode('/', $inputPath, 3); | ||||||
$users = [$user]; | ||||||
} elseif ($input->getOption('all')) { | ||||||
$users = $this->userManager->search(''); | ||||||
} else { | ||||||
$users = $input->getArgument('user_id'); | ||||||
} | ||||||
|
||||||
# check quantity of users to be process and show it on the command line | ||||||
$users_total = count($users); | ||||||
if ($users_total === 0) { | ||||||
$output->writeln('<error>Please specify the user id to scan, --all to scan for all users or --path=...</error>'); | ||||||
return self::FAILURE; | ||||||
} | ||||||
|
||||||
$this->initTools($output); | ||||||
|
||||||
// getOption() logic on VALUE_OPTIONAL | ||||||
$metadata = null; // null if --generate-metadata is not set, empty if option have no value, value if set | ||||||
if ($input->getOption('generate-metadata') !== '') { | ||||||
$metadata = $input->getOption('generate-metadata') ?? ''; | ||||||
} | ||||||
|
||||||
$user_count = 0; | ||||||
foreach ($users as $user) { | ||||||
if (is_object($user)) { | ||||||
$user = $user->getUID(); | ||||||
} | ||||||
$path = $inputPath ?: '/' . $user; | ||||||
++$user_count; | ||||||
if ($this->userManager->userExists($user)) { | ||||||
$output->writeln("Starting scan for user $user_count out of $users_total ($user)"); | ||||||
$this->scanFiles($user, $path, $metadata, $output, $input->getOption('unscanned'), !$input->getOption('shallow'), $input->getOption('home-only')); | ||||||
$output->writeln('', OutputInterface::VERBOSITY_VERBOSE); | ||||||
} else { | ||||||
$output->writeln("<error>Unknown user $user_count $user</error>"); | ||||||
$output->writeln('', OutputInterface::VERBOSITY_VERBOSE); | ||||||
} | ||||||
|
||||||
try { | ||||||
$this->abortIfInterrupted(); | ||||||
} catch (InterruptedException $e) { | ||||||
break; | ||||||
} | ||||||
} | ||||||
|
||||||
$this->presentStats($output); | ||||||
return self::SUCCESS; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Initialises some useful tools for the Command | ||||||
*/ | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe more explicit, as it does not only detect new files.