mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-29 20:27:05 -06:00
Libraries: a User Defined library file whose reading panics is skipped
The desktop app reads the User Defined swatch and graphic style libraries while it creates its window: set_user_dir runs Libraries::rescan, which read and parsed every file in the folder outside the panic guard that commands have. A parser bug that panicked on one file stopped the app before its window appeared, at every launch while the file stayed in the folder. rescan now reads and parses each file inside guard::catch_panic and skips a file whose reading panics, as it skips one that can't be read. The other libraries are listed.
This commit is contained in:
@@ -152,13 +152,16 @@ impl<L: LibraryFile> Libraries<L> {
|
||||
}
|
||||
|
||||
/// Re-read the library files of the user library folder (unreadable ones are skipped). The
|
||||
/// folder is the app's own: automation roots don't apply to it ([`crate::file_access`]).
|
||||
/// folder is the app's own: automation roots don't apply to it ([`crate::file_access`]). Each
|
||||
/// file is read inside [`crate::guard::catch_panic`], and a file whose reading panics is
|
||||
/// skipped too.
|
||||
pub fn rescan(&mut self) {
|
||||
self.extra.retain(|e| e.info.category != "user");
|
||||
let Some(dir) = self.user_dir.clone() else { return };
|
||||
for path in library_files(&dir, L::EXTS) {
|
||||
let file = file_name(&path);
|
||||
let Some(lib) = crate::file_access::unconfined(|| read_file(&path)).ok().and_then(|b| L::read(&b, stem(&file)).ok()) else { continue };
|
||||
let read = || crate::file_access::unconfined(|| read_file(&path)).ok().and_then(|b| L::read(&b, stem(&file)).ok());
|
||||
let Some(lib) = crate::guard::catch_panic(read).ok().flatten() else { continue };
|
||||
let info = LibraryInfo { id: format!("user/{file}"), name: lib.name().to_string(), category: "user" };
|
||||
self.extra.push(Extra { info, path: Some(path), lib: Arc::new(lib) });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user