Skip to content

Commit 03338d2

Browse files
committed
initial commit
0 parents  commit 03338d2

File tree

5 files changed

+402
-0
lines changed

5 files changed

+402
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
/target/
3+
**/*.rs.bk
4+
Cargo.lock

Cargo.toml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "ergo_fs"
3+
version = "0.1.0"
4+
authors = ["Garrett Berg <[email protected]>"]
5+
6+
[dependencies]
7+
tar = "^0.4.14"
8+
tempdir = "^0.3.5"
9+
walkdir = "^2.0.1"
10+
path_Abs = "^0.3.0"
11+
lockfile = "*"

notes.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Open a ticket to WalkDir to pretify their `From<Error> for io::Error` implementation.

src/lib.rs

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
//! ergo_fs: types for making working with the filesystem ergonomic, therefore fun.
2+
//!
3+
//! This crate provides a minimal set of common types and methods for working with the filesystem.
4+
//! These types aim to provide:
5+
//!
6+
//! - Descriptive error messages
7+
//! - Good performance, but not necessarily at _all_ costs.
8+
//! - As much type safety as is possible when dealing with the filesystem, which can change at any
9+
//! time.
10+
//!
11+
//! The crates it wraps/rexports are:
12+
//! - [`path_abs`](https://github.com/vitiral/path_abs): Ergonomic paths and files in rust.
13+
//! - [`tar-rs`](https://github.com/alexcrichton/tar-rs): A library for reading and writing TAR
14+
//! archives.
15+
//! - [`tempdir`](https://github.com/rust-lang-nursery/tempdir): Temporary directories
16+
//! of files.
17+
//! - [`walkdir`](https://github.com/BurntSushi/walkdir): Provides an efficient and cross platform
18+
//! implementation of recursive directory traversal.
19+
//!
20+
//! Consider supporting their development individually and starring them on github.
21+
//!
22+
//! # Types
23+
//! This library provides several kinds of types which improve and expand on `std::fs` and
24+
//! `std::path`, as well as provide new functionality like temporary files and tar archives.
25+
//!
26+
//! ## Path, Dir and File Types
27+
//! The following types are exported from [`path_abs`][`path_abs`]. These types provide improved
28+
//! error messages and type safety when working with paths and files. See the [crate documentation]
29+
//! [`path_abs`] for more details.
30+
//!
31+
//! - [`PathArc`](struct.PathArc.html): a reference counted `PathBuf` with methods reimplemented
32+
//! with better error messages. Use this for a generic serializable path that may or may
33+
//! not exist.
34+
//! - [`PathAbs`](struct.PathAbs.html): a reference counted absolute (canonicalized) path that is
35+
//! guaranteed (on initialization) to exist.
36+
//! - [`PathFile`](struct.PathFile.html): a `PathAbs` that is guaranteed to be a file, with
37+
//! associated methods.
38+
//! - [`PathDir`](struct.PathDir.html): a `PathAbs` that is guaranteed to be a directory, with
39+
//! associated methods.
40+
//! - [`PathType`](struct.PathType.html): an enum containing either a PathFile or a PathDir.
41+
//! Returned by [`PathDir::list`][dir_list]
42+
//! - [`FileRead`](struct.FileRead.html): a read-only file handle with `path()` attached and
43+
//! improved error messages. Contains only the methods and trait implementations which are
44+
//! allowed by a read-only file.
45+
//! - [`FileWrite`](struct.FileWrite.html): a write-only file handle with `path()` attached and
46+
//! improved error messages. Contains only the methods and trait implementations which are
47+
//! allowed by a write-only file.
48+
//! - [`FileEdit`](struct.FileEdit.html): a read/write file handle with `path()` attached and
49+
//! improved error messages. Contains methods and trait implements for both readable _and_
50+
//! writeable files.
51+
//!
52+
//! ## Temporary Directories
53+
//!
54+
//! There is one type exported which mimicks the above `Path*` objects.
55+
//! [`PathTmp`](struct.PathTmp.html), which is a `PathDir` that is deleted when it goes out of
56+
//! scope. This is a wrapper around the crate `tempdir::TempDir` with methods that mimick the
57+
//! `Path` types in this crate.
58+
//!
59+
//! > note: `PathTmp` is a wraper around `tempdir::TempDir`
60+
//!
61+
//! ## Walkdir
62+
//!
63+
//! The [`Walkdir`](struct.WalkDir.html) type is a direct export from the `walkdir` crate.
64+
//! The crate already has excellent error messages, and although it returns the regular
65+
//! `std::path::PathBuf` type, it is easy to convert to a file if you would like to.
66+
//!
67+
//! > TODO: although the WalkDir error can be auto-converted to std::io::Error, it
68+
//! > does not preserve the pretty output. See
69+
//! > [this ticket](https://github.com/BurntSushi/walkdir/pull/91)
70+
//!
71+
//! ### Examples
72+
//! ```rust
73+
//! use ergo_fs::{WalkDir, PathType};
74+
//!
75+
//! # fn try_main() -> Result<(), ::std::io::Error> {
76+
//! for entry in WalkDir::new("foo").min_depth(1) {
77+
//! match PathType::new(entry?)? {
78+
//! PathType::File(file) => println!("got file {}", file.display()),
79+
//! PathType::Dir(dir) => println!("got dir {}", dir.display()),
80+
//! }
81+
//! }
82+
//! # Ok(())
83+
//! # }
84+
//! ```
85+
//!
86+
//! ## Tar Files
87+
//! Similarly to walkdir, this is a direct export of the `tar` crate. It is recommended that you
88+
//! use the types like `PathDir` and `FileWrite` when interacting with this crate.
89+
//!
90+
//! > TODO: Add two "80%" methods:
91+
//! >
92+
//! > - `pack_tar(obj: Write, dir: &PathDir, src: Option<Path>)`: tars the `dir` into the `obj`,
93+
//! > using `walkdir` under the hood for speed and giving pretty error messages for all errors.
94+
//! > - `unpack_tar(obj: Read, dst: &PathDir)`: npacks the contents tarball into the specified dst
95+
//! > with cleaner error messages.
96+
//! >
97+
//! > Or... maybe consider just pretifying the error messages within the `tar` crate. Maybe they
98+
//! > would be interested in using `path_abs` under the hood?
99+
//!
100+
//! ```rust
101+
//! use ergo_fs::{PathTmp, FileWrite};
102+
//! use ergo_fs::tar::Builder;
103+
//!
104+
//! # fn try_main() -> Result<(), ::std::io::Error> {
105+
//! // We are going to tar the source code of this library
106+
//!
107+
//! let tmp = PathTmp::create("tmp")?;
108+
//! let mut tarfile = PathFile::create(tmp.join("src.tar"))?;
109+
//!
110+
//! // tar the source directory
111+
//! let mut tar = Builder::new(tarfile)
112+
//! tar.append_dir_all("src", ".")?;
113+
//! tar.finish();
114+
//! let tarfile = tar.into_inner();
115+
//! tarfile.flush();
116+
//!
117+
//! // A tarfile now exists, do whatever you would like with it.
118+
//! # Ok(())
119+
//! # }
120+
//! ```
121+
122+
extern crate std_prelude;
123+
extern crate tempdir;
124+
extern crate path_abs;
125+
126+
// -------------------------------
127+
// External Crate Exports
128+
pub extern crate tar;
129+
pub extern crate walkdir;
130+
131+
pub use path_abs::{PathAbs, PathArc, PathFile, PathDir, PathType, FileRead, FileWrite, FileEdit};
132+
pub use walkdir::{WalkDir, Error as WalkError};
133+
134+
// -------------------------------
135+
// Local Modules and Exports
136+
mod tmp;
137+
pub use tmp::PathTmp;

0 commit comments

Comments
 (0)