From f30f1f5372d25bb3d4c16b79ac206a2461c36f51 Mon Sep 17 00:00:00 2001 From: Kate Goldenring Date: Wed, 7 Jun 2023 12:53:50 -0700 Subject: [PATCH] Check for execution path to see if is a brew installation Signed-off-by: Kate Goldenring --- crates/common/src/data_dir.rs | 9 +++++---- crates/plugins/src/store.rs | 10 ++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/crates/common/src/data_dir.rs b/crates/common/src/data_dir.rs index 62b6f9de4..1d6fc8a49 100644 --- a/crates/common/src/data_dir.rs +++ b/crates/common/src/data_dir.rs @@ -18,11 +18,12 @@ pub fn default_data_dir() -> Result { /// Get the package manager specific data directory fn package_manager_data_dir() -> Option { 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 diff --git a/crates/plugins/src/store.rs b/crates/plugins/src/store.rs index cfc8977eb..7731e70cf 100644 --- a/crates/plugins/src/store.rs +++ b/crates/plugins/src/store.rs @@ -25,10 +25,12 @@ impl PluginStore { } pub fn try_default() -> Result { - 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.