Skip to content

Commit

Permalink
Check for execution path to see if is a brew installation
Browse files Browse the repository at this point in the history
Signed-off-by: Kate Goldenring <[email protected]>
  • Loading branch information
kate-goldenring committed Jun 7, 2023
1 parent 2c4c404 commit f30f1f5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
9 changes: 5 additions & 4 deletions crates/common/src/data_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ pub fn default_data_dir() -> Result<PathBuf> {
/// Get the package manager specific data directory
fn package_manager_data_dir() -> Option<PathBuf> {
if let Ok(brew_prefix) = std::env::var("HOMEBREW_PREFIX") {
let data_dir = Path::new(&brew_prefix).join("var").join("spin");

if data_dir.is_dir() {
if std::env::current_exe()
.map(|p| p.starts_with(&brew_prefix))
.unwrap_or(false)
{
let data_dir = Path::new(&brew_prefix).join("etc").join("fermyon-spin");
return Some(data_dir);
// TODO: check if they also have plugins in non-brew default dir and warn
}
}
None
Expand Down
10 changes: 6 additions & 4 deletions crates/plugins/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ impl PluginStore {
}

pub fn try_default() -> Result<Self> {
if let Ok(test_dir) = std::env::var("TEST_PLUGINS_DIRECTORY") {
return Ok(Self::new(PathBuf::from(test_dir)));
}
Ok(Self::new(default_data_dir()?.join("plugins")))
let data_dir = if let Ok(test_dir) = std::env::var("TEST_PLUGINS_DIRECTORY") {
PathBuf::from(test_dir).join("spin")
} else {
default_data_dir()?
};
Ok(Self::new(data_dir.join("plugins")))
}

/// Gets the path to where Spin plugin are installed.
Expand Down

0 comments on commit f30f1f5

Please sign in to comment.