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
52
53
use std::collections::BTreeMap;
use std::fs::{File, read_dir};
use std::io::{Error, ErrorKind, Result};
use std::path::Path;
use super::Sha384;
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
pub struct Manifest {
pub time: u64,
pub files: BTreeMap<String, Sha384>,
}
impl Manifest {
pub fn new<P: AsRef<Path>>(time: u64, path: P) -> Result<Manifest> {
let mut files = BTreeMap::new();
for entry_res in read_dir(path.as_ref())? {
let entry = entry_res?;
let name = entry.file_name().into_string().map_err(|_| {
Error::new(ErrorKind::InvalidData, "Filename is not UTF-8")
})?;
let file = File::open(entry.path())?;
let sha = Sha384::new(file)?;
files.insert(name, sha);
}
Ok(Manifest {
time: time,
files: files,
})
}
}