3131 MaxFileSize int64
3232 MaxFileAge time.Duration
3333
34+ MinAge time.Duration
35+
3436 MaxTotalSize int64
3537 MaxTotalAge time.Duration
3638 MaxTotalFiles int // including current
@@ -65,20 +67,26 @@ const (
6567 TB = 1e12
6668)
6769
68- var (
69- // SubstPattern = "XXXX"
70- // TimeFormat = "2006-01-02_15-04"
70+ // SubstPattern = "XXXX"
71+ // TimeFormat = "2006-01-02_15-04"
7172
72- patterns = []string {"xxx" , "XXX" , "ddd" }
73- )
73+ var patterns = []string {"xxx" , "XXX" , "ddd" }
7474
7575func Create (name string ) (f * File ) {
76+ const day = 24 * time .Hour
77+
7678 f = & File {
7779 name : name ,
7880
79- MaxFileSize : 128 * MiB ,
80- MaxTotalAge : 28 * 24 * time .Hour ,
81- MaxTotalFiles : 10 ,
81+ MaxFileSize : 128 * MiB ,
82+ MaxFileAge : 7 * day ,
83+
84+ MinAge : 3 * day ,
85+
86+ MaxTotalSize : 128 * GiB ,
87+ MaxTotalAge : 28 * day ,
88+
89+ MaxTotalFiles : 20 ,
8290
8391 // SubstPattern: SubstPattern,
8492 // TimeFormat: TimeFormat,
@@ -271,14 +279,9 @@ func (f *File) filesToRemove(dir, base string, now time.Time, files []string) ([
271279 files = files [:p ]
272280 size := int64 (0 )
273281
274- for p > 0 {
282+ for ; p > 0 ; p -- {
275283 prev := p - 1
276284
277- if f .MaxTotalFiles != 0 && len (files )- prev + 1 > f .MaxTotalFiles {
278- // tlog.Printw("remove files", "reason", "max_total_files", "x", len(files)-prev, "of", f.MaxTotalFiles, "files", files[:p])
279- break
280- }
281-
282285 n := filepath .Join (dir , files [prev ])
283286
284287 inf , err := f .fstat (n )
@@ -293,12 +296,19 @@ func (f *File) filesToRemove(dir, base string, now time.Time, files []string) ([
293296 break
294297 }
295298
299+ if f .MinAge != 0 && now .Sub (ctime (inf , time.Time {})) <= f .MinAge {
300+ continue
301+ }
302+
296303 if f .MaxTotalAge != 0 && now .Sub (ctime (inf , now )) > f .MaxTotalAge {
297304 // tlog.Printw("remove files", "reason", "max_total_age", "total_age", now.Sub(ctime(inf, now)), "of", f.MaxTotalAge, "files", files[:p])
298305 break
299306 }
300307
301- p --
308+ if f .MaxTotalFiles != 0 && len (files )- prev + 1 > f .MaxTotalFiles {
309+ // tlog.Printw("remove files", "reason", "max_total_files", "x", len(files)-prev, "of", f.MaxTotalFiles, "files", files[:p])
310+ break
311+ }
302312 }
303313
304314 return files [:p ], nil
0 commit comments