Expand description
A crate with file-system specific utilities.
File-opening helpers such as open_read_only_no_follow() and Unicode-aware read_dir()
are available without enabling any features. The read helper returns FileOrSymlink so callers
can choose whether to skip or reject symlinks without platform-specific handling.
§Examples
use std::path::{Path, PathBuf};
use gix_fs::{
stack::{Delegate, ToNormalPathComponents},
Stack,
};
let components = "src/lib.rs"
.to_normal_path_components()
.collect::<Result<Vec<_>, _>>()?;
assert_eq!(
components
.into_iter()
.map(|component| component.to_string_lossy().into_owned())
.collect::<Vec<_>>(),
vec!["src", "lib.rs"]
);
#[derive(Default)]
struct Recorder {
directories: Vec<PathBuf>,
paths: Vec<PathBuf>,
}
impl Delegate for Recorder {
fn push_directory(&mut self, stack: &Stack) -> std::io::Result<()> {
self.directories.push(stack.current_relative().to_path_buf());
Ok(())
}
fn push(&mut self, _is_last_component: bool, stack: &Stack) -> std::io::Result<()> {
self.paths.push(stack.current_relative().to_path_buf());
Ok(())
}
fn pop_directory(&mut self) {}
}
let capabilities = gix_fs::Capabilities::probe_dir(dir.path());
let mut stack = Stack::new(dir.path().to_path_buf());
let mut recorder = Recorder::default();
stack.make_relative_path_current("src/lib.rs", &mut recorder)?;
assert_eq!(stack.current_relative(), Path::new("src/lib.rs"));
assert_eq!(recorder.directories[0], Path::new(""));
assert_eq!(recorder.paths, vec![PathBuf::from("src"), PathBuf::from("src/lib.rs")]);
assert_eq!(gix_fs::current_dir(capabilities.precompose_unicode)?, std::env::current_dir()?);§Feature Flags
serde—Capabilitiesimplementsserde::Serializeandserde::Deserialize.walkdir— Enable recursive directory traversal with optional Unicode precomposition and Git-style sorting using thewalkdircrate.
Re-exports§
pub use walkdir::WalkDir;walkdirpub use walkdir::walkdir_new;walkdirpub use walkdir::walkdir_sorted_new;walkdir
Modules§
- dir
- io_err
- Classifiers for IO-errors.
- read_
dir - Directory entries with optional Unicode precomposition.
- stack
- symlink
- walkdir
walkdir - Recursive directory traversal with optional Unicode precomposition and Git-style sorting.
Structs§
- Capabilities
- Common knowledge about the worktree that is needed across most interactions with the work tree
- File
Snapshot - A structure holding enough information to reload a value if its on-disk representation changes as determined by its modified time.
- Shared
File Snapshot Mut - Use this type for fields in structs that are to store the
FileSnapshot, typically behind anOwnShared. - Stack
- A stack of path components with the delegation of side-effects as the currently set path changes, component by component.
Enums§
- File
OrSymlink - The outcome of
open_read_only_no_follow().
Functions§
- adjust_
shared_ repository_ permissions - Adjust
permissionsaccording to Git’s shared-repository permission policy. - clear_
readonly_ attribute - Clear the Windows read-only attribute at
path, following symbolic links to their targets. - current_
dir - Like
std::env::current_dir(), but it willprecompose_unicodeif that value is true, if the current directory is valid unicode and if there are decomposed unicode codepoints. - is_
executable Unix - Returns whether a file has the executable permission set.
- open_
options_ no_ follow - Prepare open options which won’t follow a symlink in the final path component on Unix or Windows.
- open_
read_ only_ no_ follow - Open
pathfor reading without following a symlink in its final component on Unix or Windows. - read_
dir - List all entries in
path, similar tostd::fs::read_dir(), and assure all available information adheres to the value ofprecompose_unicode. - set_
shared_ repository_ permissions - Apply the parsed Git sharing policy to an existing entry at
path, following symbolic links.
Type Aliases§
- Shared
File Snapshot - A snapshot of a resource which is up-to-date in the moment it is retrieved.