-
-
Save jbis9051/53890e087404d25b8bbb5dcea14ec537 to your computer and use it in GitHub Desktop.
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
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