Skip to main content

weavatrix_scan/walk_types/
entry.rs

1use super::{DirectoryIdentity, FileVersion, OsStr, Path, PathBuf, WalkEntry, WalkSkipReason};
2
3impl WalkEntry {
4    #[must_use]
5    pub fn path(&self) -> &Path {
6        &self.path
7    }
8
9    /// Consumes the entry and returns its owned path without cloning.
10    #[must_use]
11    pub fn into_path(self) -> PathBuf {
12        self.path
13    }
14
15    #[must_use]
16    pub fn relative_path(&self) -> &Path {
17        let mut components = self.path.components();
18        for _ in 0..self.root_components {
19            if components.next().is_none() {
20                return self.path.as_path();
21            }
22        }
23        components.as_path()
24    }
25
26    #[must_use]
27    pub fn file_name(&self) -> &OsStr {
28        self.path
29            .file_name()
30            .unwrap_or_else(|| self.path.as_os_str())
31    }
32
33    #[must_use]
34    pub const fn depth(&self) -> usize {
35        self.depth
36    }
37
38    #[must_use]
39    pub const fn is_file(&self) -> bool {
40        self.is_file
41    }
42
43    #[must_use]
44    pub const fn is_dir(&self) -> bool {
45        self.is_directory
46    }
47
48    #[must_use]
49    pub const fn is_symlink(&self) -> bool {
50        self.is_symlink
51    }
52
53    #[must_use]
54    pub const fn bytes(&self) -> Option<u64> {
55        self.bytes
56    }
57
58    /// Snapshot evidence captured with file metadata, when requested.
59    #[must_use]
60    pub const fn version(&self) -> Option<FileVersion> {
61        self.version
62    }
63
64    pub(crate) const fn hidden(&self) -> Option<bool> {
65        self.hidden
66    }
67
68    #[must_use]
69    pub const fn skip_reason(&self) -> Option<WalkSkipReason> {
70        self.skip_reason
71    }
72
73    pub(crate) fn rebase(&mut self, root: &Path, depth_offset: usize) {
74        self.root_components = root.components().count();
75        self.depth += depth_offset;
76    }
77
78    pub(crate) fn clear_depth_skip(&mut self) {
79        if self.skip_reason == Some(WalkSkipReason::MaxDepth) {
80            self.skip_reason = None;
81        }
82    }
83
84    pub(crate) const fn directory_identity(&self) -> Option<DirectoryIdentity> {
85        self.directory_identity
86    }
87}