summary refs log tree commit diff
path: root/ripple
diff options
context:
space:
mode:
authoredef <edef@unfathomable.blue>2022-04-10 23:29:51 +0000
committeredef <edef@unfathomable.blue>2022-04-10 23:41:35 +0000
commit62e3cac7747f6660d2b43ed5c21be8ab584dff5d (patch)
tree998870ce46fbea2d89ad9dbe8cecf5edec8d9299 /ripple
parent65f0ca486e42e5c054f43524e9f2709b292f08b3 (diff)
downloadunf-legacy-62e3cac7747f6660d2b43ed5c21be8ab584dff5d.tar.zst
ripple/fossil: split out FileRef/DirectoryRef
Change-Id: I649c89ccc4e7fbc3ce42c86f6653d59c07cf58a9
Diffstat (limited to 'ripple')
-rw-r--r--ripple/fossil/src/bin/extract.rs8
-rw-r--r--ripple/fossil/src/lib.rs58
2 files changed, 40 insertions, 26 deletions
diff --git a/ripple/fossil/src/bin/extract.rs b/ripple/fossil/src/bin/extract.rs
index 685805d..e55c857 100644
--- a/ripple/fossil/src/bin/extract.rs
+++ b/ripple/fossil/src/bin/extract.rs
@@ -32,13 +32,13 @@ 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, size: _ } => {
-				let blob = store.read_blob(r#ref);
+			fossil::Node::Directory(fossil::DirectoryRef { ident, size: _ }) => {
+				let blob = store.read_blob(ident);
 				let pb = store::Directory::decode(&*blob).unwrap();
 				fs::create_dir(&path).unwrap();
 				extract(store, &path, &Directory::from_pb(pb));
 			}
-			fossil::Node::File { r#ref, executable } => {
+			fossil::Node::File(fossil::FileRef { ident, executable }) => {
 				let mode = if executable { 0o755 } else { 0o644 };
 				let mut f = fs::OpenOptions::new()
 					.write(true)
@@ -46,7 +46,7 @@ fn extract(store: &fossil::Store, path: &Path, dir: &Directory) {
 					.mode(mode)
 					.open(path)
 					.unwrap();
-				let blob = store.read_blob(r#ref);
+				let blob = store.read_blob(ident);
 				f.write_all(&blob).unwrap();
 			}
 			fossil::Node::Link { target } => {
diff --git a/ripple/fossil/src/lib.rs b/ripple/fossil/src/lib.rs
index bb39665..4d3f7b0 100644
--- a/ripple/fossil/src/lib.rs
+++ b/ripple/fossil/src/lib.rs
@@ -44,19 +44,19 @@ impl Store {
 
 				let blob = d.into_pb().encode_to_vec();
 
-				Node::Directory {
-					r#ref: self.write_blob(&blob),
+				Node::Directory(DirectoryRef {
+					ident: self.write_blob(&blob),
 					size,
-				}
+				})
 			}
 			ty if ty.is_file() => {
 				let executable = (meta.permissions().mode() & 0o100) != 0;
 
 				let blob = fs::read(path).unwrap();
-				Node::File {
+				Node::File(FileRef {
 					executable,
-					r#ref: self.write_blob(&blob),
-				}
+					ident: self.write_blob(&blob),
+				})
 			}
 			ty if ty.is_symlink() => {
 				let target = path
@@ -127,15 +127,27 @@ pub struct Directory {
 
 #[derive(Clone)]
 pub enum Node {
-	Directory { r#ref: Digest, size: u32 },
-	File { r#ref: Digest, executable: bool },
+	Directory(DirectoryRef),
+	File(FileRef),
 	Link { target: String },
 }
 
+#[derive(Clone)]
+pub struct DirectoryRef {
+	pub ident: Digest,
+	pub size: u32,
+}
+
+#[derive(Clone)]
+pub struct FileRef {
+	pub ident: Digest,
+	pub executable: bool,
+}
+
 impl Node {
 	fn size(&self) -> u32 {
 		match self {
-			&Node::Directory { size, .. } => size.checked_add(1).expect("overflow"),
+			&Node::Directory(DirectoryRef { size, .. }) => size.checked_add(1).expect("overflow"),
 			_ => 1,
 		}
 	}
@@ -153,14 +165,16 @@ impl Directory {
 
 		for (name, node) in self.children.into_iter() {
 			match node {
-				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 {
+				Node::Directory(DirectoryRef { ident, size }) => {
+					d.directories.push(store::DirectoryNode {
+						name,
+						size,
+						r#ref: ident.as_bytes().to_vec(),
+					})
+				}
+				Node::File(FileRef { ident, executable }) => d.files.push(store::FileNode {
 					name,
-					r#ref: r#ref.as_bytes().to_vec(),
+					r#ref: ident.as_bytes().to_vec(),
 					executable,
 				}),
 				Node::Link { target } => d.links.push(store::LinkNode { name, target }),
@@ -176,20 +190,20 @@ impl Directory {
 		for child in pb.directories {
 			children.insert(
 				child.name,
-				Node::Directory {
-					r#ref: digest_from_bytes(&child.r#ref),
+				Node::Directory(DirectoryRef {
+					ident: digest_from_bytes(&child.r#ref),
 					size: child.size,
-				},
+				}),
 			);
 		}
 
 		for child in pb.files {
 			children.insert(
 				child.name,
-				Node::File {
-					r#ref: digest_from_bytes(&child.r#ref),
+				Node::File(FileRef {
+					ident: digest_from_bytes(&child.r#ref),
 					executable: child.executable,
-				},
+				}),
 			);
 		}