Skip to content

Commit

Permalink
fix: Use fallback home directory detection in config commands.
Browse files Browse the repository at this point in the history
Use a standard wasmer install directory if the usual detection methods
fail.

Closes #3869 .
  • Loading branch information
theduke committed May 23, 2023
1 parent d6d3a4e commit 63ab31b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
13 changes: 9 additions & 4 deletions lib/cli-compiler/src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@ impl Config {
fn inner_execute(&self) -> Result<()> {
let key = "WASMER_DIR";
let wasmer_dir = env::var(key)
.or_else(|e| {
option_env!("WASMER_INSTALL_PREFIX")
.map(str::to_string)
.ok_or(e)
.ok()
.or_else(|| option_env!("WASMER_INSTALL_PREFIX").map(str::to_string))
.or_else(|| {
// Allowing deprecated function home_dir since it works fine,
// and will never be removed from std.
#[allow(deprecated)]
let dir = std::env::home_dir()?.join(".wasmer").to_str()?.to_string();

Some(dir)
})
.context(format!(
"failed to retrieve the {} environment variables",
Expand Down
14 changes: 10 additions & 4 deletions lib/cli/src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ impl Config {
self.inner_execute()
.context("failed to retrieve the wasmer config".to_string())
}

fn inner_execute(&self) -> Result<()> {
if let Some(s) = self.set.as_ref() {
return s.execute();
Expand All @@ -174,10 +175,15 @@ impl Config {

let key = "WASMER_DIR";
let wasmer_dir = env::var(key)
.or_else(|e| {
option_env!("WASMER_INSTALL_PREFIX")
.map(str::to_string)
.ok_or(e)
.ok()
.or_else(|| option_env!("WASMER_INSTALL_PREFIX").map(str::to_string))
.or_else(|| {
// Allowing deprecated function home_dir since it works fine,
// and will never be removed from std.
#[allow(deprecated)]
let dir = std::env::home_dir()?.join(".wasmer").to_str()?.to_string();

Some(dir)
})
.context(format!(
"failed to retrieve the {} environment variables",
Expand Down

0 comments on commit 63ab31b

Please sign in to comment.