@@ -29,6 +29,7 @@ def __init__(
29
29
fileext ,
30
30
encoding = "utf-8" ,
31
31
post_hook = None ,
32
+ pre_deletion_hook = None ,
32
33
fileignoreext = ".tmp" ,
33
34
** kwargs ,
34
35
):
@@ -40,6 +41,7 @@ def __init__(
40
41
self .fileext = fileext
41
42
self .fileignoreext = fileignoreext
42
43
self .post_hook = post_hook
44
+ self .pre_deletion_hook = pre_deletion_hook
43
45
44
46
@classmethod
45
47
async def discover (cls , path , ** kwargs ):
@@ -166,6 +168,9 @@ async def delete(self, href, etag):
166
168
actual_etag = get_etag_from_file (fpath )
167
169
if etag != actual_etag :
168
170
raise exceptions .WrongEtagError (etag , actual_etag )
171
+ if self .pre_deletion_hook :
172
+ self ._run_pre_deletion_hook (fpath )
173
+
169
174
os .remove (fpath )
170
175
171
176
def _run_post_hook (self , fpath ):
@@ -175,6 +180,13 @@ def _run_post_hook(self, fpath):
175
180
except OSError as e :
176
181
logger .warning (f"Error executing external hook: { str (e )} " )
177
182
183
+ def _run_pre_deletion_hook (self , fpath ):
184
+ logger .info (f"Calling pre_deletion_hook={ self .pre_deletion_hook } with argument={ fpath } " )
185
+ try :
186
+ subprocess .call ([self .pre_deletion_hook , fpath ])
187
+ except OSError as e :
188
+ logger .warning (f"Error executing external hook: { str (e )} " )
189
+
178
190
async def get_meta (self , key ):
179
191
fpath = os .path .join (self .path , key )
180
192
try :
0 commit comments