summary refs log tree commit diff
path: root/ripple/fossil/src/bin/add.rs
blob: 114f89356dd8817b156670822a439f5a77dcd8f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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();
}