Skip to content

Commit 39e1304

Browse files
committed
fix: properly figure out what type a path is
1 parent 1cb4510 commit 39e1304

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

src/navdata_updater/src/download/downloader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl NavdataDownloader {
158158
));
159159
return;
160160
}
161-
161+
162162
let path = PathBuf::from(format!("\\work/navdata/{}", folder));
163163
// If the directory exists, delete it
164164
if util::path_exists(&path) {

src/navdata_updater/src/download/zip_handler.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ impl<R: io::Read + io::Seek> ZipFileHandler<R> {
4444
None => continue,
4545
};
4646

47+
// Check how many times "." appears in the file name
48+
let dot_count = outpath.to_str().unwrap_or_default().matches('.').count();
49+
// Skip if there are more than 1 "." in the file name (MSFS crashes if we try to extract these files for some reason)
50+
if dot_count > 1 {
51+
self.current_file_index += 1;
52+
continue;
53+
}
54+
4755
if (*file.name()).ends_with('/') {
4856
fs::create_dir_all(outpath).unwrap();
4957
} else {

src/navdata_updater/src/util.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,19 @@ pub fn get_path_type(path: &Path) -> PathType {
1515
if file_res.is_ok() {
1616
return PathType::File;
1717
}
18-
let dir_res = fs::read_dir(path);
19-
if dir_res.is_ok() {
20-
return PathType::Directory;
18+
let mut dir_res = match fs::read_dir(path) {
19+
Ok(dir_res) => dir_res,
20+
Err(_) => {
21+
return PathType::DoesNotExist;
22+
}
23+
};
24+
25+
let next = dir_res.next();
26+
27+
if next.is_some() {
28+
if next.unwrap().is_ok() {
29+
return PathType::Directory;
30+
}
2131
}
2232
PathType::DoesNotExist
2333
}
@@ -43,4 +53,4 @@ pub fn delete_folder_recursively(path: &Path) -> io::Result<()> {
4353
}
4454
fs::remove_dir(path)?;
4555
Ok(())
46-
}
56+
}

0 commit comments

Comments
 (0)