Compare commits
10 commits
6344577a40
...
8d160e3472
Author | SHA1 | Date | |
---|---|---|---|
8d160e3472 | |||
5aa2b96a9c | |||
bfc3333f81 | |||
2748efd40b | |||
0f535ca997 | |||
4b4e60c92c | |||
c59aacd4bc | |||
66a0219ba3 | |||
19754d5796 | |||
3989d269a6 |
2 changed files with 21 additions and 21 deletions
|
@ -229,6 +229,25 @@ impl<T: PathType> PathReal<T> {
|
||||||
std::fs::rename(self.as_pathbuf(), dest.as_pathbuf()).map_err(Error::Io)
|
std::fs::rename(self.as_pathbuf(), dest.as_pathbuf()).map_err(Error::Io)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the canonical, absolute form of the path with all intermediate
|
||||||
|
/// components normalized and symbolic links resolved.
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use kxio::fs::Result;
|
||||||
|
/// # fn main() -> Result<()> {
|
||||||
|
/// let fs = kxio::fs::temp()?;
|
||||||
|
/// let path = fs.base().join("foo");
|
||||||
|
/// # fs.dir(&path).create()?;
|
||||||
|
/// let dir = fs.path(&path);
|
||||||
|
/// let canonical = dir.canonicalize()?;
|
||||||
|
/// # Ok(())
|
||||||
|
/// # }
|
||||||
|
/// ```
|
||||||
|
pub fn canonicalize(&self) -> Result<PathBuf> {
|
||||||
|
self.check_error()?;
|
||||||
|
self.as_pathbuf().canonicalize().map_err(Error::Io)
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the metadata for a path.
|
/// Returns the metadata for a path.
|
||||||
///
|
///
|
||||||
/// Wrapper for [std::fs::metadata]
|
/// Wrapper for [std::fs::metadata]
|
||||||
|
@ -287,25 +306,6 @@ impl<T: PathType> PathReal<T> {
|
||||||
Ok(self.as_pathbuf().is_symlink())
|
Ok(self.as_pathbuf().is_symlink())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the canonical, absolute form of the path with all intermediate
|
|
||||||
/// components normalized and symbolic links resolved.
|
|
||||||
///
|
|
||||||
/// ```
|
|
||||||
/// # use kxio::fs::Result;
|
|
||||||
/// # fn main() -> Result<()> {
|
|
||||||
/// let fs = kxio::fs::temp()?;
|
|
||||||
/// let path = fs.base().join("foo");
|
|
||||||
/// # fs.dir(&path).create()?;
|
|
||||||
/// let dir = fs.path(&path);
|
|
||||||
/// let canonical = dir.canonicalize()?;
|
|
||||||
/// # Ok(())
|
|
||||||
/// # }
|
|
||||||
/// ```
|
|
||||||
pub fn canonicalize(&self) -> Result<PathBuf> {
|
|
||||||
self.check_error()?;
|
|
||||||
self.as_pathbuf().canonicalize().map_err(Error::Io)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the metadata for a path without following symlinks.
|
/// Returns the metadata for a path without following symlinks.
|
||||||
///
|
///
|
||||||
/// Wrapper for [std::fs::symlink_metadata]
|
/// Wrapper for [std::fs::symlink_metadata]
|
||||||
|
|
|
@ -785,14 +785,14 @@ mod canonicalize {
|
||||||
#[test]
|
#[test]
|
||||||
fn should_resolve_symlinks() -> TestResult {
|
fn should_resolve_symlinks() -> TestResult {
|
||||||
let fs = fs::temp().expect("temp fs");
|
let fs = fs::temp().expect("temp fs");
|
||||||
|
|
||||||
let file_path = fs.base().join("foo");
|
let file_path = fs.base().join("foo");
|
||||||
let file = fs.file(&file_path);
|
let file = fs.file(&file_path);
|
||||||
file.write("bar").expect("write");
|
file.write("bar").expect("write");
|
||||||
|
|
||||||
let link_path = fs.base().join("link");
|
let link_path = fs.base().join("link");
|
||||||
let link = fs.path(&link_path);
|
let link = fs.path(&link_path);
|
||||||
file.soft_link(&link).expect("create");
|
file.soft_link(&link).expect("soft_link");
|
||||||
|
|
||||||
let canonical = link.canonicalize().expect("canonicalize");
|
let canonical = link.canonicalize().expect("canonicalize");
|
||||||
// macos puts all temp files under /private
|
// macos puts all temp files under /private
|
||||||
let canonical = Path::new("/").join(canonical.strip_prefix("/private").unwrap());
|
let canonical = Path::new("/").join(canonical.strip_prefix("/private").unwrap());
|
||||||
|
|
Loading…
Reference in a new issue