aboutsummaryrefslogtreecommitdiff
path: root/.run/src
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-07-18 00:23:13 +0800
committer魏曹先生 <1992414357@qq.com>2026-07-18 00:23:13 +0800
commite938129acc6231b2224db793c7aa9d6f95f7d0bf (patch)
treed1e32095b761ccf50a58b5c59979fc0bcb0ca4b8 /.run/src
parent615b6c8964025f26856ce78af362d596c9f03593 (diff)
chore(package-all): replace system tar with native Rust extraction
Diffstat (limited to '.run/src')
-rw-r--r--.run/src/bin/package-all.rs28
-rw-r--r--.run/src/dependency_order.rs17
2 files changed, 29 insertions, 16 deletions
diff --git a/.run/src/bin/package-all.rs b/.run/src/bin/package-all.rs
index 1f1f50d..5d7cbbb 100644
--- a/.run/src/bin/package-all.rs
+++ b/.run/src/bin/package-all.rs
@@ -1,6 +1,8 @@
use std::path::{Path, PathBuf};
+use flate2::read::GzDecoder;
use serde::Deserialize;
+use tar::Archive;
use tools::{
dependency_order::find_workspace_root, eprintln_cargo_style, println_cargo_style,
run_cmd_capture_with_dir, wprintln_cargo_style,
@@ -230,20 +232,18 @@ fn main() {
std::fs::create_dir_all(&target_dir)
.unwrap_or_else(|e| panic!("failed to create {}: {e}", target_dir.display()));
- // Extract using tar + gzip
- let extract_cmd = format!(
- "tar -xzf \"{}\" -C \"{}\"",
- path.display(),
- target_dir.display()
- );
- let extract_ok = std::process::Command::new("sh")
- .arg("-c")
- .arg(&extract_cmd)
- .status()
- .expect("failed to run tar");
-
- if !extract_ok.success() {
- eprintln_cargo_style!("Failed to extract {}", fname);
+ // Extract using flate2 + tar (cross-platform)
+ let file = match std::fs::File::open(&path) {
+ Ok(f) => f,
+ Err(e) => {
+ eprintln_cargo_style!("Failed to open {}: {e}", path.display());
+ continue;
+ }
+ };
+ let decoder = GzDecoder::new(file);
+ let mut archive = Archive::new(decoder);
+ if let Err(e) = archive.unpack(&target_dir) {
+ eprintln_cargo_style!("Failed to extract {}: {e}", fname);
continue;
}
diff --git a/.run/src/dependency_order.rs b/.run/src/dependency_order.rs
index 99317ae..145bdbd 100644
--- a/.run/src/dependency_order.rs
+++ b/.run/src/dependency_order.rs
@@ -1,5 +1,5 @@
use std::collections::{HashMap, HashSet};
-use std::path::PathBuf;
+use std::path::{Path, PathBuf};
/// Parse Cargo.toml content and return dependency names that start with `prefix`.
fn parse_mingling_deps(content: &str, prefix: &str) -> Vec<String> {
@@ -119,10 +119,23 @@ fn topological_sort(
result
}
+/// Strip the `\\?\` prefix that `std::fs::canonicalize` may add on Windows.
+fn strip_verbatim_prefix(p: &Path) -> PathBuf {
+ let s = p.to_string_lossy();
+ let s_ref: &str = &s;
+ if let Some(rest) = s_ref.strip_prefix("\\\\?\\") {
+ PathBuf::from(rest)
+ } else {
+ p.to_path_buf()
+ }
+}
+
/// Find the workspace root by looking for a Cargo.toml with `[workspace]` members.
/// Starts from `start` and walks up the directory tree.
pub fn find_workspace_root(start: &std::path::Path) -> Option<PathBuf> {
- let mut current = Some(std::fs::canonicalize(start).unwrap_or_else(|_| start.to_path_buf()));
+ let mut current = Some(strip_verbatim_prefix(
+ &std::fs::canonicalize(start).unwrap_or_else(|_| start.to_path_buf()),
+ ));
while let Some(dir) = current {
let members = get_workspace_members(&dir);
if !members.is_empty() {