1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-06-07 23:27:45 +00:00

Support filenames without directories in IndexFile

This can't happen I don't think, but we should definitely not panic when
it does.
This commit is contained in:
Joshua Goins 2024-04-16 21:25:53 -04:00
parent 26e89e8873
commit d3970754f1

View file

@ -112,14 +112,16 @@ impl IndexFile {
pub fn calculate_hash(path: &str) -> u64 {
let lowercase = path.to_lowercase();
let pos = lowercase.rfind('/').unwrap();
if let Some(pos) = lowercase.rfind('/') {
let (directory, filename) = lowercase.split_at(pos);
let directory_crc = CRC.checksum(directory.as_bytes());
let filename_crc = CRC.checksum(filename[1..filename.len()].as_bytes());
(directory_crc as u64) << 32 | (filename_crc as u64)
} else {
CRC.checksum(lowercase.as_bytes()) as u64
}
}
// TODO: turn into traits?