snix_castore/fs/
inodes.rs

1//! This module contains all the data structures used to track information
2//! about inodes, which present snix-castore nodes in a filesystem.
3use crate::{B3Digest, Node, path::PathComponent};
4
5#[derive(Clone, Debug)]
6pub enum InodeData {
7    Regular(B3Digest, u64, bool),  // digest, size, executable
8    Symlink(bytes::Bytes),         // target
9    Directory(DirectoryInodeData), // either [DirectoryInodeData:Sparse] or [DirectoryInodeData:Populated]
10}
11
12/// This encodes the two different states of [InodeData::Directory].
13/// Either the data still is sparse (we only saw a [crate::Node::Directory],
14/// but didn't fetch the [crate::Directory] struct yet, or we processed a
15/// lookup and did fetch the data.
16#[derive(Clone, Debug)]
17pub enum DirectoryInodeData {
18    Sparse(B3Digest, u64),                                // digest, size
19    Populated(B3Digest, Vec<(u64, PathComponent, Node)>), // [(child_inode, name, node)]
20}
21
22impl InodeData {
23    /// Constructs a new InodeData from a `&Node`.
24    pub fn from_node(node: &Node) -> Self {
25        match node {
26            Node::Directory { digest, size } => {
27                Self::Directory(DirectoryInodeData::Sparse(*digest, *size))
28            }
29            Node::File {
30                digest,
31                size,
32                executable,
33            } => Self::Regular(*digest, *size, *executable),
34            Node::Symlink { target } => Self::Symlink(target.clone().into()),
35        }
36    }
37}