During node creation, don't attempt to get size from metadata, which can
be wildly off on zfs filesystems
This commit is contained in:
parent
3b46b11153
commit
3483bf155b
21
src/node.rs
21
src/node.rs
@ -170,9 +170,8 @@ impl Node {
|
|||||||
} else if kind == Kind::Pipe {
|
} else if kind == Kind::Pipe {
|
||||||
break 'blk FileType::Fifo;
|
break 'blk FileType::Fifo;
|
||||||
} else if kind == Kind::Normal {
|
} else if kind == Kind::Normal {
|
||||||
let mut len = meta.len();
|
let mut data = vec![];
|
||||||
let mut data = Vec::with_capacity(len.try_into()?);
|
let len = reader.read_to_end(&mut data)?.try_into()?;
|
||||||
len = reader.read_to_end(&mut data)?.try_into()?;
|
|
||||||
let checksum = match algorithm {
|
let checksum = match algorithm {
|
||||||
Algorithm::Md5 => {
|
Algorithm::Md5 => {
|
||||||
let mut hasher = Md5::new();
|
let mut hasher = Md5::new();
|
||||||
@ -319,9 +318,13 @@ mod tests {
|
|||||||
fn from_path() {
|
fn from_path() {
|
||||||
let links = Mutex::new(HashMap::new());
|
let links = Mutex::new(HashMap::new());
|
||||||
let node = Node::from_path("test/li.txt", Algorithm::Sha256, &links).unwrap();
|
let node = Node::from_path("test/li.txt", Algorithm::Sha256, &links).unwrap();
|
||||||
let FileType::Normal(f) = node.filetype else { panic!() };
|
let FileType::Normal(f) = node.filetype else {
|
||||||
|
panic!()
|
||||||
|
};
|
||||||
assert_eq!(f.len, 1005);
|
assert_eq!(f.len, 1005);
|
||||||
let Checksum::Sha256(sum) = f.checksum else { panic!() };
|
let Checksum::Sha256(sum) = f.checksum else {
|
||||||
|
panic!()
|
||||||
|
};
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
for c in &sum {
|
for c in &sum {
|
||||||
write!(s, "{c:02x}").unwrap();
|
write!(s, "{c:02x}").unwrap();
|
||||||
@ -344,8 +347,12 @@ mod tests {
|
|||||||
let fd = std::fs::File::open("test/li.node").unwrap();
|
let fd = std::fs::File::open("test/li.node").unwrap();
|
||||||
let mut reader = BufReader::new(fd);
|
let mut reader = BufReader::new(fd);
|
||||||
let node = Node::read(&mut reader).unwrap();
|
let node = Node::read(&mut reader).unwrap();
|
||||||
let FileType::Normal(f) = node.filetype else { panic!() };
|
let FileType::Normal(f) = node.filetype else {
|
||||||
let Checksum::Sha1(sum) = f.checksum else { panic!() };
|
panic!()
|
||||||
|
};
|
||||||
|
let Checksum::Sha1(sum) = f.checksum else {
|
||||||
|
panic!()
|
||||||
|
};
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
for c in &sum {
|
for c in &sum {
|
||||||
write!(s, "{c:02x}").unwrap();
|
write!(s, "{c:02x}").unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user