replace mtime with birth time
This commit is contained in:
parent
bdcada4bc2
commit
e033a2fcaf
|
@ -1,6 +1,5 @@
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::os::unix::fs::MetadataExt;
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
|
@ -96,7 +95,7 @@ impl fmt::Display for Generation {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_build_time(path: &Path) -> Result<Date> {
|
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().unwrap()).date();
|
||||||
Ok(build_time)
|
Ok(build_time)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,9 +70,6 @@ pub fn setup_generation_link_from_toplevel(
|
||||||
let mut file = fs::File::create(bootspec_path)?;
|
let mut file = fs::File::create(bootspec_path)?;
|
||||||
file.write_all(&serde_json::to_vec(&bootspec)?)?;
|
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)
|
Ok(generation_link_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use expect_test::expect;
|
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
|
@ -15,6 +14,9 @@ fn generate_expected_os_release() -> Result<()> {
|
||||||
let generation_link = common::setup_generation_link(tmpdir.path(), profiles.path(), 1)
|
let generation_link = common::setup_generation_link(tmpdir.path(), profiles.path(), 1)
|
||||||
.expect("Failed to setup generation link");
|
.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().unwrap()).date();
|
||||||
|
|
||||||
let output0 = common::lanzaboote_install(0, esp_mountpoint.path(), vec![generation_link])?;
|
let output0 = common::lanzaboote_install(0, esp_mountpoint.path(), vec![generation_link])?;
|
||||||
assert!(output0.status.success());
|
assert!(output0.status.success());
|
||||||
|
|
||||||
|
@ -27,13 +29,12 @@ fn generate_expected_os_release() -> Result<()> {
|
||||||
.context("Failed to read .osrelease PE section.")?
|
.context("Failed to read .osrelease PE section.")?
|
||||||
.to_owned();
|
.to_owned();
|
||||||
|
|
||||||
let expected = expect![[r#"
|
let expected_os_release_section = format!(r#"ID=lanza
|
||||||
ID=lanza
|
PRETTY_NAME=LanzaOS
|
||||||
PRETTY_NAME=LanzaOS
|
VERSION_ID=Generation 1, Built on {}
|
||||||
VERSION_ID=Generation 1, Built on 1970-01-01
|
"#, 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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue