diff options
author | edef <edef@unfathomable.blue> | 2022-05-03 00:29:10 +0000 |
---|---|---|
committer | edef <edef@unfathomable.blue> | 2022-05-03 00:29:10 +0000 |
commit | 9a531f656e158c9a5e0fab4cebdac6f46b19d919 (patch) | |
tree | c4e2462444c4b59ad9341ef11dad6b8c2b501cd4 /ripple | |
parent | f36ba24431313b78e1a8f489714879fe313fbd29 (diff) | |
download | unf-legacy-9a531f656e158c9a5e0fab4cebdac6f46b19d919.tar.zst |
ripple/fossil: expose add_directory
Change-Id: I8e976279bd7aaaaf325129dc5c68a6ca5c750dc6
Diffstat (limited to 'ripple')
-rw-r--r-- | ripple/fossil/src/lib.rs | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/ripple/fossil/src/lib.rs b/ripple/fossil/src/lib.rs index 0c8a61e..53e4d7b 100644 --- a/ripple/fossil/src/lib.rs +++ b/ripple/fossil/src/lib.rs @@ -64,10 +64,7 @@ impl Store { }) } - pub fn add_path(&self, path: impl AsRef<Path>) -> Node { - let path = path.as_ref(); - let node = self.add_path_inner(path); - + fn flush(&self) { // NOTE: sled *can* flush without us explicitly asking for it, so it's // possible for the store to end up containing pointers to chunks that // aren't fsynced yet. The easiest fix is to always `chunks_file.sync_data()` @@ -75,27 +72,42 @@ impl Store { // TODO(edef): keep pending and known-durable blobs/chunks separate in the database self.chunks_file.borrow_mut().sync_data().unwrap(); self.meta.flush().unwrap(); + } + pub fn add_directory(&self, path: impl AsRef<Path>) -> Directory { + let (d, _) = self.add_directory_inner(path.as_ref()); + self.flush(); + d + } + + pub fn add_path(&self, path: impl AsRef<Path>) -> Node { + let node = self.add_path_inner(path.as_ref()); + self.flush(); node } + fn add_directory_inner(&self, path: &Path) -> (Directory, u32) { + 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(); + + let child = self.add_path_inner(&entry.path()); + size = size.checked_add(child.size()).expect("overflow"); + d.children.insert(name, child); + } + + (d, size) + } + fn add_path_inner(&self, path: &Path) -> Node { let meta = fs::symlink_metadata(path).unwrap(); 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(); - - let child = self.add_path_inner(&entry.path()); - size = size.checked_add(child.size()).expect("overflow"); - d.children.insert(name, child); - } - + let (d, size) = self.add_directory_inner(path); let blob = d.into_pb().encode_to_vec(); Node::Directory(DirectoryRef { |