summary refs log tree commit diff
path: root/ripple
diff options
context:
space:
mode:
Diffstat (limited to 'ripple')
-rw-r--r--ripple/fossil/src/bin/extract.rs2
-rw-r--r--ripple/fossil/src/lib.rs22
-rw-r--r--ripple/fossil/src/store.proto1
3 files changed, 21 insertions, 4 deletions
diff --git a/ripple/fossil/src/bin/extract.rs b/ripple/fossil/src/bin/extract.rs
index f83ce0e..685805d 100644
--- a/ripple/fossil/src/bin/extract.rs
+++ b/ripple/fossil/src/bin/extract.rs
@@ -32,7 +32,7 @@ fn extract(store: &fossil::Store, path: &Path, dir: &Directory) {
 	for (name, node) in &dir.children {
 		let path = path.join(name);
 		match node.clone() {
-			fossil::Node::Directory { r#ref } => {
+			fossil::Node::Directory { r#ref, size: _ } => {
 				let blob = store.read_blob(r#ref);
 				let pb = store::Directory::decode(&*blob).unwrap();
 				fs::create_dir(&path).unwrap();
diff --git a/ripple/fossil/src/lib.rs b/ripple/fossil/src/lib.rs
index 09326a4..bb39665 100644
--- a/ripple/fossil/src/lib.rs
+++ b/ripple/fossil/src/lib.rs
@@ -31,17 +31,22 @@ impl Store {
 		match meta.file_type() {
 			ty if ty.is_dir() => {
 				let mut d = Directory::new();
+				let mut size: u32 = 0;
 
 				for entry in path.read_dir().unwrap() {
 					let entry = entry.unwrap();
 					let name = entry.file_name().into_string().unwrap();
-					d.children.insert(name, self.add_path(entry.path()));
+
+					let child = self.add_path(entry.path());
+					size = size.checked_add(child.size()).expect("overflow");
+					d.children.insert(name, child);
 				}
 
 				let blob = d.into_pb().encode_to_vec();
 
 				Node::Directory {
 					r#ref: self.write_blob(&blob),
+					size,
 				}
 			}
 			ty if ty.is_file() => {
@@ -122,11 +127,20 @@ pub struct Directory {
 
 #[derive(Clone)]
 pub enum Node {
-	Directory { r#ref: Digest },
+	Directory { r#ref: Digest, size: u32 },
 	File { r#ref: Digest, executable: bool },
 	Link { target: String },
 }
 
+impl Node {
+	fn size(&self) -> u32 {
+		match self {
+			&Node::Directory { size, .. } => size.checked_add(1).expect("overflow"),
+			_ => 1,
+		}
+	}
+}
+
 impl Directory {
 	pub fn new() -> Directory {
 		Directory {
@@ -139,8 +153,9 @@ impl Directory {
 
 		for (name, node) in self.children.into_iter() {
 			match node {
-				Node::Directory { r#ref } => d.directories.push(store::DirectoryNode {
+				Node::Directory { r#ref, size } => d.directories.push(store::DirectoryNode {
 					name,
+					size,
 					r#ref: r#ref.as_bytes().to_vec(),
 				}),
 				Node::File { r#ref, executable } => d.files.push(store::FileNode {
@@ -163,6 +178,7 @@ impl Directory {
 				child.name,
 				Node::Directory {
 					r#ref: digest_from_bytes(&child.r#ref),
+					size: child.size,
 				},
 			);
 		}
diff --git a/ripple/fossil/src/store.proto b/ripple/fossil/src/store.proto
index 58832f0..ff67d71 100644
--- a/ripple/fossil/src/store.proto
+++ b/ripple/fossil/src/store.proto
@@ -14,6 +14,7 @@ message Directory {
 message DirectoryNode {
     string name = 1;
     bytes ref = 2;
+    uint32 size = 3;
 }
 
 message FileNode {