Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adds debug info to install reload + fix sh source #336

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 40 additions & 7 deletions installers/binstall/src/system/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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};

Expand All @@ -29,10 +29,41 @@ 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)
.arg(format!(". \"{}\"", shell.env_path_str(installer)?))
.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 +131,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