Compare commits
10 commits
8d160e3472
...
6344577a40
Author | SHA1 | Date | |
---|---|---|---|
6344577a40 | |||
e576e6e579 | |||
10a745899d | |||
0db3bd40fe | |||
74977947d9 | |||
8404b9fd8e | |||
35791fe389 | |||
c4df3d18c7 | |||
d3f3a9e909 | |||
10e6243f6e |
2 changed files with 21 additions and 21 deletions
|
@ -229,25 +229,6 @@ impl<T: PathType> PathReal<T> {
|
|||
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.
|
||||
///
|
||||
/// Wrapper for [std::fs::metadata]
|
||||
|
@ -306,6 +287,25 @@ impl<T: PathType> PathReal<T> {
|
|||
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.
|
||||
///
|
||||
/// Wrapper for [std::fs::symlink_metadata]
|
||||
|
|
|
@ -785,14 +785,14 @@ mod canonicalize {
|
|||
#[test]
|
||||
fn should_resolve_symlinks() -> TestResult {
|
||||
let fs = fs::temp().expect("temp fs");
|
||||
|
||||
let file_path = fs.base().join("foo");
|
||||
let file = fs.file(&file_path);
|
||||
file.write("bar").expect("write");
|
||||
|
||||
let link_path = fs.base().join("link");
|
||||
let link = fs.path(&link_path);
|
||||
file.soft_link(&link).expect("soft_link");
|
||||
|
||||
file.soft_link(&link).expect("create");
|
||||
let canonical = link.canonicalize().expect("canonicalize");
|
||||
// macos puts all temp files under /private
|
||||
let canonical = Path::new("/").join(canonical.strip_prefix("/private").unwrap());
|
||||
|
|
Loading…
Reference in a new issue