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)]
13#[cfg_attr(
14 feature = "serde",
15 derive(serde::Serialize),
16 serde(tag = "type", rename_all = "lowercase")
17)]
18pub enum Node {
19 /// A DirectoryNode is a pointer to a [Directory], by its [Directory::digest].
20 /// It also records a `size`.
21 /// Such a node is either an element in the [Directory] it itself is contained in,
22 /// or a standalone root node.
23 Directory {
24 /// The blake3 hash of a Directory message, serialized in protobuf canonical form.
25 digest: B3Digest,
26 /// Number of child elements in the Directory referred to by `digest`.
27 /// Calculated by summing up the numbers of nodes, and for each directory,
28 /// its size field. Can be used for inode allocation.
29 /// This field is precisely as verifiable as any other Merkle tree edge.
30 /// Resolve `digest`, and you can compute it incrementally. Resolve the entire
31 /// tree, and you can fully compute it from scratch.
32 /// A credulous implementation won't reject an excessive size, but this is
33 /// harmless: you'll have some ordinals without nodes. Undersizing is obvious
34 /// and easy to reject: you won't have an ordinal for some nodes.
35 size: u64,
36 },
37 /// A FileNode represents a regular or executable file in a Directory or at the root.
38 File {
39 /// The blake3 digest of the file contents
40 digest: B3Digest,
41
42 /// The file content size
43 size: u64,
44
45 /// Whether the file is executable
46 executable: bool,
47 },
48 /// A SymlinkNode represents a symbolic link in a Directory or at the root.
49 Symlink {
50 /// The target of the symlink.
51 target: SymlinkTarget,
52 },
53}