From 292c0e53f8acf1f235ae3a1e7c7674381eba8cb0 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 16 Jun 2023 17:56:34 +0200 Subject: add summary of detected changes to files:scan output Signed-off-by: Robin Appelman --- apps/files/lib/Command/Scan.php | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'apps/files/lib/Command') diff --git a/apps/files/lib/Command/Scan.php b/apps/files/lib/Command/Scan.php index 6c7a607d2af..5d533899942 100644 --- a/apps/files/lib/Command/Scan.php +++ b/apps/files/lib/Command/Scan.php @@ -37,6 +37,9 @@ use OC\Core\Command\Base; use OC\Core\Command\InterruptedException; use OC\DB\Connection; use OC\DB\ConnectionAdapter; +use OCP\Files\Events\FileCacheUpdated; +use OCP\Files\Events\NodeAddedToCache; +use OCP\Files\Events\NodeRemovedFromCache; use OCP\Files\File; use OC\ForbiddenException; use OC\Metadata\MetadataManager; @@ -59,18 +62,27 @@ class Scan extends Base { protected int $foldersCounter = 0; protected int $filesCounter = 0; protected int $errorsCounter = 0; + protected int $newCounter = 0; + protected int $updatedCounter = 0; + protected int $removedCounter = 0; private IRootFolder $root; private MetadataManager $metadataManager; + private IEventDispatcher $eventDispatcher; + private LoggerInterface $logger; public function __construct( IUserManager $userManager, IRootFolder $rootFolder, - MetadataManager $metadataManager + MetadataManager $metadataManager, + IEventDispatcher $eventDispatcher, + LoggerInterface $logger ) { $this->userManager = $userManager; parent::__construct(); $this->root = $rootFolder; $this->metadataManager = $metadataManager; + $this->eventDispatcher = $eventDispatcher; + $this->logger = $logger; } protected function configure() { @@ -157,6 +169,16 @@ class Scan extends Base { ++$this->errorsCounter; }); + $this->eventDispatcher->addListener(NodeAddedToCache::class, function() { + ++$this->newCounter; + }); + $this->eventDispatcher->addListener(FileCacheUpdated::class, function() { + ++$this->updatedCounter; + }); + $this->eventDispatcher->addListener(NodeRemovedFromCache::class, function() { + ++$this->removedCounter; + }); + try { if ($backgroundScan) { $scanner->backgroundScan($path); @@ -277,9 +299,14 @@ class Scan extends Base { // Stop the timer $this->execTime += microtime(true); + $this->logger->info("Completed scan of {$this->filesCounter} files in {$this->foldersCounter} folder. Found {$this->newCounter} new, {$this->updatedCounter} updated and {$this->removedCounter} removed items"); + $headers = [ 'Folders', 'Files', + 'New', + 'Updated', + 'Removed', 'Errors', 'Elapsed time', ]; @@ -287,6 +314,9 @@ class Scan extends Base { $rows = [ $this->foldersCounter, $this->filesCounter, + $this->newCounter, + $this->updatedCounter, + $this->removedCounter, $this->errorsCounter, $niceDate, ]; -- cgit v1.2.3