Allow opening files/dirs using short name

This commit is contained in:
Rafał Harabień 2018-05-31 00:23:32 +02:00
parent 7355ac462c
commit 9f5f070955
2 changed files with 9 additions and 5 deletions

View File

@ -105,7 +105,7 @@ impl <'a, 'b> Dir<'a, 'b> {
for r in self.iter() {
let e = r?;
// compare name ignoring case
if e.file_name().eq_ignore_ascii_case(name) {
if e.file_name().eq_ignore_ascii_case(name) || e.short_file_name().eq_ignore_ascii_case(name) {
return Ok(e);
}
if let Some(ref mut gen) = short_name_gen {

View File

@ -123,6 +123,8 @@ fn test_get_dir_by_path(fs: FileSystem) {
let root_names = root_dir2.iter().map(|r| r.unwrap().file_name()).collect::<Vec<String>>();
let root_names2 = root_dir.iter().map(|r| r.unwrap().file_name()).collect::<Vec<String>>();
assert_eq!(root_names, root_names2);
root_dir.open_dir("VERY-L~1").unwrap();
}
#[test]
@ -147,10 +149,12 @@ fn test_get_file_by_path(fs: FileSystem) {
file.read_to_end(&mut buf).unwrap();
assert_eq!(str::from_utf8(&buf).unwrap(), TEST_TEXT);
// let mut file = root_dir.open_file("very-long-dir-name/very-long-file-name.txt").unwrap();
// let mut buf = Vec::new();
// file.read_to_end(&mut buf).unwrap();
// assert_eq!(str::from_utf8(&buf).unwrap(), TEST_TEXT);
let mut file = root_dir.open_file("very-long-dir-name/very-long-file-name.txt").unwrap();
let mut buf = Vec::new();
file.read_to_end(&mut buf).unwrap();
assert_eq!(str::from_utf8(&buf).unwrap(), TEST_TEXT);
root_dir.open_file("VERY-L~1/VERY-L~1.TXT").unwrap();
}
#[test]