Skip to content

Instantly share code, notes, and snippets.

@jbis9051
Last active February 26, 2021 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbis9051/53890e087404d25b8bbb5dcea14ec537 to your computer and use it in GitHub Desktop.
Save jbis9051/53890e087404d25b8bbb5dcea14ec537 to your computer and use it in GitHub Desktop.
use std::{fs, env};
use std::fs::metadata;
use sha1::Sha1;
fn dir_format(dir: &str) -> String {
if let Some(s) = dir.strip_prefix("~") {
format!("{}{}", env::var("HOME").unwrap(), s)
} else {
dir.to_string()
}
}
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() < 2 {
panic!("Syntax: <dir>");
}
let dir = dir_format(&args[1]);
let bytes = match fs::read(&dir) {
Ok(str) => str,
Err(err) => panic!("{}", err)
};
let mut hash = Sha1::new();
hash.update(&bytes);
println!("{}", hash.digest());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment