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
54
55
56
57
58
59
60
use crate::pb::FlatUnixFs;
use std::fmt;
pub(crate) fn check_directory_supported(
flat: FlatUnixFs<'_>,
) -> Result<FlatUnixFs<'_>, UnexpectedDirectoryProperties> {
let data = flat.data.Data.as_deref();
if flat.data.filesize.is_some()
|| !flat.data.blocksizes.is_empty()
|| flat.data.hashType.is_some()
|| flat.data.fanout.is_some()
|| !data.unwrap_or_default().is_empty()
{
let data = data.map(|s| s.to_vec());
Err(UnexpectedDirectoryProperties {
filesize: flat.data.filesize,
blocksizes: flat.data.blocksizes,
hash_type: flat.data.hashType,
fanout: flat.data.fanout,
data,
})
} else {
Ok(flat)
}
}
#[derive(Debug)]
pub struct UnexpectedDirectoryProperties {
filesize: Option<u64>,
blocksizes: Vec<u64>,
hash_type: Option<u64>,
fanout: Option<u64>,
data: Option<Vec<u8>>,
}
impl fmt::Display for UnexpectedDirectoryProperties {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
fmt,
"filesize={:?}, {} blocksizes, hash_type={:?}, fanout={:?}, data=[",
self.filesize,
self.blocksizes.len(),
self.hash_type,
self.fanout,
)?;
for b in self.data.as_deref().unwrap_or_default() {
write!(fmt, "{:02x}", b)?;
}
write!(fmt, "]")
}
}