Skip to content

Commit be694b3

Browse files
committed
wip: add func to get path type
this is because we can't access file metadata in the sim :(
1 parent 1ed6331 commit be694b3

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Sources/Code/WASM/navdata_updater/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
mod dispatcher;
22
mod download;
3+
mod util;
34

45
#[msfs::gauge(name=navdata_updater)]
56
async fn navdata_updater(mut gauge: msfs::Gauge) -> Result<(), Box<dyn std::error::Error>> {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use std::fs;
2+
use std::io;
3+
use std::path::Path;
4+
5+
#[derive(PartialEq, Eq)]
6+
pub enum PathType {
7+
File,
8+
Directory,
9+
DoesNotExist,
10+
}
11+
12+
/// We aren't able to get file metadata in the sim so we can't use some of the standard library file system functions (like is_dir, exists, and some others)
13+
pub fn get_path_type(path: &Path) -> PathType {
14+
let file_res = fs::File::open(path);
15+
if file_res.is_ok() {
16+
return PathType::File;
17+
}
18+
let dir_res = fs::read_dir(path);
19+
if dir_res.is_ok() {
20+
return PathType::Directory;
21+
}
22+
PathType::DoesNotExist
23+
}

0 commit comments

Comments
 (0)