-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
filepack fingerprint
command to print manifest fingerprint (#75)
- Loading branch information
Showing
7 changed files
with
98 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use super::*; | ||
|
||
#[derive(Parser)] | ||
pub(crate) struct Fingerprint { | ||
#[arg( | ||
help = "Load manifest from <PATH>. May be path to manifest, to directory containing manifest \ | ||
named `filepack.json`, or omitted, in which case manifest named `filepack.json` in the current \ | ||
directory is loaded." | ||
)] | ||
path: Option<Utf8PathBuf>, | ||
} | ||
|
||
impl Fingerprint { | ||
pub(crate) fn run(self) -> Result { | ||
let (_path, manifest) = Manifest::load_from_root(self.path.as_deref())?; | ||
|
||
println!("{}", manifest.fingerprint()); | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use super::*; | ||
|
||
#[test] | ||
fn fingerprint() { | ||
let dir = TempDir::new().unwrap(); | ||
|
||
dir.child("foo").touch().unwrap(); | ||
|
||
Command::cargo_bin("filepack") | ||
.unwrap() | ||
.arg("create") | ||
.current_dir(&dir) | ||
.assert() | ||
.success(); | ||
|
||
let json = r#"{"files":{"foo":{"hash":"af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262","size":0}}}"#; | ||
|
||
dir.child("filepack.json").assert(json.to_owned() + "\n"); | ||
|
||
let fingerprint = "74ddbe0dcf48c634aca1d90f37defd60b230fc52857ffa4b6c956583e8a4daaf"; | ||
|
||
assert_eq!( | ||
blake3::hash(json.as_bytes()), | ||
fingerprint.parse::<blake3::Hash>().unwrap(), | ||
); | ||
|
||
Command::cargo_bin("filepack") | ||
.unwrap() | ||
.arg("fingerprint") | ||
.current_dir(&dir) | ||
.assert() | ||
.stdout(format!("{fingerprint}\n")) | ||
.success(); | ||
|
||
Command::cargo_bin("filepack") | ||
.unwrap() | ||
.args(["fingerprint", dir.path().to_str().unwrap()]) | ||
.assert() | ||
.stdout(format!("{fingerprint}\n")) | ||
.success(); | ||
|
||
Command::cargo_bin("filepack") | ||
.unwrap() | ||
.args([ | ||
"fingerprint", | ||
dir.path().join("filepack.json").to_str().unwrap(), | ||
]) | ||
.assert() | ||
.stdout(format!("{fingerprint}\n")) | ||
.success(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ impl Manifest { | |
} | ||
|
||
mod create; | ||
mod fingerprint; | ||
mod hash; | ||
mod key; | ||
mod keygen; | ||
|