1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
extern crate chrono;
extern crate crypto_hash;
extern crate serde_yaml;
extern crate walkdir;
use std::env;
use std::io;
use std::collections::BTreeMap;
use walkdir::{WalkDir, DirEntry};
mod format;
fn main() -> io::Result<()> {
for dirname in env::args().skip(1) {
let maps = WalkDir::new(&dirname)
.into_iter()
.filter_map(|e| e.ok())
.map(|e| mkmap(e));
for map in maps {
println!("{}", serde_yaml::to_string(&map).unwrap());
}
}
Ok(())
}
fn mkmap(e: DirEntry) -> BTreeMap<&'static str, String> {
let fields = vec![
("Name", format::name(&e)),
("Mtime", format::mtime(&e)),
("Mode", format::mode(&e)),
("Ino", format::inode(&e)),
("Dev", format::dev(&e)),
("Nlink", format::nlink(&e)),
("Size", format::size(&e)),
("Uid", format::uid(&e)),
("Username", format::username(&e)),
("Gid", format::gid(&e)),
("Group", format::group(&e)),
];
let mut map: BTreeMap<&str, String> =
BTreeMap::from(fields.iter().cloned().collect());
if let Ok(m) = e.metadata() {
if m.is_file() {
map.insert("SHA256", format::sha256(&e));
}
}
map
}
|