diff --git a/blockset-lib/src/app/add.rs b/blockset-lib/src/app/add.rs index 9f4bd539..08870fbd 100644 --- a/blockset-lib/src/app/add.rs +++ b/blockset-lib/src/app/add.rs @@ -66,11 +66,19 @@ fn property( ) } +pub fn directory_js(m: M) -> JsStringRef { + let directory16 = "directory".encode_utf16().collect::>(); + new_string(m, directory16).to_ref() +} + fn dir_to_json( m: M, list: impl ExactSizeIterator>, ) -> io::Result { - to_json(m.new_js_object(list)).map_err(|_| invalid_input("to_json")) + let dir = m.new_js_object(list); + let property = (directory_js(m), dir); + let block = m.new_js_object([property]); + to_json(block).map_err(|_| invalid_input("to_json")) } fn calculate_len(files: &[(String, u64)], state: &mut State) { diff --git a/blockset-lib/src/app/get.rs b/blockset-lib/src/app/get.rs index 614a06ff..c5d80621 100644 --- a/blockset-lib/src/app/get.rs +++ b/blockset-lib/src/app/get.rs @@ -16,7 +16,10 @@ use crate::{ uint::u224::U224, }; -use super::{add::posix_path, get_hash, invalid_input, js_string_to_string, str_to_hash, try_move}; +use super::{ + add::{directory_js, posix_path}, + get_hash, invalid_input, js_string_to_string, str_to_hash, try_move, +}; pub fn restore( io: &impl Io, @@ -73,7 +76,14 @@ fn get_if(d: &U224, path: &str, io: &impl Io) -> io::Result<()> { let mut w = Cursor::new(&mut buffer); restore(io, d, &mut w, &mut |_, _| Ok(()))?; let json = try_move::<_, JsObjectRef<_>>(parse_json(io, GLOBAL, buffer)?)?; - let items = json.items(); + let dir = directory_js(GLOBAL); + let dir_json = json + .items() + .iter() + .find(|p| p.0.items() == dir.items()) + .map_or(Err(invalid_input("directory")), |f| Ok(f))?; + let dir_obj = try_move::<_, JsObjectRef<_>>(dir_json.1.clone())?; + let items = dir_obj.items(); let t = items.len(); let mut b = 0; for (offset, (k, v)) in items.iter().enumerate() { diff --git a/issues/README.md b/issues/README.md index 2b241370..a7125903 100644 --- a/issues/README.md +++ b/issues/README.md @@ -3,3 +3,4 @@ - Restore code coverage. We may switch to `cargo-llvm-cov` from `tarpauilin`. - Change directory structure. - ASN.1 +- remove `--to-posix-eol` and replace it with a separate utility