-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move templates and plugins shared data dir methods to common crate
Signed-off-by: Kate Goldenring <kate.goldenring@fermyon.com>
- Loading branch information
1 parent
de2d1a8
commit 8c961f7
Showing
6 changed files
with
40 additions
and
38 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,29 @@ | ||
//! 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") { | ||
let data_dir = Path::new(&brew_prefix).join("var").join("spin"); | ||
|
||
if data_dir.is_dir() { | ||
return Some(data_dir); | ||
// TODO: check if they also have plugins in non-brew default dir and warn | ||
} | ||
} | ||
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