Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/efi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use camino::{Utf8Path, Utf8PathBuf};
use cap_std::fs::Dir;
use cap_std_ext::cap_std;
use cap_std_ext::dirext::CapStdExtDirExt;
use chrono::prelude::*;
use fn_error_context::context;
use openat_ext::OpenatDirExt;
use os_release::OsRelease;
Expand All @@ -29,7 +28,7 @@ use crate::bootupd::RootContext;
use crate::freezethaw::fsfreeze_thaw_cycle;
use crate::model::*;
use crate::ostreeutil;
use crate::util;
use crate::util::{self, get_metadata_timestamp};
use crate::{component::*, packagesystem::*};
use crate::{filetree, grubconfigs};

Expand Down Expand Up @@ -817,10 +816,8 @@ fn generate_meta_from_usr_efi(sysroot_path: &Utf8Path) -> Result<ContentMetadata
}
modules_vec.sort_unstable();

// change to now to workaround https://github.com/coreos/bootupd/issues/933
let timestamp = std::time::SystemTime::now();
let meta = ContentMetadata {
timestamp: chrono::DateTime::<Utc>::from(timestamp),
timestamp: get_metadata_timestamp()?,
version: packages.join(","),
versions: Some(modules_vec),
};
Expand Down
24 changes: 24 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::path::Path;
use std::process::Command;

use anyhow::{bail, Context, Result};
use chrono::{DateTime, Utc};
use fn_error_context::context;
use openat_ext::OpenatDirExt;

/// Parse an environment variable as UTF-8
Expand Down Expand Up @@ -121,3 +123,25 @@ impl Drop for SignalTerminationGuard {
signal_hook_registry::unregister(self.0);
}
}

#[context("Getting timestamp for metadata")]
pub fn get_metadata_timestamp() -> Result<DateTime<Utc>> {
let ts = match std::env::var("SOURCE_DATE_EPOCH") {
Ok(value) => {
let unix_secs = value
.parse::<i64>()
.context("Parsing SOURCE_DATE_EPOCH as integer")?;

chrono::DateTime::from_timestamp_secs(unix_secs).ok_or_else(|| {
Comment thread
Johan-Liebert1 marked this conversation as resolved.
anyhow::anyhow!("SOURCE_DATE_EPOCH value '{value}' is not a valid timestamp")
})?
}
Err(std::env::VarError::NotPresent) => {
let timestamp = std::time::SystemTime::now();
chrono::DateTime::<Utc>::from(timestamp)
}
Err(e) => Err(e).context("Reading SOURCE_DATE_EPOCH")?,
};

Ok(ts)
}
Loading