Skip to content

Commit 9c03e22

Browse files
committed
fix(cherrypick): implement some failsafes for copying
1 parent 631eb9e commit 9c03e22

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/wasm/src/download/downloader.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,13 @@ impl NavigationDataDownloader {
233233

234234
// Clear our task
235235
self.task.replace(None);
236+
237+
// Needs to be here so if download fails, you can try again
238+
self.download_status.replace(DownloadStatus::NoDownload);
236239
}
237240

238241
/// This must be called to clear the download status and reset the download
239242
pub fn acknowledge_download(&self) {
240-
self.download_status.replace(DownloadStatus::NoDownload);
241-
242243
self.reset_download();
243244
}
244245

src/wasm/src/util.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,21 @@ pub fn delete_folder_recursively(path: &Path, batch_size: Option<usize>) -> io::
2626
let path = entry.path();
2727
let path_type = get_path_type(&path);
2828

29+
if path.file_name().unwrap() == "" {
30+
eprintln!("[NAVIGRAPH]: Bugged entry");
31+
continue;
32+
}
33+
2934
if path_type == PathType::Directory {
3035
delete_folder_recursively(&path, batch_size)?;
3136
} else if path_type == PathType::File {
3237
fs::remove_file(&path)?;
33-
} else if let None = path.extension() {
34-
// There are edge cases where completely empty directories are created and can't be deleted. They get registered as "unknown" path type so we need to check if the path has an extension (which would tell us if it's a file or a directory), and if it doesn't, we delete it as a directory
35-
let _ = fs::remove_dir(&path); // this can fail silently, but we don't care since there also might be cases where a file literally doesn't exist
38+
} else if path.extension().is_none() {
39+
// There are edge cases where completely empty directories are created and can't be deleted. They get
40+
// registered as "unknown" path type so we need to check if the path has an extension (which would tell us
41+
// if it's a file or a directory), and if it doesn't, we delete it as a directory
42+
let _ = fs::remove_dir(&path); // this can fail silently, but we don't care since there also might be cases
43+
// where a file literally doesn't exist
3644
}
3745
}
3846
// Check if the directory is empty. If it is, delete it
@@ -59,12 +67,23 @@ pub fn copy_files_to_folder(from: &Path, to: &Path) -> io::Result<()> {
5967
// Create the directory we are copying to
6068
fs::create_dir(to)?;
6169
// Collect the entries that we will copy
62-
let entries = fs::read_dir(from)?.collect::<Result<Vec<_>, _>>()?;
70+
let entries = fs::read_dir(from)?;
71+
6372
// Copy the entries
6473
for entry in entries {
74+
let Ok(entry) = entry else {
75+
eprintln!("[NAVIGRAPH]: Bugged entry");
76+
continue;
77+
};
78+
6579
let path = entry.path();
6680
let path_type = get_path_type(&path);
6781

82+
if path.file_name().unwrap() == "" {
83+
eprintln!("[NAVIGRAPH]: Bugged entry");
84+
continue;
85+
}
86+
6887
if path_type == PathType::Directory {
6988
let new_dir = to.join(path.file_name().unwrap());
7089
fs::create_dir(&new_dir)?;

0 commit comments

Comments
 (0)