A way to cancel an action who precede a hook

Hello everybody,

I'm trying to develop an app who can check the number of files inside directories of the user.
I'm using Hooks for checking the number of files before the write action, but now when the number of files is too high, I need to cancel the write action.
How can I do that ? I was looking at the documentation, but I didn't find any relative information.
It seems that the write action after my hooks can be cancelled by generating an error but I really don't think this is a good way.
I'm actually working on Owncloud 9.2.


Try setting $run to 0 in the hook handler.

Best would be to use a storage wrapper instead, see how the quota storage wrapper works: https://github.com/owncloud/core/blob/master/lib/private/Files/Storage/Wrapper/Quota.php#L30.
Registration works this way: https://github.com/owncloud/core/blob/master/lib/private/legacy/util.php#L185.
To register from within an app, do it in the presetup hook as shown in this old app: https://github.com/owncloud/files_locking/blob/master/appinfo/app.php#L3 and https://github.com/owncloud/files_locking/blob/master/lib/lockingwrapper.php#L199.
Then from fopen or file_put_contents you can throw an exception to block upload.


I used storage wrapper and it worked fine, thanks to you :).
I am actually trying to get the uploaded file size, but I don't know if it's possible to get it using this method.
Do you have any tips ?

Thank you