Skip to content

Commit 833cbe8

Browse files
committed
fix: only remove file if its a file
1 parent f22d6c6 commit 833cbe8

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/wasm/src/util.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ use std::{fs, io, path::Path};
22

33
use navigation_database::util::{get_path_type, PathType};
44

5-
pub fn path_exists(path: &Path) -> bool { get_path_type(path) != PathType::DoesNotExist }
5+
pub fn path_exists(path: &Path) -> bool {
6+
get_path_type(path) != PathType::DoesNotExist
7+
}
68

79
pub fn delete_folder_recursively(path: &Path, batch_size: Option<usize>) -> io::Result<()> {
810
// Make sure we are deleting a directory (and in turn that it exists)
@@ -22,9 +24,11 @@ pub fn delete_folder_recursively(path: &Path, batch_size: Option<usize>) -> io::
2224
// After we have collected the entries, delete them
2325
for entry in entries {
2426
let path = entry.path();
25-
if get_path_type(&path) == PathType::Directory {
27+
let path_type = get_path_type(&path);
28+
29+
if path_type == PathType::Directory {
2630
delete_folder_recursively(&path, batch_size)?;
27-
} else {
31+
} else if path_type == PathType::File {
2832
fs::remove_file(&path)?;
2933
}
3034
}
@@ -42,4 +46,6 @@ pub fn delete_folder_recursively(path: &Path, batch_size: Option<usize>) -> io::
4246
Ok(())
4347
}
4448

45-
pub fn trim_null_terminator(s: &str) -> &str { s.trim_end_matches(char::from(0)) }
49+
pub fn trim_null_terminator(s: &str) -> &str {
50+
s.trim_end_matches(char::from(0))
51+
}

0 commit comments

Comments
 (0)