forked from fermyon/spin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request fermyon#1494 from kate-goldenring/brew
Conditionally use Homebrew location for Spin plugins and templates
- Loading branch information
Showing
6 changed files
with
43 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//! Resolves Spin's default data directory paths | ||
use anyhow::{anyhow, Result}; | ||
use std::path::{Path, PathBuf}; | ||
|
||
/// Return the default data directory for Spin | ||
pub fn default_data_dir() -> Result<PathBuf> { | ||
if let Some(pkg_mgr_dir) = package_manager_data_dir() { | ||
return Ok(pkg_mgr_dir); | ||
} | ||
|
||
let data_dir = dirs::data_local_dir() | ||
.or_else(|| dirs::home_dir().map(|p| p.join(".spin"))) | ||
.ok_or_else(|| anyhow!("Unable to get local data directory or home directory"))?; | ||
Ok(data_dir.join("spin")) | ||
} | ||
|
||
/// Get the package manager specific data directory | ||
fn package_manager_data_dir() -> Option<PathBuf> { | ||
if let Ok(brew_prefix) = std::env::var("HOMEBREW_PREFIX") { | ||
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); | ||
} | ||
} | ||
None | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,6 @@ | |
// - Code should have at least 2 dependents | ||
|
||
pub mod arg_parser; | ||
pub mod data_dir; | ||
pub mod sha256; | ||
pub mod sloth; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters