pub struct DirTree {
pub files: Vec<(String, Checksum)>,
pub dirs: Vec<(String, Checksum, Checksum)>,
}Expand description
An owned dirtree object: the lists of child files and subdirectories.
§Wire form
The GVariant type is (a(say)a(sayay)). It holds two lists:
- the file entries
(say): the name and the checksum of the content object - the directory entries
(sayay): the name, the checksum of the dirtree object, and the checksum of the dirmeta object
Each checksum is a raw 32-byte ay.
§Rules
- Each list is sorted by name in byte-wise order. A name occurs at most once in a list. The sort order makes the checksum of a tree reproducible.
- Each name is one path component, as
check_namestates. - No name is in both lists, because the two entries have the same checkout path.
serialize and parse check all three
rules. DirTreeRef checks the first two rules only.
Fields§
§files: Vec<(String, Checksum)>The file entries: the name and the content checksum, sorted by name.
dirs: Vec<(String, Checksum, Checksum)>The directory entries, sorted by name.
Each entry holds the name, the dirtree checksum, and the dirmeta checksum.
Implementations§
Source§impl DirTree
impl DirTree
Sourcepub fn check_name(name: &str) -> Result<()>
pub fn check_name(name: &str) -> Result<()>
Checks that name is one path component.
A valid name is not empty, is not . or .., and holds no /. This
check is the defense against path traversal through a dirtree entry.
The string decoder of the read path refuses a name that is not UTF-8.
§Errors
Error::InvalidDirTree with one of these reasons:
"empty entry name"ifnameis empty"entry name is a directory traversal"ifnameis.or.."entry name contains a slash"ifnameholds a/
Sourcepub fn parse(data: &[u8]) -> Result<DirTree>
pub fn parse(data: &[u8]) -> Result<DirTree>
Parses a serialized dirtree object into an owned tree.
The parse checks each entry when it collects the lists, as
DirTreeRef::to_owned does. Then it checks that no name is in both
lists. A tree that this function returns obeys all
rules.
§Errors
Error::Gvariantifdatais not a normal-form value of type(a(say)a(sayay)).Error::InvalidDirTreeif an entry breaks a rule. These are the reasons:- a reason of
check_nameif a name is not one path component "entry names are not sorted"if a name does not sort strictly after the previous name of its list"entry checksum is not 32 bytes"if a checksum has a different length"a name appears in both the file and directory lists"if a name is in both lists
- a reason of
Sourcepub fn serialize(&self) -> Result<Vec<u8>>
pub fn serialize(&self) -> Result<Vec<u8>>
Serializes the tree to normal-form bytes.
The SHA-256 of these bytes is the checksum of the dirtree object.
§Errors
Error::InvalidDirTreeif the tree breaks a rule. These are the reasons:- a reason of
check_nameif a name is not one path component "entry names are not sorted"if a name does not sort strictly after the previous name of its list"a name appears in both the file and directory lists"if a name is in both lists
- a reason of
Error::GvariantwithInvalidValueif a name holds a NUL byte.
Trait Implementations§
impl Eq for DirTree
Source§impl GvEncode for DirTree
The encoder writes the two lists as they are and checks no
rule. DirTree::serialize checks the rules before it
encodes.
impl GvEncode for DirTree
The encoder writes the two lists as they are and checks no
rule. DirTree::serialize checks the rules before it
encodes.