parent
86c3c260a1
commit
a9b0f463a1
|
@ -33,7 +33,6 @@ use OCP\IUserManager;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\ConsoleSectionOutput;
|
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
class IndexOpts
|
class IndexOpts
|
||||||
|
@ -66,7 +65,6 @@ class Index extends Command
|
||||||
// IO
|
// IO
|
||||||
private InputInterface $input;
|
private InputInterface $input;
|
||||||
private OutputInterface $output;
|
private OutputInterface $output;
|
||||||
private ConsoleSectionOutput $outputSection;
|
|
||||||
|
|
||||||
// Command options
|
// Command options
|
||||||
private IndexOpts $opts;
|
private IndexOpts $opts;
|
||||||
|
@ -105,7 +103,10 @@ class Index extends Command
|
||||||
$this->input = $input;
|
$this->input = $input;
|
||||||
$this->output = $output;
|
$this->output = $output;
|
||||||
$this->opts = new IndexOpts($input);
|
$this->opts = new IndexOpts($input);
|
||||||
|
|
||||||
|
// Assign to indexer
|
||||||
$this->indexer->output = $output;
|
$this->indexer->output = $output;
|
||||||
|
$this->indexer->section = $output->section();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Use static exiftool process
|
// Use static exiftool process
|
||||||
|
|
|
@ -52,30 +52,18 @@ class PostWriteListener implements IEventListener
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if a directory at a higher level contains a .nomedia file
|
// 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 {
|
try {
|
||||||
$parent = $node->getParent();
|
$parent = $node;
|
||||||
while ($parent) {
|
while ($parent = $parent->getParent()) {
|
||||||
$parents[] = $parent;
|
if ($parent->nodeExists('.nomedia')) {
|
||||||
$parent = $parent->getParent();
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (\OCP\Files\NotFoundException $e) {
|
} catch (\OCP\Files\NotFoundException $e) {
|
||||||
// This happens when the parent is in the root directory
|
// This happens when the parent is in the root directory
|
||||||
// and getParent() is called on it.
|
// 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);
|
$this->timelineWrite->processFile($node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,11 +35,13 @@ use OCP\IDBConnection;
|
||||||
use OCP\IPreview;
|
use OCP\IPreview;
|
||||||
use OCP\ITempManager;
|
use OCP\ITempManager;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Symfony\Component\Console\Output\ConsoleSectionOutput;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
class Index
|
class Index
|
||||||
{
|
{
|
||||||
public ?OutputInterface $output;
|
public ?OutputInterface $output;
|
||||||
|
public ?ConsoleSectionOutput $section;
|
||||||
|
|
||||||
protected IRootFolder $rootFolder;
|
protected IRootFolder $rootFolder;
|
||||||
protected TimelineWrite $timelineWrite;
|
protected TimelineWrite $timelineWrite;
|
||||||
|
@ -112,8 +114,9 @@ class Index
|
||||||
*/
|
*/
|
||||||
public function indexFolder(Folder $folder): void
|
public function indexFolder(Folder $folder): void
|
||||||
{
|
{
|
||||||
// Respect the '.nomedia' file. If present don't traverse the folder
|
|
||||||
if ($folder->nodeExists('.nomedia')) {
|
if ($folder->nodeExists('.nomedia')) {
|
||||||
|
$this->log("Skipping folder {$folder->getPath()} due to .nomedia file\n", true);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,6 +186,7 @@ class Index
|
||||||
public function indexFile(File $file): void
|
public function indexFile(File $file): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
$this->log("Indexing file {$file->getPath()}", true);
|
||||||
$this->timelineWrite->processFile($file);
|
$this->timelineWrite->processFile($file);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->error("Failed to index file {$file->getPath()}: {$e->getMessage()}");
|
$this->error("Failed to index file {$file->getPath()}: {$e->getMessage()}");
|
||||||
|
@ -263,10 +267,13 @@ class Index
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Log to console if CLI */
|
/** Log to console if CLI */
|
||||||
private function log(string $message)
|
private function log(string $message, bool $overwrite = false)
|
||||||
{
|
{
|
||||||
if ($this->output) {
|
if ($this->output) {
|
||||||
$this->output->writeln($message);
|
if ($overwrite) {
|
||||||
|
$this->section->clear(1);
|
||||||
|
}
|
||||||
|
$this->section->write($message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue