Skip to main content

qubit_fs/metadata/
symlink_policy.rs

1// =============================================================================
2//    Copyright (c) 2026 Haixing Hu.
3//
4//    SPDX-License-Identifier: Apache-2.0
5//
6//    Licensed under the Apache License, Version 2.0.
7// =============================================================================
8//! Portable symbolic-link resolution policies.
9
10/// Controls whether a filesystem may resolve symbolic links while operating
11/// within its configured namespace.
12///
13/// # Examples
14///
15/// ```rust
16/// use qubit_fs::metadata::SymlinkPolicy;
17///
18/// assert!(matches!(SymlinkPolicy::Reject, SymlinkPolicy::Reject));
19/// ```
20#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
21#[must_use]
22#[non_exhaustive]
23pub enum SymlinkPolicy {
24    /// Reject an operation that requires symbolic-link resolution.
25    #[default]
26    Reject,
27    /// Follow symbolic links only when the resolved target remains inside the
28    /// configured filesystem namespace.
29    FollowWithinFileSystem,
30}
31
32impl SymlinkPolicy {
33    /// Returns whether this policy permits symbolic-link resolution.
34    #[inline]
35    #[must_use]
36    pub const fn follows(self) -> bool {
37        matches!(self, Self::FollowWithinFileSystem)
38    }
39}