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:
parent
26e89e8873
commit
d3970754f1
1 changed files with 8 additions and 6 deletions
14
src/index.rs
14
src/index.rs
|
@ -112,14 +112,16 @@ impl IndexFile {
|
||||||
pub fn calculate_hash(path: &str) -> u64 {
|
pub fn calculate_hash(path: &str) -> u64 {
|
||||||
let lowercase = path.to_lowercase();
|
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, filename) = lowercase.split_at(pos);
|
let directory_crc = CRC.checksum(directory.as_bytes());
|
||||||
|
let filename_crc = CRC.checksum(filename[1..filename.len()].as_bytes());
|
||||||
|
|
||||||
let directory_crc = CRC.checksum(directory.as_bytes());
|
(directory_crc as u64) << 32 | (filename_crc as u64)
|
||||||
let filename_crc = CRC.checksum(filename[1..filename.len()].as_bytes());
|
} else {
|
||||||
|
CRC.checksum(lowercase.as_bytes()) as u64
|
||||||
(directory_crc as u64) << 32 | (filename_crc as u64)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: turn into traits?
|
// TODO: turn into traits?
|
||||||
|
|
Loading…
Add table
Reference in a new issue