mirror of
https://github.com/jht5945/rust_util.git
synced 2025-12-27 07:30:05 +08:00
26 lines
687 B
Rust
26 lines
687 B
Rust
use std::{
|
|
io::{ self, Error, ErrorKind },
|
|
process::Command,
|
|
};
|
|
|
|
pub fn run_command_and_wait(cmd: &mut Command) -> io::Result<()> {
|
|
cmd.spawn()?.wait()?;
|
|
Ok(())
|
|
}
|
|
|
|
pub fn extract_package_and_wait(dir: &str, file_name: &str) -> io::Result<()> {
|
|
let mut cmd: Command;
|
|
if file_name.ends_with(".zip") {
|
|
cmd = Command::new("unzip");
|
|
} else if file_name.ends_with(".tar.gz") {
|
|
cmd = Command::new("tar");
|
|
cmd.arg("-xzvf");
|
|
} else {
|
|
let m: &str = &format!("Unknown file type: {}", file_name);
|
|
return Err(Error::new(ErrorKind::Other, m));
|
|
}
|
|
cmd.arg(file_name).current_dir(dir);
|
|
run_command_and_wait(&mut cmd)
|
|
}
|
|
|