Compare commits

..

10 commits

Author SHA1 Message Date
6344577a40 feat(fs): add .path(path).read_link() 2024-11-03 22:14:31 +00:00
e576e6e579 refactor(fs): PathReal owns its own data 2024-11-03 22:14:28 +00:00
10a745899d feat(fs): add .path(path).set_permissions(perms) 2024-11-03 22:14:26 +00:00
0db3bd40fe docs(fs): make it clearer what the std::fs functions map to 2024-11-03 22:14:24 +00:00
74977947d9 docs(fs): move checklist/std::fs mapping to rustdoc 2024-11-03 22:14:21 +00:00
8404b9fd8e feat(fs): add .path(path).symlink_metadata() 2024-11-03 22:14:03 +00:00
35791fe389 feat(fs): add .path(path).canonicalize()
Some checks failed
Rust / build (map[name:nightly]) (push) Failing after 41s
Rust / build (map[name:stable]) (push) Failing after 3m53s
2024-11-03 22:13:37 +00:00
c4df3d18c7 feat(fs): add .path(path).soft_link(other), .path(path).is_link()
All checks were successful
Rust / build (map[name:nightly]) (push) Successful in 2m4s
Rust / build (map[name:stable]) (push) Successful in 3m41s
Release Please / Release-plz (push) Successful in 38s
2024-11-03 22:10:34 +00:00
d3f3a9e909 feat(fs): add .path(path).metadata()
All checks were successful
Rust / build (map[name:nightly]) (push) Successful in 2m2s
Rust / build (map[name:stable]) (push) Successful in 3m41s
Release Please / Release-plz (push) Successful in 42s
2024-11-03 22:09:40 +00:00
10e6243f6e feat(fs): add .file(path).hard_link(path)
All checks were successful
Rust / build (map[name:nightly]) (push) Successful in 3m59s
Rust / build (map[name:stable]) (push) Successful in 1m45s
Release Please / Release-plz (push) Successful in 1m26s
2024-11-03 22:08:18 +00:00
2 changed files with 21 additions and 21 deletions

View file

@ -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]

View file

@ -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());