Skip to content

Commit

Permalink
fix: adds debug info to install reload + fix sh source
Browse files Browse the repository at this point in the history
  • Loading branch information
EverlastingBugstopper committed Mar 11, 2021
1 parent 9f5749c commit ee2bff8
Showing 1 changed file with 42 additions and 7 deletions.
49 changes: 42 additions & 7 deletions installers/binstall/src/system/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use std::fmt::Debug;
use std::fs;
use std::io::{self, Write};
use std::process::Command;
use std::{env, path::PathBuf};
use std::{env, path::PathBuf, str};

use crate::{Installer, InstallerError};

pub fn add_binary_to_path(installer: &Installer) -> Result<(), InstallerError> {
for shell in get_available_shells() {
let source_cmd = shell.source_string(installer)?;
let source_cmd = format!(". \"{}\"", shell.env_path_str(installer)?);
let script = shell.env_script();
script.write(installer)?;

Expand All @@ -29,10 +29,43 @@ pub fn add_binary_to_path(installer: &Installer) -> Result<(), InstallerError> {
// run the `source env` command so folks don't need to
// re-source their shell. the binary will be available for
// execution immediately after installation.
let _ = Command::new(shell.name())
let shell_reload_output = Command::new(shell.name())
.arg("-c")
.arg(&source_cmd)
.output();

if let Ok(output) = shell_reload_output {
if output.status.success() {
tracing::debug!("Successfully sourced \"{}\".", shell.name());
} else {
if let Some(status_code) = output.status.code() {
tracing::error!(
"could not source {}. failed with code {:?}",
shell.name(),
status_code
);
if !output.stderr.is_empty() {
if let Ok(stderr) = str::from_utf8(&output.stderr) {
tracing::error!("stderr: {}", stderr);
} else {
tracing::error!("stderr contained invalid UTF-8 sequence");
}
}

if !output.stdout.is_empty() {
if let Ok(stdout) = str::from_utf8(&output.stdout) {
tracing::error!("stdout: {}", stdout)
} else {
tracing::error!("stdout contained invalid UTF-8 sequence");
}
}
} else {
tracing::error!("source command process terminated by signal");
}
}
} else {
tracing::error!("source command failed: {:?}", shell_reload_output);
}
}

Ok(())
Expand Down Expand Up @@ -100,11 +133,13 @@ trait UnixShell: Debug {
}
}

fn env_path_str(&self, installer: &Installer) -> Result<String, InstallerError> {
Ok(format!("\"{}/env\"", installer.get_base_dir_path()?))
}

fn source_string(&self, installer: &Installer) -> Result<String, InstallerError> {
Ok(format!(
r#"source "{}/env""#,
installer.get_base_dir_path()?
))
let env_path = self.env_path_str(installer)?;
Ok(format!("source {}", &env_path))
}
}

Expand Down

0 comments on commit ee2bff8

Please sign in to comment.