Refactor Result handling.
This commit is contained in:
parent
95f9897766
commit
16b3a09558
3 changed files with 18 additions and 13 deletions
|
|
@ -34,15 +34,15 @@ fn install_nix_profile(
|
|||
profile_name: &Path,
|
||||
) -> Result<process::ExitStatus> {
|
||||
DirBuilder::new().recursive(true).create(profile_dir)?;
|
||||
process::Command::new("nix-env")
|
||||
let status = process::Command::new("nix-env")
|
||||
.arg("--profile")
|
||||
.arg(profile_dir.join(profile_name))
|
||||
.arg("--set")
|
||||
.arg(&store_path.store_path)
|
||||
.stdout(process::Stdio::inherit())
|
||||
.stderr(process::Stdio::inherit())
|
||||
.status()
|
||||
.map_err(anyhow::Error::from)
|
||||
.status()?;
|
||||
Ok(status)
|
||||
}
|
||||
|
||||
fn create_gcroot(gcroot_path: &str, profile_path: &Path) -> Result<()> {
|
||||
|
|
@ -92,7 +92,7 @@ fn parse_nix_build_output(output: String) -> Result<StorePath> {
|
|||
}
|
||||
|
||||
fn run_nix_build(flake_uri: &str, flake_attr: &str) -> Result<process::Output> {
|
||||
process::Command::new("nix")
|
||||
let output = process::Command::new("nix")
|
||||
.arg("build")
|
||||
.arg(format!("{flake_uri}#{flake_attr}"))
|
||||
.arg("--json")
|
||||
|
|
@ -100,6 +100,6 @@ fn run_nix_build(flake_uri: &str, flake_attr: &str) -> Result<process::Output> {
|
|||
// so we inherit and output stderr directly to the terminal, but we
|
||||
// capture stdout as the result of this call
|
||||
.stderr(process::Stdio::inherit())
|
||||
.output()
|
||||
.map_err(anyhow::Error::from)
|
||||
.output()?;
|
||||
Ok(output)
|
||||
}
|
||||
|
|
|
|||
12
src/lib.rs
12
src/lib.rs
|
|
@ -66,13 +66,15 @@ fn create_link(to: &Path, from: &Path) -> Result<()> {
|
|||
anyhow::bail!("File exists and is no link!");
|
||||
}
|
||||
}
|
||||
unix::fs::symlink(to, from).map_err(anyhow::Error::from)
|
||||
unix::fs::symlink(to, from)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn remove_link(from: &Path) -> Result<()> {
|
||||
log::info!("Removing symlink: {}", from.display());
|
||||
if from.is_symlink() {
|
||||
fs::remove_file(from).map_err(anyhow::Error::from)
|
||||
fs::remove_file(from)?;
|
||||
Ok(())
|
||||
} else {
|
||||
anyhow::bail!("Not a symlink!");
|
||||
}
|
||||
|
|
@ -80,12 +82,14 @@ fn remove_link(from: &Path) -> Result<()> {
|
|||
|
||||
fn remove_file(from: &Path) -> Result<()> {
|
||||
log::info!("Removing file: {}", from.display());
|
||||
fs::remove_file(from).map_err(anyhow::Error::from)
|
||||
fs::remove_file(from)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn remove_dir(from: &Path) -> Result<()> {
|
||||
log::info!("Removing directory: {}", from.display());
|
||||
fs::remove_dir(from).map_err(anyhow::Error::from)
|
||||
fs::remove_dir(from)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn compose<A, B, C, G, F>(f: F, g: G) -> impl Fn(A) -> C
|
||||
|
|
|
|||
|
|
@ -226,11 +226,12 @@ fn invoke_remote_script(
|
|||
if use_remote_sudo {
|
||||
cmd.arg("sudo");
|
||||
}
|
||||
cmd.arg(format!("{store_path}/bin/{script_name}"))
|
||||
let status = cmd
|
||||
.arg(format!("{store_path}/bin/{script_name}"))
|
||||
.stdout(process::Stdio::inherit())
|
||||
.stderr(process::Stdio::inherit())
|
||||
.status()
|
||||
.map_err(anyhow::Error::from)
|
||||
.status()?;
|
||||
Ok(status)
|
||||
}
|
||||
|
||||
fn check_root() -> Result<()> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue