Fix some logic errors, use some of the read/write methods previously set

up
This commit is contained in:
Nathan Fisher 2023-07-03 18:54:44 -04:00
parent 458e572bb0
commit d69198d7f8

View File

@ -232,7 +232,7 @@ impl File {
#[repr(u8)]
#[derive(Debug)]
pub enum FileType {
Normal = 0,
Normal(File),
HardLink(String),
SoftLink(String),
Directory,
@ -246,7 +246,10 @@ impl FileType {
let mut buf = [0; 1];
reader.read_exact(&mut buf)?;
match buf[0] {
0 => Ok(Self::Normal),
0 => {
let file = File::read(reader)?;
Ok(Self::Normal(file))
},
1 => {
let mut len = [0; 8];
reader.read_exact(&mut len)?;
@ -283,7 +286,12 @@ impl FileType {
pub fn write<T: Write>(&self, writer: &mut T) -> Result<(), Error> {
match self {
Self::Normal => writer.write_all(&[0])?,
Self::Normal(f) => {
writer.write_all(&[0])?;
writer.write_all(&f.len.to_le_bytes())?;
f.checksum.write(writer)?;
writer.write_all(&f.data)?;
},
Self::HardLink(s) => {
writer.write_all(&[1])?;
let len = s.len() as u64;