diff options
Diffstat (limited to 'ripple/fossil/src/bin')
-rw-r--r-- | ripple/fossil/src/bin/add.rs | 12 | ||||
-rw-r--r-- | ripple/fossil/src/bin/extract.rs | 11 | ||||
-rw-r--r-- | ripple/fossil/src/bin/mount.rs | 27 |
3 files changed, 19 insertions, 31 deletions
diff --git a/ripple/fossil/src/bin/add.rs b/ripple/fossil/src/bin/add.rs index ba51cd6..9024b81 100644 --- a/ripple/fossil/src/bin/add.rs +++ b/ripple/fossil/src/bin/add.rs @@ -1,14 +1,7 @@ // SPDX-FileCopyrightText: edef <edef@unfathomable.blue> // SPDX-License-Identifier: OSL-3.0 -use { - clap::StructOpt, - prost::Message, - std::{ - io::{self, Write}, - path::PathBuf, - }, -}; +use {clap::StructOpt, std::path::PathBuf}; #[derive(clap::Parser)] struct Args { @@ -23,6 +16,5 @@ fn main() { let store = fossil::Store::open(args.store).unwrap(); let root = store.add_directory(args.dir); - let mut stdout = io::stdout(); - stdout.write_all(&root.into_pb().encode_to_vec()).unwrap(); + println!("{}", fossil::digest_str(&root.ident)); } diff --git a/ripple/fossil/src/bin/extract.rs b/ripple/fossil/src/bin/extract.rs index a1e83df..64e27d4 100644 --- a/ripple/fossil/src/bin/extract.rs +++ b/ripple/fossil/src/bin/extract.rs @@ -7,7 +7,7 @@ use { prost::Message, std::{ fs, - io::{self, Read, Write}, + io::Write, os::unix::{fs::symlink, prelude::OpenOptionsExt}, path::{Path, PathBuf}, }, @@ -17,6 +17,8 @@ use { struct Args { #[clap(long, default_value = "fossil.db")] store: PathBuf, + #[clap(parse(try_from_str = fossil::digest_from_str))] + root: fossil::Digest, } fn main() { @@ -24,12 +26,9 @@ fn main() { let store = fossil::Store::open(args.store).unwrap(); let root = { - let mut stdin = io::stdin(); - - let mut bytes = Vec::new(); - stdin.read_to_end(&mut bytes).unwrap(); - + let bytes = store.read_blob(args.root); let pb = store::Directory::decode(&*bytes).unwrap(); + Directory::from_pb(pb) }; diff --git a/ripple/fossil/src/bin/mount.rs b/ripple/fossil/src/bin/mount.rs index 5a5f276..0f9e2ec 100644 --- a/ripple/fossil/src/bin/mount.rs +++ b/ripple/fossil/src/bin/mount.rs @@ -2,12 +2,12 @@ // SPDX-License-Identifier: OSL-3.0 use { + anyhow::Result, clap::StructOpt, - fossil::{store, FileRef}, + fossil::FileRef, lazy_static::lazy_static, libc::{c_int, EINVAL, ENOENT, ENOSYS, EROFS}, log::debug, - prost::Message, std::{ cell::RefCell, io::{self, Read, Seek}, @@ -77,6 +77,8 @@ fn file_attr(ino: u64, node: &memtree::Node) -> fuser::FileAttr { struct Args { #[clap(long, default_value = "fossil.db")] store: PathBuf, + #[clap(parse(try_from_str = fossil::digest_from_str))] + root: fossil::Digest, } fn main() { @@ -84,14 +86,7 @@ fn main() { let args = Args::parse(); let store = fossil::Store::open(args.store).unwrap(); - let root = memtree::load_root(&store, { - let mut stdin = io::stdin(); - - let mut bytes = Vec::new(); - stdin.read_to_end(&mut bytes).unwrap(); - - store::Directory::decode(&*bytes).unwrap() - }); + let root = memtree::load_root(&store, args.root); fuser::mount2( Filesystem::open(store, root), @@ -670,7 +665,7 @@ impl fuser::Filesystem for Filesystem { mod memtree { pub use fossil::FileRef; use { - fossil::store, + fossil::{store, Digest}, prost::Message, std::{collections::BTreeMap, fmt}, }; @@ -725,7 +720,11 @@ mod memtree { } } - pub fn load_root(store: &fossil::Store, pb: store::Directory) -> Directory { + pub fn load_root(store: &fossil::Store, ident: Digest) -> Directory { + let pb = { + let bytes = store.read_blob(ident); + store::Directory::decode(&*bytes).unwrap() + }; let mut children = BTreeMap::new(); for store::DirectoryNode { @@ -734,9 +733,7 @@ mod memtree { size: _, } in pb.directories { - let bytes = store.read_blob(fossil::digest_from_bytes(&r#ref)); - let pb = store::Directory::decode(&*bytes).unwrap(); - let child = load_root(store, pb); + let child = load_root(store, fossil::digest_from_bytes(&r#ref)); children.insert(name, Node::Directory(child)); } |