about summary refs log tree commit diff
path: root/tvix/castore/src/nodes/symlink_node.rs
blob: 6b9df96a5dd3f34141b0defda6ebb1b5f9cc5310 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use crate::ValidateNodeError;

/// A SymlinkNode represents a symbolic link in a Directory or at the root.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SymlinkNode {
    /// The target of the symlink.
    target: bytes::Bytes,
}

impl SymlinkNode {
    pub fn new(target: bytes::Bytes) -> Result<Self, ValidateNodeError> {
        if target.is_empty() || target.contains(&b'\0') {
            return Err(ValidateNodeError::InvalidSymlinkTarget(target));
        }
        Ok(Self { target })
    }

    pub fn target(&self) -> &bytes::Bytes {
        &self.target
    }
}