summary refs log tree commit diff
path: root/ripple/fossil/src/bin/mount.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ripple/fossil/src/bin/mount.rs')
-rw-r--r--ripple/fossil/src/bin/mount.rs27
1 files changed, 12 insertions, 15 deletions
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));
 		}