refactor: more precise path handling on windows

This commit is contained in:
zhom
2025-07-28 18:14:25 +04:00
parent 6f80b5ac13
commit 1298a5ff11
2 changed files with 24 additions and 8 deletions
+3 -3
View File
@@ -13,9 +13,9 @@ impl EmbeddedTemplate {
/// Get the embedded template files
pub fn new() -> Self {
Self {
cargo_toml: include_str!("./template/crg.toml"),
build_rs: include_str!("./template/build.rs"),
main_rs: include_str!("./template/src/main.rs"),
cargo_toml: include_str!("template/crg.toml"),
build_rs: include_str!("template/build.rs"),
main_rs: include_str!("template/src/main.rs"),
}
}
+21 -5
View File
@@ -89,13 +89,29 @@ fn extract_application(app_dir: &Path) -> Result<()> {
for i in 0..archive.len() {
let mut file = archive.by_index(i).context("Failed to read zip entry")?;
// Normalize the file path for the current platform
// Zip files use forward slashes, but we need proper path separators for the OS
// Get the file name from the zip entry
let file_name = file.name();
// Use Path::new to properly handle path separators across platforms
let normalized_path = Path::new(file_name);
let outpath = app_dir.join(normalized_path);
// Skip entries with invalid characters or paths
if file_name.is_empty() || file_name.contains('\0') {
continue;
}
// Normalize path separators for the current platform
// Zip files always use forward slashes, convert to platform-specific separators
let normalized_name = if cfg!(windows) {
file_name.replace('/', "\\")
} else {
file_name.to_string()
};
// Create the output path using platform-specific path handling
let outpath = app_dir.join(&normalized_name);
// Ensure the path is within the app directory (security check)
if !outpath.starts_with(app_dir) {
continue;
}
if file_name.ends_with('/') {
// Directory