aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/files/lib/Command/Scan.php32
-rw-r--r--lib/private/Files/Cache/Scanner.php2
-rw-r--r--lib/private/Files/Utils/Scanner.php8
3 files changed, 38 insertions, 4 deletions
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,
];
diff --git a/lib/private/Files/Cache/Scanner.php b/lib/private/Files/Cache/Scanner.php
index 6734a62db80..52268032409 100644
--- a/lib/private/Files/Cache/Scanner.php
+++ b/lib/private/Files/Cache/Scanner.php
@@ -291,7 +291,7 @@ class Scanner extends BasicEmitter implements IScanner {
$data['permissions'] = $data['scan_permissions'];
}
\OC_Hook::emit('Scanner', 'addToCache', ['file' => $path, 'data' => $data]);
- $this->emit('\OC\Files\Cache\Scanner', 'addToCache', [$path, $this->storageId, $data]);
+ $this->emit('\OC\Files\Cache\Scanner', 'addToCache', [$path, $this->storageId, $data, $fileId]);
if ($this->cacheActive) {
if ($fileId !== -1) {
$this->cache->update($fileId, $data);
diff --git a/lib/private/Files/Utils/Scanner.php b/lib/private/Files/Utils/Scanner.php
index 277ce38175f..b7f6972ee10 100644
--- a/lib/private/Files/Utils/Scanner.php
+++ b/lib/private/Files/Utils/Scanner.php
@@ -251,9 +251,13 @@ class Scanner extends PublicEmitter {
$this->postProcessEntry($storage, $path);
$this->dispatcher->dispatchTyped(new FileCacheUpdated($storage, $path));
});
- $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) {
+ $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path, $storageId, $data, $fileId) use ($storage) {
$this->postProcessEntry($storage, $path);
- $this->dispatcher->dispatchTyped(new NodeAddedToCache($storage, $path));
+ if ($fileId) {
+ $this->dispatcher->dispatchTyped(new FileCacheUpdated($storage, $path));
+ } else {
+ $this->dispatcher->dispatchTyped(new NodeAddedToCache($storage, $path));
+ }
});
if (!$storage->file_exists($relativePath)) {