]>
Commit | Line | Data |
---|---|---|
49aad941 FG |
1 | //! A crate with file-system specific utilities. |
2 | #![deny(rust_2018_idioms, missing_docs)] | |
3 | #![forbid(unsafe_code)] | |
4 | ||
781aab86 FG |
5 | use std::path::PathBuf; |
6 | ||
49aad941 FG |
7 | /// Common knowledge about the worktree that is needed across most interactions with the work tree |
8 | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | |
9 | #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)] | |
10 | pub struct Capabilities { | |
11 | /// If true, the filesystem will store paths as decomposed unicode, i.e. `ä` becomes `"a\u{308}"`, which means that | |
12 | /// we have to turn these forms back from decomposed to precomposed unicode before storing it in the index or generally | |
13 | /// using it. This also applies to input received from the command-line, so callers may have to be aware of this and | |
14 | /// perform conversions accordingly. | |
15 | /// If false, no conversions will be performed. | |
16 | pub precompose_unicode: bool, | |
17 | /// If true, the filesystem ignores the case of input, which makes `A` the same file as `a`. | |
18 | /// This is also called case-folding. | |
19 | pub ignore_case: bool, | |
20 | /// If true, we assume the executable bit is honored as part of the files mode. If false, we assume the file system | |
21 | /// ignores the executable bit, hence it will be reported as 'off' even though we just tried to set it to be on. | |
22 | pub executable_bit: bool, | |
23 | /// If true, the file system supports symbolic links and we should try to create them. Otherwise symbolic links will be checked | |
24 | /// out as files which contain the link as text. | |
25 | pub symlink: bool, | |
26 | } | |
27 | mod capabilities; | |
28 | ||
29 | mod snapshot; | |
49aad941 FG |
30 | pub use snapshot::{FileSnapshot, SharedFileSnapshot, SharedFileSnapshotMut}; |
31 | ||
32 | /// | |
33 | pub mod symlink; | |
34 | ||
35 | /// | |
36 | pub mod dir; | |
37 | ||
38 | /// A stack of path components with the delegation of side-effects as the currently set path changes, component by component. | |
39 | #[derive(Clone)] | |
40 | pub struct Stack { | |
41 | /// The prefix/root for all paths we handle. | |
42 | root: PathBuf, | |
43 | /// the most recent known cached that we know is valid. | |
44 | current: PathBuf, | |
45 | /// The relative portion of `valid` that was added previously. | |
46 | current_relative: PathBuf, | |
47 | /// The amount of path components of 'current' beyond the roots components. | |
48 | valid_components: usize, | |
49 | /// If set, we assume the `current` element is a directory to affect calls to `(push|pop)_directory()`. | |
50 | current_is_directory: bool, | |
51 | } | |
52 | ||
781aab86 FG |
53 | #[cfg(unix)] |
54 | /// Returns whether a a file has the executable permission set. | |
55 | pub fn is_executable(metadata: &std::fs::Metadata) -> bool { | |
56 | use std::os::unix::fs::MetadataExt; | |
57 | (metadata.mode() & 0o100) != 0 | |
58 | } | |
59 | ||
60 | #[cfg(not(unix))] | |
61 | /// Returns whether a a file has the executable permission set. | |
62 | pub fn is_executable(_metadata: &std::fs::Metadata) -> bool { | |
63 | false | |
64 | } | |
65 | ||
49aad941 FG |
66 | /// |
67 | pub mod stack; |