Skip to content

Commit

Permalink
add_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-shandar committed Mar 11, 2024
1 parent 598f3d8 commit c9f10bb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 29 deletions.
21 changes: 17 additions & 4 deletions blockset-lib/src/app/add.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -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,
Expand Down Expand Up @@ -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<String> {
fn path_to_json(&self, path: &str) -> io::Result<String> {
let files = read_dir_recursive(self.io, path)?;
let mut list = Vec::default();
for e in files {
Expand All @@ -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()])
}
}
22 changes: 0 additions & 22 deletions blockset-lib/src/app/add_dir.rs

This file was deleted.

4 changes: 2 additions & 2 deletions blockset-lib/src/app/add_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()])
Expand Down
1 change: 0 additions & 1 deletion blockset-lib/src/app/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
mod add;
mod add_dir;
mod add_entry;

use std::io::{self, ErrorKind, Read, Write};
Expand Down

0 comments on commit c9f10bb

Please sign in to comment.