-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Replace $verbose with VERBOSITY_VERBOSE for scanFiles method #11968
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
|
@@ -33,7 +33,6 @@ | |
use OCP\IConfig; | ||
use OCP\IDBConnection; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Helper\Table; | ||
|
||
|
@@ -62,19 +61,7 @@ protected function configure() { | |
|
||
$this | ||
->setName('files:scan-app-data') | ||
->setDescription('rescan the AppData folder') | ||
->addOption( | ||
'quiet', | ||
'q', | ||
InputOption::VALUE_NONE, | ||
'suppress any output' | ||
) | ||
->addOption( | ||
'verbose', | ||
'-v|vv|vvv', | ||
InputOption::VALUE_NONE, | ||
'verbose the output' | ||
); | ||
->setDescription('rescan the AppData folder'); | ||
} | ||
|
||
public function checkScanWarning($fullPath, OutputInterface $output) { | ||
|
@@ -86,7 +73,7 @@ public function checkScanWarning($fullPath, OutputInterface $output) { | |
} | ||
} | ||
|
||
protected function scanFiles($verbose, OutputInterface $output) { | ||
protected function scanFiles(OutputInterface $output) { | ||
try { | ||
$appData = $this->getAppDataFolder(); | ||
} catch (NotFoundException $e) { | ||
|
@@ -96,44 +83,36 @@ protected function scanFiles($verbose, OutputInterface $output) { | |
|
||
$connection = $this->reconnectToDatabase($output); | ||
$scanner = new \OC\Files\Utils\Scanner(null, $connection, \OC::$server->getLogger()); | ||
|
||
# check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception | ||
# printout and count | ||
if ($verbose) { | ||
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { | ||
$output->writeln("\tFile <info>$path</info>"); | ||
$this->filesCounter += 1; | ||
$this->abortIfInterrupted(); | ||
}); | ||
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { | ||
$output->writeln("\tFolder <info>$path</info>"); | ||
$this->foldersCounter += 1; | ||
$this->abortIfInterrupted(); | ||
}); | ||
$scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output) { | ||
$output->writeln('Error while scanning, storage not available (' . $e->getMessage() . ')'); | ||
}); | ||
# count only | ||
} else { | ||
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function () use ($output) { | ||
$this->filesCounter += 1; | ||
$this->abortIfInterrupted(); | ||
}); | ||
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function () use ($output) { | ||
$this->foldersCounter += 1; | ||
$this->abortIfInterrupted(); | ||
}); | ||
} | ||
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function($path) use ($output) { | ||
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { | ||
$output->writeln("\tFile\t<info>$path</info>", OutputInterface::VERBOSITY_VERBOSE); | ||
++$this->filesCounter; | ||
$this->abortIfInterrupted(); | ||
}); | ||
|
||
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { | ||
$output->writeln("\tFolder\t<info>$path</info>", OutputInterface::VERBOSITY_VERBOSE); | ||
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. same |
||
++$this->foldersCounter; | ||
$this->abortIfInterrupted(); | ||
}); | ||
|
||
$scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output) { | ||
$output->writeln('Error while scanning, storage not available (' . $e->getMessage() . ')', OutputInterface::VERBOSITY_VERBOSE); | ||
}); | ||
|
||
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { | ||
$this->checkScanWarning($path, $output); | ||
}); | ||
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function($path) use ($output) { | ||
|
||
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { | ||
$this->checkScanWarning($path, $output); | ||
}); | ||
|
||
try { | ||
$scanner->scan($appData->getPath()); | ||
} catch (ForbiddenException $e) { | ||
$output->writeln("<error>Storage not writable</error>"); | ||
$output->writeln('<error>Storage not writable</error>'); | ||
$output->writeln('Make sure you\'re running the scan command only as the user the web server runs as'); | ||
} catch (InterruptedException $e) { | ||
# exit the function if ctrl-c has been pressed | ||
|
@@ -148,33 +127,19 @@ protected function scanFiles($verbose, OutputInterface $output) { | |
|
||
|
||
protected function execute(InputInterface $input, OutputInterface $output) { | ||
# no messaging level option means: no full printout but statistics | ||
# $quiet means no print at all | ||
# $verbose means full printout including statistics | ||
# -q -v full stat | ||
# 0 0 no yes | ||
# 0 1 yes yes | ||
# 1 -- no no (quiet overrules verbose) | ||
$verbose = $input->getOption('verbose'); | ||
$quiet = $input->getOption('quiet'); | ||
# restrict the verbosity level to VERBOSITY_VERBOSE | ||
if ($output->getVerbosity() > OutputInterface::VERBOSITY_VERBOSE) { | ||
$output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); | ||
} | ||
if ($quiet) { | ||
$verbose = false; | ||
} | ||
|
||
$output->writeln("\nScanning AppData for files"); | ||
$output->writeln('Scanning AppData for files'); | ||
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. same |
||
|
||
$this->initTools(); | ||
|
||
$this->scanFiles($verbose, $output); | ||
$this->scanFiles($output); | ||
$output->writeln('', OutputInterface::VERBOSITY_VERBOSE); | ||
|
||
# stat: printout statistics if $quiet was not set | ||
if (!$quiet) { | ||
$this->presentStats($output); | ||
} | ||
$this->presentStats($output); | ||
} | ||
|
||
/** | ||
|
@@ -213,7 +178,6 @@ public function exceptionErrorHandler($severity, $message, $file, $line) { | |
protected function presentStats(OutputInterface $output) { | ||
// Stop the timer | ||
$this->execTime += microtime(true); | ||
$output->writeln(""); | ||
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. same |
||
|
||
$headers = [ | ||
'Folders', 'Files', 'Elapsed time' | ||
|
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.
please don't change these unrelated commands. It's fine to fix/enhance this in another PR though.