Merge pull request #139 from adtya/built_on_date
Use birth time instead of modify time for generation "built on" date
This commit is contained in:
commit
d751d13b0a
|
@ -1,6 +1,5 @@
|
|||
use std::fmt;
|
||||
use std::fs;
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
|
@ -96,7 +95,7 @@ impl fmt::Display for Generation {
|
|||
}
|
||||
|
||||
fn read_build_time(path: &Path) -> Result<Date> {
|
||||
let build_time = time::OffsetDateTime::from_unix_timestamp(fs::metadata(path)?.mtime())?.date();
|
||||
let build_time = time::OffsetDateTime::from(fs::metadata(path)?.created()?).date();
|
||||
Ok(build_time)
|
||||
}
|
||||
|
||||
|
|
|
@ -70,9 +70,6 @@ pub fn setup_generation_link_from_toplevel(
|
|||
let mut file = fs::File::create(bootspec_path)?;
|
||||
file.write_all(&serde_json::to_vec(&bootspec)?)?;
|
||||
|
||||
// Explicitly set modification time so that snapshot test of os-release reliably works.
|
||||
// This has to happen after any modifications to the directory.
|
||||
filetime::set_file_mtime(&generation_link_path, filetime::FileTime::zero())?;
|
||||
Ok(generation_link_path)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use std::fs;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use expect_test::expect;
|
||||
use tempfile::tempdir;
|
||||
|
||||
mod common;
|
||||
|
@ -15,6 +14,9 @@ fn generate_expected_os_release() -> Result<()> {
|
|||
let generation_link = common::setup_generation_link(tmpdir.path(), profiles.path(), 1)
|
||||
.expect("Failed to setup generation link");
|
||||
|
||||
// Expect the 'Built on' date in VERSION_ID to be from the birth time of generation_link
|
||||
let expected_built_on = time::OffsetDateTime::from(fs::metadata(generation_link.as_path())?.created()?).date();
|
||||
|
||||
let output0 = common::lanzaboote_install(0, esp_mountpoint.path(), vec![generation_link])?;
|
||||
assert!(output0.status.success());
|
||||
|
||||
|
@ -27,13 +29,12 @@ fn generate_expected_os_release() -> Result<()> {
|
|||
.context("Failed to read .osrelease PE section.")?
|
||||
.to_owned();
|
||||
|
||||
let expected = expect![[r#"
|
||||
ID=lanza
|
||||
PRETTY_NAME=LanzaOS
|
||||
VERSION_ID=Generation 1, Built on 1970-01-01
|
||||
"#]];
|
||||
let expected_os_release_section = format!(r#"ID=lanza
|
||||
PRETTY_NAME=LanzaOS
|
||||
VERSION_ID=Generation 1, Built on {}
|
||||
"#, expected_built_on.to_string());
|
||||
|
||||
expected.assert_eq(&String::from_utf8(os_release_section)?);
|
||||
assert_eq!(&expected_os_release_section, &String::from_utf8(os_release_section)?);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue