FsTree
is a path Trie with an API focused on filesystem operations.
- Unix only.
- This crate was transfered after
0.1.3
, and changed its purpose. - This crate refers to "filesystem tree" as the result you get from recursively traversing files:
- If you try traversing a single file, you get a single node.
- If you try traversing a directories, you might get a large subtree (of nodes).
- This is agnostic to the underlying filesystem (nothing to do with
ext4
orbtrfs
).
- Check Trie if you both haven't met yet.
A FsTree
is a node with three possible file types:
use std::{collections::BTreeMap, path::PathBuf};
pub enum FsTree {
Regular,
Directory(TrieMap), // Recursive part
Symlink(PathBuf),
}
// ↓↓
pub type TrieMap = BTreeMap<PathBuf, FsTree>; // Recursive part
The root of the FsTree
is unnamed (no filename/path), the "edges" to children are the
relative paths.
Like std
functions, functions in this crate follow symlinks (and symlink chains), so you'll
never get a FsTree::Symlink(_)
in your tree! If you want symlink-awareness, use the function
version with the symlink
prefix (FsTree::read_at
vs FsTree::symlink_read_at
).
Ways to construct a FsTree
:
- Read node/tree from path. (
FsTree::symlink_read_at
) - Declare a
FsTree
literal. (tree!
) - Insert each node in an empty folder. (
FsTree::new_dir
+FsTree::insert
) - Parse from path text segments. (
FsTree::from_path_text
)
What you can do with a FsTree
:
- Traverse, query, and modify it.
- Merge with another tree. (
FsTree::try_merge
) - Write it to disk. (
FsTree::write_at
) - Try loading a structural copy of it from a path. (
FsTree::read_structure_at
) - (TODO) Compare with another
FsTree
, generating a DiffTree. - (TODO) Add entry API.
See docs in the iter
module.
- Crate
walkdir
- Better if you just need to iterate on filesystem trees. - Crate
file_type_enum
- If you want a shallow type enum. - Crate
build-fs-tree
- If you need to create a filesystem tree from a YAML file.- The closest we got is creating a tree literal with
tree!
, and writing withFsTree::write_at
.
- The closest we got is creating a tree literal with