diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 6f7ca8fd..40253a71 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -7,7 +7,7 @@ use OC\Files\Filesystem; use OCA\GDataVaas\AvirWrapper; use OCA\GDataVaas\Service\VerdictService; -use OCA\GDataVaas\EventListener; +use OCA\GDataVaas\CacheEntryListener; use OCP\Activity\IManager; use OCP\App\IAppManager; use OCP\AppFramework\App; @@ -50,7 +50,7 @@ public function register(IRegistrationContext $context): void { require_once $composerAutoloadFile; } - EventListener::register($context); + CacheEntryListener::register($context); // Util::connection is deprecated, but required ATM by FileSystem::addStorageWrapper Util::connectHook('OC_Filesystem', 'preSetup', $this, 'setupWrapper'); diff --git a/lib/EventListener.php b/lib/CacheEntryListener.php similarity index 93% rename from lib/EventListener.php rename to lib/CacheEntryListener.php index a0363f27..15df297c 100644 --- a/lib/EventListener.php +++ b/lib/CacheEntryListener.php @@ -12,7 +12,7 @@ use OCP\Files\Cache\CacheEntryUpdatedEvent; use Psr\Log\LoggerInterface; -class EventListener implements IEventListener +class CacheEntryListener implements IEventListener { private LoggerInterface $logger; @@ -28,8 +28,8 @@ public function __construct(LoggerInterface $logger, TagService $tagService, Ver } public static function register(IRegistrationContext $context): void { - $context->registerEventListener(CacheEntryInsertedEvent::class, EventListener::class); - $context->registerEventListener(CacheEntryUpdatedEvent::class, EventListener::class); + $context->registerEventListener(CacheEntryInsertedEvent::class, CacheEntryListener::class); + $context->registerEventListener(CacheEntryUpdatedEvent::class, CacheEntryListener::class); } public function handle(Event $event): void diff --git a/lib/Service/VerdictService.php b/lib/Service/VerdictService.php index f6433354..c3a8f9f0 100644 --- a/lib/Service/VerdictService.php +++ b/lib/Service/VerdictService.php @@ -129,12 +129,23 @@ private function tagFile(int $fileId, string $tagName) { } } - public static function isFileTooLargeToScan($path) { + /** + * Checks if a file is too large to be scanned. + * @param string $path + * @return bool + */ + public static function isFileTooLargeToScan(string $path): bool { $size = filesize($path); return !$size || $size > self::MAX_FILE_SIZE; } - public function scan(string $filePath): VaasVerdict { + + /** + * Scans a file for malicious content with G DATA Verdict-as-a-Service and returns the verdict. + * @param string $filePath The local path to the file to scan. + * @return VaasVerdict The verdict. + */ + public function scan(string $filePath): VaasVerdict { $this->lastLocalPath = $filePath; $this->lastVaasVerdict = null; @@ -155,14 +166,27 @@ public function scan(string $filePath): VaasVerdict { } } - public function onRename(string $localSource, string $localTarget) + /** + * Call this from a StorageWrapper, when a local file was renamed. This allows the scanner to track the name + * of the file that was scanned last. + * @param string $localSource The local source path. + * @param string $localTarget The local destination path. + */ + public function onRename(string $localSource, string $localTarget): void { if ($localSource === $this->lastLocalPath) { $this->lastLocalPath = $localTarget; } } - public function tagLastScannedFile(string $localPath, int $fileId) { + + /** + * Tag the file that was scanned last with it's verdict. Call this from an EventListener on CacheEntryInsertedEvent or + * CacheEntryUpdatedEvent. + * @param string $localPath The local path. + * @param int $fileId The corresponding file id to tag. + */ + public function tagLastScannedFile(string $localPath, int $fileId): void { if (self::isFileTooLargeToScan($localPath)) { $this->tagFile($fileId, TagService::WONT_SCAN); return;