diff --git a/blockset-lib/src/app/add.rs b/blockset-lib/src/app/add.rs index eb44b5fc..53b8a076 100644 --- a/blockset-lib/src/app/add.rs +++ b/blockset-lib/src/app/add.rs @@ -1,5 +1,5 @@ use core::ops::Deref; -use std::io; +use std::io::{self, Cursor}; use io_trait::{DirEntry, Io, Metadata}; use nanvm_lib::{ @@ -14,9 +14,9 @@ use nanvm_lib::{ serializer::to_json, }; -use crate::cdt::tree_add::TreeAdd; +use crate::{cdt::tree_add::TreeAdd, common::print::Print}; -use super::{invalid_input, read_to_tree_file}; +use super::{invalid_input, read_to_tree, read_to_tree_file}; pub struct Add<'a, T: Io, S: 'a + TreeAdd, F: Fn(&'a T) -> S> { pub io: &'a T, @@ -73,7 +73,7 @@ impl<'a, T: Io, S: 'a + TreeAdd, F: Fn(&'a T) -> S> Add<'a, T, S, F> { self.display_new, ) } - pub fn path_to_json(&self, path: &str) -> io::Result { + fn path_to_json(&self, path: &str) -> io::Result { let files = read_dir_recursive(self.io, path)?; let mut list = Vec::default(); for e in files { @@ -83,4 +83,17 @@ impl<'a, T: Io, S: 'a + TreeAdd, F: Fn(&'a T) -> S> Add<'a, T, S, F> { } dir_to_json(GLOBAL, list.into_iter()) } + pub fn add_dir( + &self, + path: &str, + ) -> io::Result<()> { + let json = self.path_to_json(path)?; + let hash = read_to_tree( + (self.storage)(self.io), + Cursor::new(&json), + self.io, + self.display_new, + )?; + self.io.stdout().println([hash.as_str()]) + } } diff --git a/blockset-lib/src/app/add_dir.rs b/blockset-lib/src/app/add_dir.rs deleted file mode 100644 index 2a290771..00000000 --- a/blockset-lib/src/app/add_dir.rs +++ /dev/null @@ -1,22 +0,0 @@ - -use std::io::{self, Cursor}; - -use io_trait::Io; - -use crate::{cdt::tree_add::TreeAdd, common::print::Print}; - -use super::{add::Add, read_to_tree}; - -pub fn add_dir<'a, T: Io, S: 'a + TreeAdd, F: Fn(&'a T) -> S>( - add: &Add<'a, T, S, F>, - path: &str, -) -> io::Result<()> { - let json = add.path_to_json(path)?; - let hash = read_to_tree( - (add.storage)(add.io), - Cursor::new(&json), - add.io, - add.display_new, - )?; - add.io.stdout().println([hash.as_str()]) -} diff --git a/blockset-lib/src/app/add_entry.rs b/blockset-lib/src/app/add_entry.rs index 93ee2dfb..b745a442 100644 --- a/blockset-lib/src/app/add_entry.rs +++ b/blockset-lib/src/app/add_entry.rs @@ -4,7 +4,7 @@ use io_trait::{Io, Metadata}; use crate::{cdt::tree_add::TreeAdd, common::print::Print}; -use super::{add::Add, add_dir::add_dir, invalid_input, is_to_posix_eol}; +use super::{add::Add, invalid_input, is_to_posix_eol}; pub fn add_entry<'a, T: Io, S: 'a + TreeAdd>( io: &'a T, @@ -21,7 +21,7 @@ pub fn add_entry<'a, T: Io, S: 'a + TreeAdd>( display_new, }; if io.metadata(&path)?.is_dir() { - add_dir(&add, &path) + add.add_dir(&path) } else { let k = add.add_file(&path)?; io.stdout().println([k.as_str()]) diff --git a/blockset-lib/src/app/mod.rs b/blockset-lib/src/app/mod.rs index 77709217..91d5f403 100644 --- a/blockset-lib/src/app/mod.rs +++ b/blockset-lib/src/app/mod.rs @@ -1,5 +1,4 @@ mod add; -mod add_dir; mod add_entry; use std::io::{self, ErrorKind, Read, Write};