summary refs log tree commit diff
path: root/ripple/fossil/src/bin/add.rs
diff options
context:
space:
mode:
authoredef <edef@unfathomable.blue>2021-08-14 21:28:14 +0000
committeredef <edef@unfathomable.blue>2021-08-14 21:28:14 +0000
commitdb7c54f92f386a94db8af7a12626d2657b4dd640 (patch)
tree4baba57bac54c68823a834c0f8aa97b24cfec7a2 /ripple/fossil/src/bin/add.rs
parentdcae0f9c8a94f05bf55cf9b6fbc773502ab5784f (diff)
downloadunf-legacy-db7c54f92f386a94db8af7a12626d2657b4dd640.tar.zst
ripple/fossil: a basic content-addressable store
Fossil stores content-addressed blobs of file contents and
Protobuf-encoded directory listings, backed by Sled.

Change-Id: I8b49de6342218ca00755cec980b1d0cfb18878a7
Diffstat (limited to 'ripple/fossil/src/bin/add.rs')
-rw-r--r--ripple/fossil/src/bin/add.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/ripple/fossil/src/bin/add.rs b/ripple/fossil/src/bin/add.rs
new file mode 100644
index 0000000..114f893
--- /dev/null
+++ b/ripple/fossil/src/bin/add.rs
@@ -0,0 +1,31 @@
+// SPDX-FileCopyrightText: edef <edef@unfathomable.blue>
+// SPDX-License-Identifier: OSL-3.0
+
+use {
+	fossil::Directory,
+	prost::Message,
+	std::{
+		env,
+		io::{self, Write},
+		path::Path,
+	},
+};
+
+fn main() {
+	let store = fossil::Store::open("fossil.db").unwrap();
+	let mut root = Directory::new();
+
+	for name in env::args().skip(1) {
+		let path = Path::new(&name);
+		let name = path
+			.file_name()
+			.and_then(|s| s.to_str())
+			.expect("invalid path")
+			.to_owned();
+
+		root.children.insert(name, store.add_path(path));
+	}
+
+	let mut stdout = io::stdout();
+	stdout.write_all(&root.into_pb().encode_to_vec()).unwrap();
+}