use monofs::filesystem::{Dir, File, FsResult};
use monoutils_store::{MemoryStore, Storable};
#[tokio::main]
async fn main() -> FsResult<()> {
let store = MemoryStore::default();
let mut root = Dir::new(store.clone());
println!("Created root directory: {:?}", root);
let file = root.find_or_create("docs/readme.md", true).await?;
println!("Created file: {:?}", file);
let dir = root.find_or_create("projects/rust", false).await?;
println!("Created directory: {:?}", dir);
let entries = root.list()?;
println!("Root directory contents: {:?}", entries);
root.copy("docs/readme.md", "projects").await?;
println!("Copied 'readme.md' to 'projects' directory");
let copied_file = root.find("projects/readme.md").await?;
println!("Copied file: {:?}", copied_file);
let (removed_name, removed_entity) = root.remove("docs/readme.md").await?;
println!("Removed '{}': {:?}", removed_name, removed_entity);
root.put_dir("subdir", Dir::new(store.clone()))?;
println!("Added subdirectory 'subdir'");
root.put_file("example.txt", File::new(store.clone()))?;
println!("Added file 'example.txt' to root");
println!("Entries in root directory:");
for (name, entity) in root.get_entries() {
println!("- {}: {:?}", name, entity);
}
let file_exists = root.has_entry("example.txt").await?;
println!("'example.txt' exists: {}", file_exists);
if let Some(subdir) = root.get_dir_mut("subdir").await? {
subdir.put_file("subdir_file.txt", File::new(store.clone()))?;
println!("Added 'subdir_file.txt' to 'subdir'");
}
root.remove_entry("example.txt")?;
println!("Removed 'example.txt' from root");
println!("Root directory is empty: {}", root.is_empty());
let root_cid = root.store().await?;
println!("Stored root directory with CID: {}", root_cid);
let loaded_root = Dir::load(&root_cid, store).await?;
println!("Loaded root directory: {:?}", loaded_root);
Ok(())
}