Skip to main content

latest

Function latest 

Source
pub fn latest(root: &Path) -> Result<PathBuf, String>
Expand description

The newest handover record of a checkout: names begin with a compact UTC timestamp, so the greatest name is the latest record.

Sorting by name rather than by modification time is deliberate — a file copied or restored keeps the moment its handover describes, which is the question being asked, and not the moment the bytes landed. Anything that is not a handover of this checkout is passed over rather than reported: a file that is not Markdown, one whose name does not begin with a timestamp, and a symbolic link out of the directory, which is how something outside the checkout would otherwise get itself published.

use majordomus_cli::mesh::handover::{directory, latest};

let root = tempfile::tempdir().unwrap();
let dir = directory(root.path());
std::fs::create_dir_all(&dir).unwrap();
assert!(latest(root.path()).is_err(), "an empty directory holds no newest record");

std::fs::write(dir.join("20260101T000000Z--a--0000000--00.md"), "---\n---\nold").unwrap();
std::fs::write(dir.join("20260915T100000Z--b--0000000--01.md"), "---\n---\nnew").unwrap();
std::fs::write(dir.join("README.md"), "not a handover").unwrap();
let newest = latest(root.path()).unwrap();
assert!(newest.ends_with("20260915T100000Z--b--0000000--01.md"));