Skip to content

Commit

Permalink
feat: skip extraction error when running in systemd-nspawn
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Mar 18, 2024
1 parent 5f5b4d9 commit 2838c03
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,24 @@ pub fn extract_system_rootfs(path: &Path, total: u64, use_tarball: bool) -> Resu
fs::create_dir_all(&dist_dir)?;
}

if use_tarball {
extract_tar_xz(progress_bar.wrap_read(f), &dist_dir)?;
// detect if we are running in systemd-nspawn
// where /dev/console character device file cannot be created
// thus ignoring the error in extracting
let mut in_systemd_nspawn = false;
if let Ok(output) = std::process::Command::new("systemd-detect-virt").output() {
if let Ok("systemd-nspawn") = std::str::from_utf8(&output.stdout) {
in_systemd_nspawn = true;
}
}

let res = if use_tarball {
extract_tar_xz(progress_bar.wrap_read(f), &dist_dir)
} else {
extract_squashfs(path, &dist_dir, &progress_bar, total)?;
extract_squashfs(path, &dist_dir, &progress_bar, total)
};

if !in_systemd_nspawn {
res?
}

progress_bar.finish_and_clear();
Expand Down

0 comments on commit 2838c03

Please sign in to comment.