catar cleanups ...
This commit is contained in:
parent
6cd28d200e
commit
0866748de6
@ -40,4 +40,5 @@
|
||||
pub mod binary_search_tree;
|
||||
pub mod format_definition;
|
||||
pub mod encoder;
|
||||
pub mod decoder;
|
||||
|
||||
|
@ -86,6 +86,7 @@ pub fn copy_binary_search_tree<F: FnMut(usize, usize)>(
|
||||
) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
3
src/catar/decoder.rs
Normal file
3
src/catar/decoder.rs
Normal file
@ -0,0 +1,3 @@
|
||||
///! *catar* format decoder.
|
||||
|
||||
|
@ -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 <W: Write> CaTarEncoder<W> {
|
||||
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 <W: Write> CaTarEncoder<W> {
|
||||
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()
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -46,6 +46,8 @@ fn run_all_tests() -> Result<(), Error> {
|
||||
|
||||
run_test("tests/catar_data/test_subdir")?;
|
||||
|
||||
run_test("tests/catar_data/test1")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user