index: better output

Signed-off-by: Varun Patil <varunpatil@ucla.edu>
pull/579/head
Varun Patil 2023-04-13 22:24:01 -07:00
parent 86c3c260a1
commit a9b0f463a1
3 changed files with 18 additions and 22 deletions

View File

@ -33,7 +33,6 @@ use OCP\IUserManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\ConsoleSectionOutput;
use Symfony\Component\Console\Output\OutputInterface;
class IndexOpts
@ -66,7 +65,6 @@ class Index extends Command
// IO
private InputInterface $input;
private OutputInterface $output;
private ConsoleSectionOutput $outputSection;
// Command options
private IndexOpts $opts;
@ -105,7 +103,10 @@ class Index extends Command
$this->input = $input;
$this->output = $output;
$this->opts = new IndexOpts($input);
// Assign to indexer
$this->indexer->output = $output;
$this->indexer->section = $output->section();
try {
// Use static exiftool process

View File

@ -52,30 +52,18 @@ class PostWriteListener implements IEventListener
}
// Check if a directory at a higher level contains a .nomedia file
// Do this by getting all the parent folders first, then checking them
// in reverse order from root to leaf. The rationale is that the
// .nomedia file is most likely to be in higher level directories.
$parents = [];
try {
$parent = $node->getParent();
while ($parent) {
$parents[] = $parent;
$parent = $parent->getParent();
$parent = $node;
while ($parent = $parent->getParent()) {
if ($parent->nodeExists('.nomedia')) {
return;
}
}
} catch (\OCP\Files\NotFoundException $e) {
// This happens when the parent is in the root directory
// and getParent() is called on it.
}
// Traverse the array in reverse order looking for .nomedia
$parents = array_reverse($parents);
foreach ($parents as &$parent) {
if ($parent->nodeExists('.nomedia')) {
return;
}
}
$this->timelineWrite->processFile($node);
}
}

View File

@ -35,11 +35,13 @@ use OCP\IDBConnection;
use OCP\IPreview;
use OCP\ITempManager;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Output\ConsoleSectionOutput;
use Symfony\Component\Console\Output\OutputInterface;
class Index
{
public ?OutputInterface $output;
public ?ConsoleSectionOutput $section;
protected IRootFolder $rootFolder;
protected TimelineWrite $timelineWrite;
@ -112,8 +114,9 @@ class Index
*/
public function indexFolder(Folder $folder): void
{
// Respect the '.nomedia' file. If present don't traverse the folder
if ($folder->nodeExists('.nomedia')) {
$this->log("Skipping folder {$folder->getPath()} due to .nomedia file\n", true);
return;
}
@ -183,6 +186,7 @@ class Index
public function indexFile(File $file): void
{
try {
$this->log("Indexing file {$file->getPath()}", true);
$this->timelineWrite->processFile($file);
} catch (\Exception $e) {
$this->error("Failed to index file {$file->getPath()}: {$e->getMessage()}");
@ -263,10 +267,13 @@ class Index
}
/** Log to console if CLI */
private function log(string $message)
private function log(string $message, bool $overwrite = false)
{
if ($this->output) {
$this->output->writeln($message);
if ($overwrite) {
$this->section->clear(1);
}
$this->section->write($message);
}
}
}