From d69198d7f83f4f0026ae527d907d3bca4ead3867 Mon Sep 17 00:00:00 2001 From: Nathan Fisher Date: Mon, 3 Jul 2023 18:54:44 -0400 Subject: [PATCH] Fix some logic errors, use some of the read/write methods previously set up --- src/lib.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e32435d..7326e73 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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(&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;