diff --git a/lib/b3fs/src/directory/hasher.rs b/lib/b3fs/src/directory/hasher.rs index b8e24aa77..8b28541d0 100644 --- a/lib/b3fs/src/directory/hasher.rs +++ b/lib/b3fs/src/directory/hasher.rs @@ -122,7 +122,7 @@ impl DirectoryHasher { // file name. if self.counter > 0 { let end = 3 + self.last_filename_size; - let prev_name = &self.transcript_buffer[3..end]; + let prev_name = &self.transcript_buffer[1..end]; if prev_name == entry.name { return Err(Error::FilenameNotUnique); diff --git a/lib/b3fs/src/test_utils.rs b/lib/b3fs/src/test_utils.rs index f3beddb0e..6d52dce98 100644 --- a/lib/b3fs/src/test_utils.rs +++ b/lib/b3fs/src/test_utils.rs @@ -3,17 +3,17 @@ use crate::directory::hasher::DirectoryHasher; use crate::directory::transcript::{hash_transcript, write_entry_transcript}; /// Returns the `i`-th ascii character starting from `A`. +/// +/// `name(a) < name(b) for a < b` pub fn name(mut i: usize) -> String { - const CHARS: &str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - let mut bytes = Vec::new(); + const CHARS: &[u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + let mut bytes = vec![b'A'; 14]; + let mut j = bytes.len(); while i > 0 { - bytes.push(CHARS.as_bytes()[i % CHARS.len()]); + j -= 1; + bytes[j] = CHARS[i % CHARS.len()]; i /= CHARS.len(); } - while bytes.len() < 5 { - bytes.push(CHARS.as_bytes()[0]); - } - bytes.reverse(); String::from_utf8(bytes).unwrap() }