2023-01-03 14:20:35 +00:00
|
|
|
use super::{ReadExt, Version};
|
|
|
|
|
2023-01-06 19:54:48 +00:00
|
|
|
#[derive(Debug)]
|
2023-01-03 14:20:35 +00:00
|
|
|
pub enum Index {
|
|
|
|
WithoutPathHash(IndexV1),
|
2023-01-06 19:54:48 +00:00
|
|
|
WithPathHash,
|
2023-01-03 14:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Index {
|
|
|
|
pub fn new<R: std::io::Read>(reader: &mut R, version: &Version) -> Result<Self, super::Error> {
|
|
|
|
Ok(match version < &Version::PathHashIndex {
|
|
|
|
true => Index::WithoutPathHash(IndexV1::new(reader, version)?),
|
2023-01-06 19:54:48 +00:00
|
|
|
false => Index::WithPathHash,
|
2023-01-03 14:20:35 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-06 19:54:48 +00:00
|
|
|
#[derive(Debug)]
|
2023-01-03 14:20:35 +00:00
|
|
|
pub struct IndexV1 {
|
|
|
|
pub mount_point: String,
|
|
|
|
pub entries: Vec<super::Entry>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl IndexV1 {
|
|
|
|
pub fn new<R: std::io::Read>(
|
|
|
|
reader: &mut R,
|
|
|
|
version: &super::Version,
|
|
|
|
) -> Result<Self, super::Error> {
|
|
|
|
Ok(Self {
|
|
|
|
mount_point: reader.read_string()?,
|
|
|
|
entries: reader.read_array(|reader| super::Entry::new(reader, version))?,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct IndexV2 {}
|