From 2625ed645c93b708342f9fcc25f2a30e635613c1 Mon Sep 17 00:00:00 2001 From: edef Date: Tue, 3 May 2022 15:49:43 +0000 Subject: ripple/fossil: don't expose protobufs in the frontend Previously, the CLI took Directory protobufs as input or wrote them as output. Now we just deal in store hashes. Change-Id: I5e0f0f33929ede43d971080c33bdb865f1832b2e --- ripple/fossil/src/bin/add.rs | 12 ++---------- ripple/fossil/src/bin/extract.rs | 11 +++++------ ripple/fossil/src/bin/mount.rs | 27 ++++++++++++--------------- ripple/fossil/src/lib.rs | 21 ++++++++------------- 4 files changed, 27 insertions(+), 44 deletions(-) (limited to 'ripple/fossil') 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 // 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)); } diff --git a/ripple/fossil/src/lib.rs b/ripple/fossil/src/lib.rs index aa4821c..ca474e3 100644 --- a/ripple/fossil/src/lib.rs +++ b/ripple/fossil/src/lib.rs @@ -74,8 +74,8 @@ impl Store { self.meta.flush().unwrap(); } - pub fn add_directory(&self, path: impl AsRef) -> Directory { - let (d, _) = self.add_directory_inner(path.as_ref()); + pub fn add_directory(&self, path: impl AsRef) -> DirectoryRef { + let d = self.add_directory_inner(path.as_ref()); self.flush(); d } @@ -86,7 +86,7 @@ impl Store { node } - fn add_directory_inner(&self, path: &Path) -> (Directory, u32) { + fn add_directory_inner(&self, path: &Path) -> DirectoryRef { let mut d = Directory::new(); let mut size: u32 = 0; @@ -99,22 +99,17 @@ impl Store { d.children.insert(name, child); } - (d, size) + let blob = d.into_pb().encode_to_vec(); + let ident = self.write_blob(&blob); + + DirectoryRef { ident, size } } fn add_path_inner(&self, path: &Path) -> Node { let meta = fs::symlink_metadata(path).unwrap(); match meta.file_type() { - ty if ty.is_dir() => { - let (d, size) = self.add_directory_inner(path); - let blob = d.into_pb().encode_to_vec(); - - Node::Directory(DirectoryRef { - ident: self.write_blob(&blob), - size, - }) - } + ty if ty.is_dir() => Node::Directory(self.add_directory_inner(path)), ty if ty.is_file() => { let executable = (meta.permissions().mode() & 0o100) != 0; -- cgit 1.4.1