@@ -18,7 +18,7 @@ use std::sync::Arc;
1818
1919pub struct AuditLogCleanup {
2020 datastore : Arc < DataStore > ,
21- retention_days : NonZeroU32 ,
21+ retention : TimeDelta ,
2222 max_deleted_per_activation : u32 ,
2323}
2424
@@ -28,21 +28,25 @@ impl AuditLogCleanup {
2828 retention_days : NonZeroU32 ,
2929 max_deleted_per_activation : u32 ,
3030 ) -> Self {
31- Self { datastore, retention_days, max_deleted_per_activation }
31+ let retention =
32+ TimeDelta :: try_days ( i64:: from ( retention_days. get ( ) ) ) . expect (
33+ "retention_days must be representable as a TimeDelta" ,
34+ ) ;
35+ Self { datastore, retention, max_deleted_per_activation }
3236 }
3337
3438 pub ( crate ) async fn actually_activate (
3539 & mut self ,
3640 opctx : & OpContext ,
3741 ) -> AuditLogCleanupStatus {
38- let cutoff = TimeDelta :: try_days ( i64 :: from ( self . retention_days . get ( ) ) )
39- . and_then ( |d| Utc :: now ( ) . checked_sub_signed ( d ) ) ;
40- let cutoff = match cutoff {
42+ // retention was validated at construction time; only the
43+ // subtraction from "now" can fail (effectively impossible).
44+ let cutoff = match Utc :: now ( ) . checked_sub_signed ( self . retention ) {
4145 Some ( c) => c,
4246 None => {
4347 let msg = format ! (
44- "retention_days { } overflows date arithmetic" ,
45- self . retention_days ,
48+ "retention {:? } overflows date arithmetic" ,
49+ self . retention ,
4650 ) ;
4751 slog:: error!( & opctx. log, "{msg}" ) ;
4852 return AuditLogCleanupStatus {
0 commit comments