Skip to content

Commit

Permalink
Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tesujimath committed Jun 27, 2024
1 parent 8b70698 commit 9384625
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# real_parent

Provides a path extension method `real_parent` which is safe in the presence of symlinks.
Provides path extension methods including `real_parent` which are safe in the presence of symlinks.

Noting that `Path::parent` gives incorrect results in the presence of symlinks, `Path::canonicalize` has been used extensively to mitigate this.
This comes, however, with some ergonomic drawbacks (see below).
Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ pub trait PathExt {
/// Any symlink expansion is minimal, that is, as much as possible of the relative and
/// symlinked nature of the receiver is preserved, minimally resolving symlinks are necessary to maintain
/// physical path correctness.
/// For example, no attempt is made to fold away dotdot in the path.
/// For example, no attempt is made to fold away `..` in the path.
///
/// Differences from `Path::parent`
/// - `Path::new("..").parent() == ""`, which is incorrect, so `Path::new("..").real_parent() == "../.."`
/// - `Path::new("foo").parent() == ""`, which is not a valid path, so `Path::new("foo").real_parent() == "."`
/// - where `Path::parent()` returns `None`, `real_parent()` returns self for absolute root path, and appends `..` otherwise
fn real_parent(&self) -> io::Result<PathBuf>;

/// Return a clean path, with dotdot folded away as much as possible, and without expanding symlinks except where required
/// Return a clean path, with `.` and `..` folded away as much as possible, and without expanding symlinks except where required
/// for correctness.
fn real_clean(&self) -> io::Result<PathBuf>;

Expand Down Expand Up @@ -129,7 +129,7 @@ impl RealPath {
} else {
match path.components().last() {
None | Some(Component::ParentDir) => {
// don't attempt to fold away dotdot in the base path
// don't attempt to fold away `..` in the base path
Ok(path.join(DOTDOT).into())
}
_ => {
Expand All @@ -146,7 +146,7 @@ impl RealPath {
Ok(path.parent().unwrap().into())
}

// join paths, folding away dotdot
// join paths, folding away `..`
fn join<P1, P2>(&mut self, origin: P1, other: P2) -> Result<PathBuf, Error>
where
P1: AsRef<Path>,
Expand Down Expand Up @@ -192,7 +192,7 @@ impl RealPath {
Ok(resolving)
}

// clean a path, folding away dotdot
// clean a path, folding away `..`
fn clean<P>(&mut self, path: P) -> Result<PathBuf, Error>
where
P: AsRef<Path>,
Expand Down

0 comments on commit 9384625

Please sign in to comment.