Skip to main content

fingerprint_of

Function fingerprint_of 

Source
pub fn fingerprint_of(root: &Path, paths: &[String], salt: &[&str]) -> String
Expand description

A fingerprint over a set of files: their paths, sizes and modification times.

Paths are repository-relative and the set is sorted, so the value does not depend on the order they were offered or on where the checkout lives. A file that does not exist contributes its absence, which is itself a fact worth invalidating on: deleting the justfile must expire the workflows.

use majordomus_cli::environment::cache::fingerprint_of;
let dir = tempfile::tempdir().expect("a temporary directory");
std::fs::write(dir.path().join("a"), "1").expect("a file");
let before = fingerprint_of(dir.path(), &["a".into(), "b".into()], &["salt"]);
let same = fingerprint_of(dir.path(), &["a".into(), "b".into()], &["salt"]);
assert_eq!(before, same, "the same inputs give the same fingerprint");
let salted = fingerprint_of(dir.path(), &["a".into(), "b".into()], &["other"]);
assert_ne!(before, salted, "the salt is part of it");