Progress towards port to new spec (still not compiling)

This commit is contained in:
Nathan Fisher 2023-07-15 12:05:24 -04:00
parent 64a8269b9d
commit 1bf8fd416a
2 changed files with 33 additions and 9 deletions

View File

@ -3,15 +3,16 @@ use {
std::io::{Read, Write}, std::io::{Read, Write},
}; };
#[repr(u8)]
pub(crate) enum Flag { pub(crate) enum Flag {
Normal, Normal = 0,
HardLink, HardLink = 1,
SoftLink, SoftLink = 2,
Directory, Directory = 3,
Character, Character = 4,
Block, Block = 5,
Fifo, Fifo = 6,
Eof, Eof = 7,
} }
impl TryFrom<u8> for Flag { impl TryFrom<u8> for Flag {
@ -32,6 +33,28 @@ impl TryFrom<u8> for Flag {
} }
} }
impl From<&FileType> for Flag {
fn from(value: &FileType) -> Self {
match value {
FileType::Normal(_) => Self::Normal,
FileType::HardLink(_) => Self::HardLink,
FileType::SoftLink(_) => Self::SoftLink,
FileType::Directory => Self::Directory,
FileType::Character(_) => Self::Character,
FileType::Block(_) => Self::Block,
FileType::Fifo => Self::Fifo,
FileType::Eof => Self::Eof,
}
}
}
impl Flag {
pub(crate) fn append_mode(&self, mode: u16) -> u16 {
let mask: u16 = u16::from(*self as u8) << 13;
mode & mask
}
}
/// An enum representing the type of file of an archive member /// An enum representing the type of file of an archive member
#[derive(Debug)] #[derive(Debug)]
pub enum FileType { pub enum FileType {

View File

@ -108,11 +108,12 @@ impl Node {
let len: u16 = self.name.len().try_into()?; let len: u16 = self.name.len().try_into()?;
writer.write_all(&len.to_le_bytes())?; writer.write_all(&len.to_le_bytes())?;
writer.write_all(self.name.as_bytes())?; writer.write_all(self.name.as_bytes())?;
writer.write_all(&self.mode.to_le_bytes())?;
[self.uid, self.gid] [self.uid, self.gid]
.iter() .iter()
.try_for_each(|f| writer.write_all(&f.to_le_bytes()))?; .try_for_each(|f| writer.write_all(&f.to_le_bytes()))?;
writer.write_all(&self.mtime.to_le_bytes())?; writer.write_all(&self.mtime.to_le_bytes())?;
let mode = Flag::from(&self.filetype).append_mode(self.mode);
writer.write_all(&mode.to_le_bytes())?;
self.filetype.write(writer)?; self.filetype.write(writer)?;
Ok(()) Ok(())
} }