@@ -90,18 +90,19 @@ pub(crate) fn remove_or_compress_too_old_logfiles_impl(
90
90
infix_filter : & InfixFilter ,
91
91
writes_direct : bool ,
92
92
) -> Result < ( ) , std:: io:: Error > {
93
- let ( mut log_limit, compress_limit) = match * cleanup_config {
93
+ let ( mut log_limit, day_limit , compress_limit) : ( usize , usize , usize ) = match * cleanup_config {
94
94
Cleanup :: Never => {
95
95
return Ok ( ( ) ) ;
96
96
}
97
- Cleanup :: KeepLogFiles ( log_limit) => ( log_limit, 0 ) ,
97
+ Cleanup :: KeepLogFiles ( log_limit) => ( log_limit, 0 , 0 ) ,
98
98
99
- #[ cfg( feature = "compress" ) ]
100
- Cleanup :: KeepCompressedFiles ( compress_limit) => ( 0 , compress_limit) ,
99
+ Cleanup :: KeepForDays ( day_limit) => ( 0 , day_limit, 0 ) ,
101
100
101
+ #[ cfg( feature = "compress" ) ]
102
+ Cleanup :: KeepCompressedFiles ( compress_limit) => ( 0 , 0 , compress_limit) ,
102
103
#[ cfg( feature = "compress" ) ]
103
104
Cleanup :: KeepLogAndCompressedFiles ( log_limit, compress_limit) => {
104
- ( log_limit, compress_limit)
105
+ ( log_limit, 0 , compress_limit)
105
106
}
106
107
} ;
107
108
@@ -146,6 +147,20 @@ pub(crate) fn remove_or_compress_too_old_logfiles_impl(
146
147
}
147
148
}
148
149
}
150
+ } else if day_limit > 0 {
151
+ // Remove files older than the configured day limit
152
+ let mod_limit = std:: time:: SystemTime :: now ( )
153
+ . checked_sub ( std:: time:: Duration :: from_secs (
154
+ u64:: try_from ( day_limit)
155
+ . ok ( )
156
+ . and_then ( |days| days. checked_mul ( 24 * 3600 ) )
157
+ . unwrap_or ( u64:: MAX ) ,
158
+ ) )
159
+ . unwrap_or ( std:: time:: UNIX_EPOCH ) ;
160
+
161
+ if std:: fs:: metadata ( & file) ?. modified ( ) ? < mod_limit {
162
+ std:: fs:: remove_file ( & file) ?;
163
+ }
149
164
}
150
165
}
151
166
0 commit comments