Symlink the entire release to preserve relative paths from bin/

This commit is contained in:
Michael Vines 2019-04-12 14:13:01 -07:00
parent 1e8f83a74a
commit bf4d5745c9
2 changed files with 19 additions and 14 deletions

View File

@ -246,14 +246,15 @@ fn get_update_manifest(
Ok(signed_update_manifest.manifest) Ok(signed_update_manifest.manifest)
} }
/// Bug the user if bin_dir is not in their PATH /// Bug the user if active_release_bin_dir is not in their PATH
fn check_env_path_for_bin_dir(config: &Config) { fn check_env_path_for_bin_dir(config: &Config) {
use std::env; use std::env;
let bin_dir = config.active_release_bin_dir();
let found = match env::var_os("PATH") { let found = match env::var_os("PATH") {
Some(paths) => env::split_paths(&paths).any(|path| { Some(paths) => env::split_paths(&paths).any(|path| {
if let Ok(path) = path.canonicalize() { if let Ok(path) = path.canonicalize() {
if path == *config.bin_dir() { if path == bin_dir {
return true; return true;
} }
} }
@ -265,7 +266,7 @@ fn check_env_path_for_bin_dir(config: &Config) {
if !found { if !found {
println!( println!(
"\nPlease update your PATH environment variable to include the solana programs:\n PATH=\"{}:$PATH\"\n", "\nPlease update your PATH environment variable to include the solana programs:\n PATH=\"{}:$PATH\"\n",
config.bin_dir().to_str().unwrap() bin_dir.to_str().unwrap()
); );
} }
} }
@ -284,7 +285,7 @@ pub fn init(
let mut modified_rcfiles = false; let mut modified_rcfiles = false;
let shell_export_string = format!( let shell_export_string = format!(
r#"export PATH="{}:$PATH""#, r#"export PATH="{}:$PATH""#,
config.bin_dir().to_str().unwrap() config.active_release_bin_dir().to_str().unwrap()
); );
if !no_modify_path { if !no_modify_path {
@ -362,7 +363,7 @@ pub fn init(
if modified_rcfiles { if modified_rcfiles {
println!( println!(
"\n{}\n {}\n", "\n{}\n {}\n",
style("Close and reopen your terminal to apply the PATH changes or run the following to use it now:").bold().blue(), style("Close and reopen your terminal to apply the PATH changes or run the following in your existing shell:").bold().blue(),
shell_export_string shell_export_string
); );
} else { } else {
@ -561,16 +562,16 @@ pub fn update(config_file: &str) -> Result<bool, String> {
Err(format!("Incompatible update target: {}", release_target))?; Err(format!("Incompatible update target: {}", release_target))?;
} }
let _ = fs::remove_dir_all(config.bin_dir()); let _ = fs::remove_dir_all(config.active_release_dir());
std::os::unix::fs::symlink( std::os::unix::fs::symlink(
release_dir.join("solana-release").join("bin"), release_dir.join("solana-release"),
config.bin_dir(), config.active_release_dir(),
) )
.map_err(|err| { .map_err(|err| {
format!( format!(
"Unable to symlink {:?} to {:?}: {}", "Unable to symlink {:?} to {:?}: {}",
release_dir, release_dir,
config.bin_dir(), config.active_release_dir(),
err err
) )
})?; })?;
@ -589,7 +590,7 @@ pub fn run(
) -> Result<(), String> { ) -> Result<(), String> {
let config = Config::load(config_file)?; let config = Config::load(config_file)?;
let full_program_path = config.bin_dir().join(program_name); let full_program_path = config.active_release_bin_dir().join(program_name);
if !full_program_path.exists() { if !full_program_path.exists() {
Err(format!( Err(format!(
"{} does not exist", "{} does not exist",

View File

@ -12,7 +12,7 @@ pub struct Config {
pub current_update_manifest: Option<UpdateManifest>, pub current_update_manifest: Option<UpdateManifest>,
pub update_poll_secs: u64, pub update_poll_secs: u64,
releases_dir: PathBuf, releases_dir: PathBuf,
bin_dir: PathBuf, active_release_dir: PathBuf,
} }
impl Config { impl Config {
@ -23,7 +23,7 @@ impl Config {
current_update_manifest: None, current_update_manifest: None,
update_poll_secs: 60, // check for updates once a minute update_poll_secs: 60, // check for updates once a minute
releases_dir: PathBuf::from(data_dir).join("releases"), releases_dir: PathBuf::from(data_dir).join("releases"),
bin_dir: PathBuf::from(data_dir).join("bin"), active_release_dir: PathBuf::from(data_dir).join("active_release"),
} }
} }
@ -56,8 +56,12 @@ impl Config {
.map_err(|err| format!("Unable to save {}: {:?}", config_file, err)) .map_err(|err| format!("Unable to save {}: {:?}", config_file, err))
} }
pub fn bin_dir(&self) -> &PathBuf { pub fn active_release_dir(&self) -> &PathBuf {
&self.bin_dir &self.active_release_dir
}
pub fn active_release_bin_dir(&self) -> PathBuf {
self.active_release_dir.join("bin")
} }
pub fn release_dir(&self, release_sha256: &str) -> PathBuf { pub fn release_dir(&self, release_sha256: &str) -> PathBuf {