@@ -86,7 +86,7 @@ def stat(x):
86
86
return collected , collected_paths
87
87
88
88
class FileDeleter (object ):
89
- def __init__ (self , top , thresholds , report_directory , log , fake = True , app_tag = "fff_deleter" ):
89
+ def __init__ (self , top , thresholds , report_directory , log , fake = True , skip_latest = False , app_tag = "fff_deleter" ):
90
90
self .top = top
91
91
self .fake = fake
92
92
self .thresholds = thresholds
@@ -95,6 +95,7 @@ def __init__(self, top, thresholds, report_directory, log, fake=True, app_tag="f
95
95
self .app_tag = app_tag
96
96
self .log = log
97
97
self .delay_seconds = 30
98
+ self .skip_latest = skip_latest
98
99
99
100
self .hostname = socket .gethostname ()
100
101
@@ -121,7 +122,7 @@ def rename(self, f):
121
122
122
123
return fn
123
124
124
- def delete (self , f ):
125
+ def overwrite (self , f ):
125
126
if not f .endswith (".deleted" ):
126
127
return f
127
128
@@ -137,7 +138,7 @@ def delete(self, f):
137
138
138
139
return f
139
140
140
- def unlink (self , f , json = False ):
141
+ def delete (self , f , json = False ):
141
142
if not f .endswith (".deleted" ):
142
143
return f
143
144
@@ -205,6 +206,8 @@ def do_the_cleanup(self):
205
206
collected , collected_paths = collect (self .top , self .log )
206
207
self .log .info ("Done file collection, took %.03fs." , time .time () - start )
207
208
209
+ latest_run = collected [- 1 ][0 ][0 ]
210
+
208
211
file_count = len (collected )
209
212
210
213
# stopSizeDelete can still be positive after this
@@ -214,14 +217,15 @@ def do_the_cleanup(self):
214
217
start_cleanup = time .time ()
215
218
for entry in collected :
216
219
sort_key , fp , fsize , ftime = entry
220
+ if self .skip_latest and latest_run == sort_key : continue # do not want to
217
221
218
222
# unlink file and json older than 2 days
219
223
# this has no effect on thresholds, but affects performance
220
224
age = start - ftime
221
225
if fsize == 0 and age >= 2 * 24 * 60 * 60 and fp .endswith (".deleted" ):
222
226
# remove empty and old files
223
227
# no one uses them anymore...
224
- self .unlink (fp , json = True )
228
+ self .delete (fp , json = True )
225
229
226
230
if stopSizeRename <= 0 :
227
231
break
@@ -230,11 +234,11 @@ def do_the_cleanup(self):
230
234
stopSizeRename -= fsize
231
235
232
236
if fp .endswith (".deleted" ) and stopSizeDelete > 0 :
233
- # delete the files which have been previously marked
237
+ # overwrite the files which have been previously marked with dummy
234
238
# and we have disk over-usage
235
239
stopSizeDelete -= fsize
236
240
237
- self .delete (fp )
241
+ self .overwrite (fp )
238
242
elif fp .endswith (".deleted" ):
239
243
# already renamed, do nothing
240
244
pass
@@ -244,6 +248,7 @@ def do_the_cleanup(self):
244
248
245
249
if self .thresholds .has_key ("delete_folders" ) and self .thresholds ["delete_folders" ]:
246
250
for entry in collected_paths :
251
+ if self .skip_latest and str (latest_run ) in entry .path : continue
247
252
248
253
# check if empty - we don't non-empty dirs
249
254
# empty as in a 'no stream files left to truncate' sense
0 commit comments