mirror of
https://github.com/deuxfleurs-org/garage.git
synced 2026-08-10 06:26:52 +00:00
lifecycle config: store date as given, try to debug
This commit is contained in:
@@ -105,7 +105,7 @@ mod v08 {
|
||||
/// Objects expire x days after they were created
|
||||
AfterDays(usize),
|
||||
/// Objects expire at date x (must be in yyyy-mm-dd format)
|
||||
AtDate(chrono::naive::NaiveDate),
|
||||
AtDate(String),
|
||||
}
|
||||
|
||||
#[derive(Default, PartialEq, Eq, PartialOrd, Ord, Clone, Debug, Serialize, Deserialize)]
|
||||
@@ -155,6 +155,20 @@ impl Crdt for BucketParams {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_lifecycle_date(date: &str) -> Result<chrono::NaiveDate, &'static str> {
|
||||
use chrono::prelude::*;
|
||||
|
||||
if let Ok(datetime) = NaiveDateTime::parse_from_str(date, "%Y-%m-%dT%H:%M:%SZ") {
|
||||
if datetime.time() == NaiveTime::MIN {
|
||||
Ok(datetime.date())
|
||||
} else {
|
||||
Err("date must be at midnight")
|
||||
}
|
||||
} else {
|
||||
NaiveDate::parse_from_str(date, "%Y-%m-%d").map_err(|_| "date has invalid format")
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Bucket {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
|
||||
@@ -268,7 +268,14 @@ async fn process_object(
|
||||
LifecycleExpiration::AfterDays(n_days) => {
|
||||
(now_date - version_date) >= chrono::Duration::days(*n_days as i64)
|
||||
}
|
||||
LifecycleExpiration::AtDate(exp_date) => now_date >= *exp_date,
|
||||
LifecycleExpiration::AtDate(exp_date) => {
|
||||
if let Ok(exp_date) = parse_lifecycle_date(&exp_date) {
|
||||
now_date >= exp_date
|
||||
} else {
|
||||
warn!("Invalid expiraiton date stored in bucket {:?} lifecycle config: {}", bucket.id, exp_date);
|
||||
false
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if size_match && date_match {
|
||||
|
||||
Reference in New Issue
Block a user