Compare commits

..

No commits in common. "c1c0ea22dec69273523d3dd4c38efd616b9038d1" and "3be53a969dd73684c5bce69a5bbe02ce2b73e17b" have entirely different histories.

4 changed files with 5 additions and 45 deletions

View file

@ -4,7 +4,7 @@ Provides injectable Filesystem and Network resources to make code more testable.
#### std::fs alternatives
- [x] `std::fs::canonicalize` - `path(path).canonicalize()` - Returns the canonical, absolute form of a path with all intermediate components normalized and symbolic links resolved.
- [ ] `std::fs::canonicalize` - `path(path).canonicalize()` - Returns the canonical, absolute form of a path with all intermediate components normalized and symbolic links resolved.
- [ ] `std::fs::copy` - `file(path).copy(target)` - Copies the contents of one file to another. This function will also copy the permission bits of the original file to the destination file.
- [x] `std::fs::create_dir` - `dir(path).create()` - Creates a new, empty directory at the provided path
- [x] `std::fs::create_dir_all` - `dir(path).create_all()` - Recursively create a directory and all of its parent components if they are missing.

View file

@ -3,10 +3,10 @@ use crate::fs::{DirItem, DirItemIterator, Result};
use super::{
path::{DirMarker, PathReal},
DirHandle, Error, FileMarker, PathMarker,
Error, FileMarker, PathMarker,
};
impl<'base, 'path> DirHandle<'base, 'path> {
impl<'base, 'path> PathReal<'base, 'path, DirMarker> {
/// Creates a new, empty directory at the path
///
/// Wrapper for [std::fs::create_dir]

View file

@ -4,10 +4,10 @@ use crate::fs::Result;
use super::{
path::{FileMarker, PathReal},
reader::Reader,
Error, FileHandle,
Error,
};
impl<'base, 'path> FileHandle<'base, 'path> {
impl<'base, 'path> PathReal<'base, 'path, FileMarker> {
/// Returns a [Reader] for the file.
///
/// ```
@ -41,25 +41,4 @@ impl<'base, 'path> FileHandle<'base, 'path> {
self.check_error()?;
std::fs::write(self.as_pathbuf(), contents).map_err(Error::Io)
}
/// Copies the contents of a file to another file.
///
/// Wrapper for [std::fs::copy]
///
/// ```
/// # fn try_main() -> kxio::fs::Result<()> {
/// let fs = kxio::fs::temp()?;
/// let src_path = fs.base().join("foo");
/// let dest_path = fs.base().join("bar");
/// let src = fs.file(&src_path);
/// # fs.file(&dest_path).write("new file contents")?;
/// let dest = fs.file(&dest_path);
/// src.copy(&dest)?;
/// # Ok(())
/// # }
/// ```
pub fn copy(&self, dest: &PathReal<'base, 'path, FileMarker>) -> Result<u64> {
self.check_error()?;
std::fs::copy(self.as_pathbuf(), dest.as_pathbuf()).map_err(Error::Io)
}
}

View file

@ -201,25 +201,6 @@ impl<'base, 'path, T: PathType> PathReal<'base, 'path, T> {
Ok(None)
}
}
/// 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)
}
}
impl From<PathReal<'_, '_, PathMarker>> for PathBuf {
fn from(path: PathReal<PathMarker>) -> Self {