FileSystem hooks don't fire


Hello fellow developers!

I'm developing an app and struggling with how filesystem hooks are used.

From what I read in the documentation and Github issues I can listen to events using three different methods.

I tried the method described in the documentation and it worked well for session events (user login/logout etc.) but filesystem events are not emitted.

In my Application.php I register three services: LogService which is responsible for writing to a log destination, FileHooks which contains the code for registering hooks for filesystem events and SessionHooks which contains the same code but for the session events. While SessionHooks 's is registered properly, FileHooks 's constructor is not called for some reason.

I also added <filesystem/> to the <types> container in info.xml which I read somewhere is neccessary for filesystem events to be emitted.

I then tried the apparently old method for registering hooks via \OCP\Util::connectHook() with no success either.

I'd really appreciate if someone could look through the code and tell me if I'm missing something!!

I uploaded a ZIP archive containing the code here:

Thanks in advance & have a nice evening :wink:

@patrickjahns you had a similar issue at the conf, how did you solve it ?

1 Like

Initially, it was a problem with not defining the proper application type as <filesystem/>.

I am using the following code to register a hook:

		$container = $this->getContainer();
		$rootfolder = $container->query('OCP\\Files\\IRootFolder');
		$rootfolder->listen('\OC\Files', 'postDelete', function(Node $node) use ($container) {

See here:

Will have a quick look at the app on the weekend

Thanks for the quick reponses, @PVince81 and @patrickjahns !

I wrongly used \OCP\Files to listen upon, but now that I changed it to $this->root->listen('\OC\Files', 'postWrite', $callbackPostWrite); it still doesn't work :confused:


Can you check oc_appconfig database table if the type listed for your application actually says filesystem ?

If it's not listed as filesystem, do a version bump of your application, run occ upgrade and it should be listed as filesystem. (And the hooks should fire).

1 Like

Thanks :heart:, @patrickjahns, that did the trick!