snix_castore/nodes/mod.rs
1//! This holds types describing nodes in the snix-castore model.
2mod directory;
3mod symlink_target;
4
5use crate::B3Digest;
6pub use directory::Directory;
7pub use symlink_target::{SymlinkTarget, SymlinkTargetError};
8
9/// A Node is either a directory, file or symlink.
10/// Nodes themselves don't have names, what gives them names is either them
11/// being inside a [Directory], or a root node with a name attached adjacently.
12#[derive(Debug, Clone, PartialEq, Eq)]
13pub enum Node {
14 /// A DirectoryNode is a pointer to a [Directory], by its [Directory::digest].
15 /// It also records a`size`.
16 /// Such a node is either an element in the [Directory] it itself is contained in,
17 /// or a standalone root node.
18 Directory {
19 /// The blake3 hash of a Directory message, serialized in protobuf canonical form.
20 digest: B3Digest,
21 /// Number of child elements in the Directory referred to by `digest`.
22 /// Calculated by summing up the numbers of nodes, and for each directory,
23 /// its size field. Can be used for inode allocation.
24 /// This field is precisely as verifiable as any other Merkle tree edge.
25 /// Resolve `digest`, and you can compute it incrementally. Resolve the entire
26 /// tree, and you can fully compute it from scratch.
27 /// A credulous implementation won't reject an excessive size, but this is
28 /// harmless: you'll have some ordinals without nodes. Undersizing is obvious
29 /// and easy to reject: you won't have an ordinal for some nodes.
30 size: u64,
31 },
32 /// A FileNode represents a regular or executable file in a Directory or at the root.
33 File {
34 /// The blake3 digest of the file contents
35 digest: B3Digest,
36
37 /// The file content size
38 size: u64,
39
40 /// Whether the file is executable
41 executable: bool,
42 },
43 /// A SymlinkNode represents a symbolic link in a Directory or at the root.
44 Symlink {
45 /// The target of the symlink.
46 target: SymlinkTarget,
47 },
48}