diff --git a/CHANGELOG.md b/CHANGELOG.md index 03490c86..97f95d49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased -- `blockset get` can create directories recursively. PR [#168](https://github.com/datablockset/blockset/pull/168) +## 0.5.0 + +- `blockset get` can create directories recursively. PR [#168](https://github.com/datablockset/blockset/pull/168). - `blockset add` works with directories. PR [#165](https://github.com/datablockset/blockset/pull/165). ## 0.4.2 diff --git a/blockset-lib/src/app/get.rs b/blockset-lib/src/app/get.rs index f412fa10..0ab77688 100644 --- a/blockset-lib/src/app/get.rs +++ b/blockset-lib/src/app/get.rs @@ -42,7 +42,8 @@ fn dir(path: &str) -> Option<&str> { } fn create_file_path_recursively(io: &T, path: &str) -> io::Result<()> { - dir(path).map_or(Ok(()), |d| io.create_dir_recursively(d)) + dir(path).map(|d| io.create_dir_recursively(d)); + Ok(()) } pub fn create_file_recursively(io: &T, path: &str) -> io::Result { diff --git a/blockset-lib/src/app/mod.rs b/blockset-lib/src/app/mod.rs index 85db47ac..c06e1342 100644 --- a/blockset-lib/src/app/mod.rs +++ b/blockset-lib/src/app/mod.rs @@ -128,10 +128,13 @@ fn read_to_tree_file( } } +fn str_to_hash(s: &str) -> io::Result { + s.from_base32::().ok_or(invalid_input("invalid hash")) +} + fn get_hash(a: &mut impl Iterator) -> io::Result { let b32 = a.next().ok_or(invalid_input("missing hash"))?; - b32.from_base32::() - .ok_or(invalid_input("invalid hash")) + str_to_hash(&b32) } fn validate(a: &mut impl Iterator, stdout: &mut impl Write) -> io::Result<()> { @@ -166,11 +169,14 @@ pub fn run(io: &impl Io) -> io::Result<()> { restore(io, &d, &mut w)?; let json: JsObjectRef<_> = try_move(parse_json(io, GLOBAL, buffer)?)?; for (k, v) in json.items() { - stdout.println([ - js_string_to_string(k)?.as_str(), - ": ", - js_string_to_string(&try_move(v.clone())?)?.as_str(), - ])?; + let file = js_string_to_string(k)?; + let hash = js_string_to_string(&try_move(v.clone())?)?; + restore( + io, + &str_to_hash(&hash)?, + &mut create_file_recursively(io, (path.to_owned() + &file).as_str())?, + )?; + // stdout.println([&path, ": ", &hash])?; } Ok(()) } else { diff --git a/blockset/README.md b/blockset/README.md index 757417f5..7f662d6e 100644 --- a/blockset/README.md +++ b/blockset/README.md @@ -12,15 +12,18 @@ The `blockset` application is a command line program that can store and retrieve ```console blockset hash ./README.md ``` -- add content of a file to the local storage `cdt0/`: +- add content of a file or a directory to the local storage `cdt0/`: ```console blockset add ./README.md blockset add ./LICENSE --to-posix-eol ``` -- get a file by a content hash +- get a file or a directory by a content hash ```console blockset get ngd7zembwj6f2tsh4gyxrcyx26h221e3f2wdgfbtq87nd ./old.md ``` + ```console + blockset get ngd7zembwj6f2tsh4gyxrcyx26h221e3f2wdgfbtq87nd ./dir/ + ``` - information about the repository ```console blockset info