summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: ea3704087ff1aafdcea9597fffc708bc5c4f6bd3 (plain)
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
use std::env;
use std::io;
use std::collections::BTreeMap;

extern crate walkdir;
use walkdir::{WalkDir, DirEntry};

extern crate chrono;
extern crate crypto_hash;
extern crate serde_yaml;

mod format;


fn main() -> io::Result<()> {
    for dirname in env::args().skip(1) {
        for e in WalkDir::new(&dirname).into_iter().filter_map(|e| e.ok()) {
            let map = mkmap(&e);
            println!("{}", serde_yaml::to_string(&map).unwrap());
        }
    }
    Ok(())
}


fn mkmap(e: &DirEntry) -> BTreeMap<&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
}