Skip to content

Commit

Permalink
147 scan on update via events (#160)
Browse files Browse the repository at this point in the history
* switch to event driven scanning to properly handle scanning on client and UI uploads, updates or changes of files

* make debugging and the devcontainer work again

---------

Co-authored-by: PT-ATA No One <[email protected]>
Co-authored-by: Lennart Dohmann <[email protected]>
  • Loading branch information
3 people authored Nov 25, 2024
1 parent cd80b83 commit 2b73060
Show file tree
Hide file tree
Showing 17 changed files with 308 additions and 425 deletions.
6 changes: 4 additions & 2 deletions .devcontainer/postCreateCommands.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

bash -i -c 'nvm install 20'
bash -i -c 'nvm use 20'

echo "setup php-scoper"
composer global require humbug/php-scoper
$(composer config home)/vendor/bin/php-scoper completion bash >> $HOME.bash_completion
Expand All @@ -22,10 +25,9 @@ echo ". /usr/share/bash-completion/bash_completion" >> /home/vscode/.bashrc
NEXTCLOUD_VERSION=$(grep -oP -m 1 "[0-9]+\.[0-9]+\.[0-9]+" install.sh)

mkdir -p ~/.ssh/
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts

rm -rf nextcloud-server/
git clone --depth 1 --recurse-submodules --single-branch --branch v$NEXTCLOUD_VERSION git@github.com:nextcloud/server.git ./nextcloud-server
git clone --depth 1 --recurse-submodules --single-branch --branch v$NEXTCLOUD_VERSION https://github.com/nextcloud/server.git ./nextcloud-server
cd nextcloud-server
git submodule update --init
cd -
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"port": 9080,
"pathMappings": {
"/var/www/html/": "${workspaceFolder}/nextcloud-server",
"/var/www/html/apps/gdatavaas": "${workspaceFolder}/",
"/var/www/html/apps/gdatavaas": "${workspaceFolder}/build/artifacts/gdatavaas",
},
"runtimeArgs": [
"-dxdebug.mode=debug",
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
"[php]": {
"editor.defaultFormatter": "junstyle.php-cs-fixer"
},
"php.suggest.basic": false
}
6 changes: 2 additions & 4 deletions Dockerfile.Nextcloud
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ RUN echo "error_log = /var/www/html/data/php.log" >> "$PHP_INI_DIR/php.ini"
RUN sed -i 's/#LogLevel info ssl:warn/LogLevel debug/g' /etc/apache2/sites-available/000-default.conf

COPY xdebug.ini /tmp/xdebug.ini
RUN if [[ "$INSTALL_XDEBUG" == "1" ]]; then \
install-php-extensions gd xdebug; \
mv /tmp/xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
fi
RUN install-php-extensions gd xdebug;
RUN mv /tmp/xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini;

1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"autoload": {
"psr-4": {
"OCP\\": "vendor/nextcloud/ocp/OCP",
"OCA\\Files_Trashbin\\": "nextcloud-server/apps/files_trashbin",
"OCA\\GDataVaas\\": "lib"
}
},
Expand Down
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -e

export NEXTCLOUD_VERSION=${1:-30.0.0}
export NEXTCLOUD_VERSION=${1:-30.0.2}
export INSTALL_XDEBUG=${2:-1}
export XDEBUG_MODE=${XDEBUG_MODE:-develop}

Expand Down
63 changes: 6 additions & 57 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,16 @@

namespace OCA\GDataVaas\AppInfo;

use OC\Files\Filesystem;
use OCA\GDataVaas\AvirWrapper;
use OCA\GDataVaas\CacheEntryListener;
use OCA\GDataVaas\Db\DbFileMapper;
use OCA\GDataVaas\Service\MailService;
use OCA\GDataVaas\EventListener\FileEventsListener;
use OCA\GDataVaas\Service\TagService;
use OCA\GDataVaas\Service\VerdictService;
use OCA\GDataVaas\SystemTag\SystemTagObjectMapperWithoutActivityFactory;
use OCP\Activity\IManager;
use OCP\App\IAppManager;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\IHomeStorage;
use OCP\Files\Storage\IStorage;
use OCP\IAppConfig;
use OCP\IDBConnection;
use OCP\SystemTag\ISystemTagManager;
use OCP\SystemTag\ISystemTagObjectMapper;
Expand All @@ -43,6 +34,7 @@ public function __construct() {

$container = $this->getContainer();
$eventDispatcher = $container->get(IEventDispatcher::class);
assert($eventDispatcher instanceof IEventDispatcher);
$eventDispatcher->addListener(LoadAdditionalScriptsEvent::class, function () {
Util::addScript(self::APP_ID, 'gdatavaas-files-action');
});
Expand All @@ -53,9 +45,9 @@ public function __construct() {
* @return void
*/
public function register(IRegistrationContext $context): void {
require_once file_exists(__DIR__.'/../../vendor/scoper-autoload.php')
? __DIR__.'/../../vendor/scoper-autoload.php'
: __DIR__.'/../../vendor/autoload.php';
require_once file_exists(__DIR__ . '/../../vendor/scoper-autoload.php')
? __DIR__ . '/../../vendor/scoper-autoload.php'
: __DIR__ . '/../../vendor/autoload.php';

// Manually register TagService so that we can customize the DI used for $silentTagMapper
$context->registerService(TagService::class, function ($c) {
Expand All @@ -69,50 +61,7 @@ public function register(IRegistrationContext $context): void {
return new TagService($logger, $systemTagManager, $standardTagMapper, $silentTagMapper, $dbFileMapper);
}, true);

CacheEntryListener::register($context);

// Util::connection is deprecated, but required ATM by FileSystem::addStorageWrapper
Util::connectHook('OC_Filesystem', 'preSetup', $this, 'setupWrapper');
}

/**
* * Add wrapper for local storages
*/
public function setupWrapper(): void {
Filesystem::addStorageWrapper(
'oc_gdata_vaas',
function (string $mountPoint, IStorage $storage) {
/*
if ($storage->instanceOfStorage(Jail::class)) {
// No reason to wrap jails again
return $storage;
}
*/

$container = $this->getContainer();
$verdictService = $container->get(VerdictService::class);
$mailService = $container->get(MailService::class);
$appConfig = $container->get(IAppConfig::class);
// $l10n = $container->get(IL10N::class);
$logger = $container->get(LoggerInterface::class);
$activityManager = $container->get(IManager::class);
$eventDispatcher = $container->get(IEventDispatcher::class);
$appManager = $container->get(IAppManager::class);
return new AvirWrapper([
'storage' => $storage,
'verdictService' => $verdictService,
'mailService' => $mailService,
'appConfig' => $appConfig,
//'l10n' => $l10n,
'logger' => $logger,
'activityManager' => $activityManager,
'isHomeStorage' => $storage->instanceOfStorage(IHomeStorage::class),
'eventDispatcher' => $eventDispatcher,
'trashEnabled' => $appManager->isEnabledForUser('files_trashbin'),
]);
},
1
);
FileEventsListener::register($context);
}

public function boot(IBootContext $context): void {
Expand Down
Loading

0 comments on commit 2b73060

Please sign in to comment.