aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2017-05-26 13:17:14 -0700
committerbnewbold <bnewbold@robocracy.org>2017-05-26 13:17:14 -0700
commita2ca6a70cc0511f02dfffb29e298bf188d445836 (patch)
treea9a43f52a50bbc99ad9e2361e2e6a8b5a0297b17
parent0294cfc029ca3402c1070165a6c585fc56b3f199 (diff)
downloadbad-hashish-a2ca6a70cc0511f02dfffb29e298bf188d445836.tar.gz
bad-hashish-a2ca6a70cc0511f02dfffb29e298bf188d445836.zip
some cleanups/lint
-rw-r--r--src/bin/bhash.rs20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/bin/bhash.rs b/src/bin/bhash.rs
index 691db2a..b5d2937 100644
--- a/src/bin/bhash.rs
+++ b/src/bin/bhash.rs
@@ -16,7 +16,7 @@ extern crate crypto;
use clap::App;
use bad_hashish::Result;
use std::path::Path;
-use std::io::{self, BufReader};
+use std::io::BufReader;
use std::io::prelude::*;
use std::fs::File;
use flate2::read::GzDecoder;
@@ -38,24 +38,28 @@ fn run() -> Result<()> {
println!("{} ({})", f, tree_magic::from_filepath(path));
if tree_magic::match_filepath("application/zip", path) {
- println!("It's a zip.");
+ //println!("It's a zip.");
} else if tree_magic::match_filepath("application/gzip", path) {
- println!("It's gzip.");
+ //println!("It's gzip.");
let f = File::open(path)?;
- let mut gz = GzDecoder::new(f)?;
+ let gz = GzDecoder::new(f)?;
let mut reader = BufReader::with_capacity(4*1024*1024, gz);
let is_tar: bool = {
let buf = reader.fill_buf()?;
- println!("Inside is: {}", tree_magic::from_u8(&buf));
+ //println!("Inside is: {}", tree_magic::from_u8(&buf));
tree_magic::match_u8("application/x-tar", &buf)
};
if is_tar {
- println!("It's a tar inside");
+ //println!("It's a tar inside");
let mut a = Archive::new(reader);
for inner in a.entries().unwrap() {
let mut inner = inner.unwrap();
+ // Only do actual files ("regular", not directories, fifo, etc)
+ if inner.header().entry_type() != tar::EntryType::Regular {
+ continue;
+ }
let mut hasher = Sha1::new();
let mut buf: [u8; 1*1024*1024] = [0; 1*1024*1024];
loop {
@@ -63,7 +67,9 @@ fn run() -> Result<()> {
if got <= 0 { break };
hasher.input(&buf[0..got]);
}
- println!("\t{} {:?}", hasher.result_str(), inner.header().path().unwrap());
+ println!("{} {}",
+ hasher.result_str(),
+ inner.header().path()?.to_str().unwrap());
}
}
}