1use std::convert::TryInto;
2
3use crate::{entry, Entry, State};
4
5impl Entry {
6 pub fn write_to(&self, mut out: impl std::io::Write, state: &State) -> std::io::Result<()> {
8 let stat = self.stat;
9 out.write_all(&stat.ctime.secs.to_be_bytes())?;
10 out.write_all(&stat.ctime.nsecs.to_be_bytes())?;
11 out.write_all(&stat.mtime.secs.to_be_bytes())?;
12 out.write_all(&stat.mtime.nsecs.to_be_bytes())?;
13 out.write_all(&stat.dev.to_be_bytes())?;
14 out.write_all(&stat.ino.to_be_bytes())?;
15 out.write_all(&self.mode.bits().to_be_bytes())?;
16 out.write_all(&stat.uid.to_be_bytes())?;
17 out.write_all(&stat.gid.to_be_bytes())?;
18 out.write_all(&stat.size.to_be_bytes())?;
19 out.write_all(self.id.as_bytes())?;
20 let path = self.path(state);
21 let path_len: u16 = if path.len() >= entry::Flags::PATH_LEN.bits() as usize {
22 entry::Flags::PATH_LEN.bits() as u16
23 } else {
24 path.len()
25 .try_into()
26 .expect("we just checked that the length is smaller than 0xfff")
27 };
28 out.write_all(&(self.flags.to_storage().bits() | path_len).to_be_bytes())?;
29 if self.flags.contains(entry::Flags::EXTENDED) {
30 out.write_all(
31 &entry::at_rest::FlagsExtended::from_flags(self.flags)
32 .bits()
33 .to_be_bytes(),
34 )?;
35 }
36 out.write_all(path)?;
37 out.write_all(b"\0")
38 }
39}