diff options
author | edef <edef@unfathomable.blue> | 2022-04-10 22:17:00 +0000 |
---|---|---|
committer | edef <edef@unfathomable.blue> | 2022-04-10 22:41:22 +0000 |
commit | 65f0ca486e42e5c054f43524e9f2709b292f08b3 (patch) | |
tree | 149db3f735e88091d20596e2e173aab72b0159b9 /ripple/fossil/src | |
parent | 5410c542c0ac55ca88252497380ea1c3b3a1e8eb (diff) | |
download | unf-legacy-65f0ca486e42e5c054f43524e9f2709b292f08b3.tar.zst |
ripple/fossil: track transitive inode count
Change-Id: Ia5893bc64f58e3a6b17aa96fdd27b6b49ebf5fa5
Diffstat (limited to 'ripple/fossil/src')
-rw-r--r-- | ripple/fossil/src/bin/extract.rs | 2 | ||||
-rw-r--r-- | ripple/fossil/src/lib.rs | 22 | ||||
-rw-r--r-- | ripple/fossil/src/store.proto | 1 |
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 { |