diff --git a/src/catar.rs b/src/catar.rs index 22a87a24..a9688c63 100644 --- a/src/catar.rs +++ b/src/catar.rs @@ -40,4 +40,5 @@ pub mod binary_search_tree; pub mod format_definition; pub mod encoder; +pub mod decoder; diff --git a/src/catar/binary_search_tree.rs b/src/catar/binary_search_tree.rs index 035eab54..7cad3e6d 100644 --- a/src/catar/binary_search_tree.rs +++ b/src/catar/binary_search_tree.rs @@ -86,6 +86,7 @@ pub fn copy_binary_search_tree( ) { if n == 0 { return }; let e = (64 - n.leading_zeros() - 1) as usize; // fast log2(n) + copy_binary_search_tree_inner(&mut copy_func, n, 0, e, 0); } diff --git a/src/catar/decoder.rs b/src/catar/decoder.rs new file mode 100644 index 00000000..b80f4cc3 --- /dev/null +++ b/src/catar/decoder.rs @@ -0,0 +1,3 @@ +///! *catar* format decoder. + + diff --git a/src/catar/encoder.rs b/src/catar/encoder.rs index 8ace30cf..c7d3d559 100644 --- a/src/catar/encoder.rs +++ b/src/catar/encoder.rs @@ -21,8 +21,6 @@ use nix::sys::stat::Mode; use nix::errno::Errno; use nix::sys::stat::FileStat; -use siphasher::sip::SipHasher24; - /// The format requires to build sorted directory lookup tables in /// memory, so we restrict the number of allowed entries to limit /// maximum memory usage. @@ -264,7 +262,7 @@ impl CaTarEncoder { goodbye_items.push(CaFormatGoodbyeItem { offset: start_pos as u64, size: (end_pos - start_pos) as u64, - hash: compute_goodbye_hash(&filename), + hash: compute_goodbye_hash(filename.to_bytes()), }); self.current_path.pop(); @@ -357,11 +355,3 @@ impl CaTarEncoder { Ok(()) } } - -fn compute_goodbye_hash(name: &CStr) -> u64 { - - use std::hash::Hasher; - let mut hasher = SipHasher24::new_with_keys(0x8574442b0f1d84b3, 0x2736ed30d1c22ec1); - hasher.write(name.to_bytes()); - hasher.finish() -} diff --git a/src/catar/format_definition.rs b/src/catar/format_definition.rs index 755b3fee..30cb6bc5 100644 --- a/src/catar/format_definition.rs +++ b/src/catar/format_definition.rs @@ -7,6 +7,8 @@ use failure::*; +use siphasher::sip::SipHasher24; + pub const CA_FORMAT_ENTRY: u64 = 0x1396fabcea5bbb51; pub const CA_FORMAT_FILENAME: u64 = 0x6dbb6ebcb3161f0b; pub const CA_FORMAT_SYMLINK: u64 = 0x664a6fb6830e0d6c; @@ -51,7 +53,9 @@ pub struct CaFormatGoodbyeItem { pub hash: u64, } -fn read_os_string(buffer: &[u8]) -> std::ffi::OsString { + +/// Helper function to extract file names from binary archive. +pub fn read_os_string(buffer: &[u8]) -> std::ffi::OsString { let len = buffer.len(); use std::os::unix::ffi::OsStrExt; @@ -64,3 +68,13 @@ fn read_os_string(buffer: &[u8]) -> std::ffi::OsString { name.into() } + +/// Create SipHash values for goodby tables. +//pub fn compute_goodbye_hash(name: &std::ffi::CStr) -> u64 { +pub fn compute_goodbye_hash(name: &[u8]) -> u64 { + + use std::hash::Hasher; + let mut hasher = SipHasher24::new_with_keys(0x8574442b0f1d84b3, 0x2736ed30d1c22ec1); + hasher.write(name); + hasher.finish() +} diff --git a/tests/catar.rs b/tests/catar.rs index 0a6a5a9d..40e10854 100644 --- a/tests/catar.rs +++ b/tests/catar.rs @@ -46,6 +46,8 @@ fn run_all_tests() -> Result<(), Error> { run_test("tests/catar_data/test_subdir")?; + run_test("tests/catar_data/test1")?; + Ok(()) }