Name update
This commit is contained in:
@@ -54,7 +54,10 @@ pub struct WimPatcher {
|
||||
impl WimPatcher {
|
||||
#[must_use]
|
||||
pub fn new(smb_host: String, smb_share: String) -> Self {
|
||||
Self { smb_host, smb_share }
|
||||
Self {
|
||||
smb_host,
|
||||
smb_share,
|
||||
}
|
||||
}
|
||||
|
||||
/// Apply WinPE patches to `boot.wim` inside `extracted_iso_dir`. Returns
|
||||
@@ -72,31 +75,40 @@ impl WimPatcher {
|
||||
|
||||
let work = match tempfile::tempdir() {
|
||||
Ok(d) => d,
|
||||
Err(e) => return WinPatchState::Failed { reason: format!("tempdir: {e}") },
|
||||
Err(e) => {
|
||||
return WinPatchState::Failed {
|
||||
reason: format!("tempdir: {e}"),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Stage the two files we want present at /Windows/System32/.
|
||||
let staging = work.path().join("stage/Windows/System32");
|
||||
if let Err(e) = std::fs::create_dir_all(&staging) {
|
||||
return WinPatchState::Failed { reason: format!("staging mkdir: {e}") };
|
||||
return WinPatchState::Failed {
|
||||
reason: format!("staging mkdir: {e}"),
|
||||
};
|
||||
}
|
||||
if let Err(e) = std::fs::write(staging.join("winpeshl.ini"), WINPESHL_INI) {
|
||||
return WinPatchState::Failed { reason: format!("write winpeshl.ini: {e}") };
|
||||
return WinPatchState::Failed {
|
||||
reason: format!("write winpeshl.ini: {e}"),
|
||||
};
|
||||
}
|
||||
let startnet = render_startnet(&self.smb_host, &self.smb_share);
|
||||
if let Err(e) = std::fs::write(staging.join("startnet.cmd"), startnet) {
|
||||
return WinPatchState::Failed { reason: format!("write startnet.cmd: {e}") };
|
||||
return WinPatchState::Failed {
|
||||
reason: format!("write startnet.cmd: {e}"),
|
||||
};
|
||||
}
|
||||
|
||||
// Build a wimlib update command file:
|
||||
// add <stage>/Windows/System32 /Windows/System32
|
||||
let update_file = work.path().join("update.cmd");
|
||||
let update_cmd = format!(
|
||||
"add \"{}\" \"/Windows/System32\"\n",
|
||||
staging.display()
|
||||
);
|
||||
let update_cmd = format!("add \"{}\" \"/Windows/System32\"\n", staging.display());
|
||||
if let Err(e) = std::fs::write(&update_file, update_cmd) {
|
||||
return WinPatchState::Failed { reason: format!("write update.cmd: {e}") };
|
||||
return WinPatchState::Failed {
|
||||
reason: format!("write update.cmd: {e}"),
|
||||
};
|
||||
}
|
||||
|
||||
// Run wimlib-imagex update against image index 2 (WinPE).
|
||||
@@ -120,7 +132,9 @@ impl WimPatcher {
|
||||
String::from_utf8_lossy(&o.stderr)
|
||||
),
|
||||
},
|
||||
Err(e) => WinPatchState::Failed { reason: format!("spawn wimlib-imagex: {e}") },
|
||||
Err(e) => WinPatchState::Failed {
|
||||
reason: format!("spawn wimlib-imagex: {e}"),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,7 +147,9 @@ fn which(cmd: &str) -> Option<PathBuf> {
|
||||
let paths = std::env::var_os("PATH")?;
|
||||
for dir in std::env::split_paths(&paths) {
|
||||
let p = dir.join(cmd);
|
||||
if p.is_file() { return Some(p); }
|
||||
if p.is_file() {
|
||||
return Some(p);
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
@@ -174,7 +190,11 @@ fn render_startnet(host: &str, share: &str) -> String {
|
||||
)
|
||||
.unwrap();
|
||||
s.push_str(":havenet\r\n");
|
||||
writeln!(s, "echo Mapping install media from \\\\{host}\\{share}...\r").unwrap();
|
||||
writeln!(
|
||||
s,
|
||||
"echo Mapping install media from \\\\{host}\\{share}...\r"
|
||||
)
|
||||
.unwrap();
|
||||
writeln!(
|
||||
s,
|
||||
":mapshare\r\nnet use Z: \\\\{host}\\{share} /user:guest \"\" /persistent:no && goto mapped\r\n\
|
||||
@@ -205,6 +225,23 @@ mod tests {
|
||||
assert!(s.contains("setup.exe"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn startnet_primes_workstation_and_surfaces_mapping_errors() {
|
||||
let s = render_startnet("10.0.0.5", "win11");
|
||||
assert!(
|
||||
s.contains("net start Workstation"),
|
||||
"WinPE should explicitly start the SMB client before net use:\n{s}"
|
||||
);
|
||||
let net_use_line = s
|
||||
.lines()
|
||||
.find(|line| line.contains("net use Z:"))
|
||||
.expect("net use line");
|
||||
assert!(
|
||||
!net_use_line.contains(">nul"),
|
||||
"net use errors must remain visible in WinPE console: {net_use_line}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn patcher_reports_wimlib_missing_gracefully() {
|
||||
// We don't assume wimlib is present in CI; this checks the missing
|
||||
|
||||
Reference in New Issue
Block a user