Skip to content

Commit

Permalink
{"directory":...}
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-shandar committed Aug 14, 2024
1 parent d236b7d commit a52458d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
10 changes: 9 additions & 1 deletion blockset-lib/src/app/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,19 @@ fn property<M: Manager>(
)
}

pub fn directory_js<M: Manager>(m: M) -> JsStringRef<M::Dealloc> {
let directory16 = "directory".encode_utf16().collect::<Vec<_>>();
new_string(m, directory16).to_ref()
}

fn dir_to_json<M: Manager>(
m: M,
list: impl ExactSizeIterator<Item = Property<M::Dealloc>>,
) -> io::Result<String> {
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) {
Expand Down
14 changes: 12 additions & 2 deletions blockset-lib/src/app/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions issues/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a52458d

Please sign in to comment.