From bb796d6ef291e7bef192a269d5f082c791a516cb Mon Sep 17 00:00:00 2001 From: sergey-shandar Date: Tue, 17 Oct 2023 15:14:32 -0700 Subject: [PATCH] Use additional folders --- src/app.rs | 6 ++++-- src/file_table.rs | 11 ++++++++++- src/io.rs | 12 ++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/app.rs b/src/app.rs index bb8b0dc5..1c68fe4d 100644 --- a/src/app.rs +++ b/src/app.rs @@ -193,7 +193,9 @@ mod test { ]; let s = compress_one(&d).to_base32(); assert_eq!(io.stdout.to_string(), s.clone() + "\n"); - let v = io.read(&("cdt0/roots/".to_owned() + &s)).unwrap(); + let v = io + .read(&("cdt0/roots/".to_owned() + &s[..2] + "/" + &s[2..4] + "/" + &s[4..])) + .unwrap(); assert_eq!(v, " Hello, world!".as_bytes()); } @@ -208,7 +210,7 @@ mod test { let mut io = VirtualIo::new(&["get", s.as_str(), "b.txt"]); // io.create_dir("cdt0").unwrap(); io.write_recursively( - &("cdt0/roots/".to_owned() + &s), + &("cdt0/roots/".to_owned() + &s[..2] + "/" + &s[2..4] + "/" + &s[4..]), " Hello, world!".as_bytes(), ) .unwrap(); diff --git a/src/file_table.rs b/src/file_table.rs index 5b1720fc..c7b13fc2 100644 --- a/src/file_table.rs +++ b/src/file_table.rs @@ -12,7 +12,16 @@ pub struct FileTable<'a, T: Io>(pub &'a T); pub const DIR: &str = "cdt0"; fn path(t: Type, key: &U224) -> String { - DIR.to_owned() + "/" + ["roots", "parts"][t as usize] + "/" + &key.to_base32() + let s = key.to_base32(); + DIR.to_owned() + + "/" + + ["roots", "parts"][t as usize] + + "/" + + &s[..2] + + "/" + + &s[2..4] + + "/" + + &s[4..] } impl<'a, T: Io> Table for FileTable<'a, T> { diff --git a/src/io.rs b/src/io.rs index 39afb2d4..b4fc1028 100644 --- a/src/io.rs +++ b/src/io.rs @@ -84,6 +84,18 @@ mod test { assert!(io.write("a/test.txt", "Hello, world!".as_bytes()).is_err()); } + #[wasm_bindgen_test] + #[test] + fn test_write_recursively() { + let io = VirtualIo::new(&[]); + assert!(io + .write_recursively("a/test.txt", "Hello, world!".as_bytes()) + .is_ok()); + assert!(io + .write_recursively("a/test2.txt", "Hello, world!".as_bytes()) + .is_ok()); + } + #[wasm_bindgen_test] #[test] fn test_dir_rec() {