From 1371747b59e99f817f8615496cec705c0f8ed584 Mon Sep 17 00:00:00 2001 From: Nyannyacha Date: Sun, 28 Jan 2024 12:00:46 +0000 Subject: [PATCH 1/2] fix(sb_graph): checking whether the path is relative and unix format while reading module path (cherry picked from commit 999f625653b456d2ddf049f19ff147c5a3d27095) --- crates/sb_graph/lib.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/sb_graph/lib.rs b/crates/sb_graph/lib.rs index 273980727..8327b666c 100644 --- a/crates/sb_graph/lib.rs +++ b/crates/sb_graph/lib.rs @@ -134,21 +134,34 @@ pub struct ExtractEszipPayload { pub folder: PathBuf, } +fn ensure_unix_relative_path(path: &Path) -> &Path { + assert!(path.is_relative()); + assert!(!path.to_string_lossy().starts_with("\\")); + path +} + fn create_module_path(global_specifier: &str, entry_path: &Path, output_folder: &Path) -> PathBuf { let cleaned_specifier = global_specifier.replace(entry_path.to_str().unwrap(), ""); let module_path = PathBuf::from(cleaned_specifier); if let Some(parent) = module_path.parent() { if parent.parent().is_some() { - let output_folder_and_mod_folder = - output_folder.join(parent.strip_prefix("/").unwrap()); + let output_folder_and_mod_folder = output_folder.join( + parent + .strip_prefix("/") + .unwrap_or_else(|_| ensure_unix_relative_path(parent)), + ); if !output_folder_and_mod_folder.exists() { create_dir_all(&output_folder_and_mod_folder).unwrap(); } } } - output_folder.join(module_path.strip_prefix("/").unwrap()) + output_folder.join( + module_path + .strip_prefix("/") + .unwrap_or_else(|_| ensure_unix_relative_path(&module_path)), + ) } async fn extract_modules( From 5fa91e06e7f11f11c26a70596909a4385253f518 Mon Sep 17 00:00:00 2001 From: Nyannyacha Date: Sun, 28 Jan 2024 12:39:35 +0000 Subject: [PATCH 2/2] stamp: make clippy happy (cherry picked from commit 3ad82a6bb12dbb9c95e98f4f51b0c7491d60deca) --- crates/sb_graph/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/sb_graph/lib.rs b/crates/sb_graph/lib.rs index 8327b666c..ce8a8fabb 100644 --- a/crates/sb_graph/lib.rs +++ b/crates/sb_graph/lib.rs @@ -136,7 +136,7 @@ pub struct ExtractEszipPayload { fn ensure_unix_relative_path(path: &Path) -> &Path { assert!(path.is_relative()); - assert!(!path.to_string_lossy().starts_with("\\")); + assert!(!path.to_string_lossy().starts_with('\\')); path }