11# This file is part of Radicale - CalDAV and CardDAV server
22# Copyright © 2014 Jean-Marc Martins
33# Copyright © 2012-2017 Guillaume Ayoub
4- # Copyright © 2017-2019 Unrud <unrud@outlook.com>
4+ # Copyright © 2017-2022 Unrud <unrud@outlook.com>
5+ # Copyright © 2023-2025 Peter Bieringer <pb@bieringer.de>
56#
67# This library is free software: you can redistribute it and/or modify
78# it under the terms of the GNU General Public License as published by
@@ -58,7 +59,7 @@ def __init__(self, configuration: config.Configuration) -> None:
5859 self ._hook = configuration .get ("storage" , "hook" )
5960
6061 @types .contextmanager
61- def acquire_lock (self , mode : str , user : str = "" ) -> Iterator [None ]:
62+ def acquire_lock (self , mode : str , user : str = "" , * args , ** kwargs ) -> Iterator [None ]:
6263 with self ._lock .acquire (mode ):
6364 yield
6465 # execute hook
@@ -73,8 +74,17 @@ def acquire_lock(self, mode: str, user: str = "") -> Iterator[None]:
7374 else :
7475 # Process group is also used to identify child processes
7576 preexec_fn = os .setpgrp
76- command = self ._hook % {
77- "user" : shlex .quote (user or "Anonymous" )}
77+ # optional argument
78+ path = kwargs .get ('path' , "" )
79+ try :
80+ command = self ._hook % {
81+ "path" : shlex .quote (self ._get_collection_root_folder () + path ),
82+ "cwd" : shlex .quote (self ._filesystem_folder ),
83+ "user" : shlex .quote (user or "Anonymous" )}
84+ except KeyError as e :
85+ logger .error ("Storage hook contains not supported placeholder %s (skip execution of: %r)" % (e , self ._hook ))
86+ return
87+
7888 logger .debug ("Executing storage hook: '%s'" % command )
7989 try :
8090 p = subprocess .Popen (
0 commit comments