Skip to content

Commit

Permalink
chore: Replace dirs with etcetera
Browse files Browse the repository at this point in the history
Fixes bytecodealliance#303

Signed-off-by: Joonas Bergius <[email protected]>
  • Loading branch information
joonas committed Nov 18, 2024
1 parent 19339f1 commit c9ac18b
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 19 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ warg key new 127.0.0.1:8090
The new signing key will be stored in your operating system's key store and
used to sign package log entries when publishing to the registry.

[config_dir]: https://docs.rs/dirs/5.0.0/dirs/fn.config_dir.html
[cache_dir]: https://docs.rs/dirs/5.0.0/dirs/fn.cache_dir.html
[config_dir]: https://docs.rs/etcetera/0.8.0/etcetera/base_strategy/trait.BaseStrategy.html#tymethod.config_dir
[cache_dir]: https://docs.rs/etcetera/0.8.0/etcetera/base_strategy/trait.BaseStrategy.html#tymethod.cache_dir

### Improving The Documentation
<!-- TODO
Expand Down
31 changes: 21 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ rand = "0.8.5"
url = "2.5.0"
libc = "0.2.153"
itertools = "0.12.1"
dirs = "5.0.1"
etcetera = "0.8.0"
once_cell = "1.19.0"
walkdir = "2.4.0"
normpath = "1.1.1"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ warg key new --registry 127.0.0.1:8090
The new signing key will be stored in your operating system's key store and
used to sign package log entries when publishing to the registry.

[config_dir]: https://docs.rs/dirs/5.0.0/dirs/fn.config_dir.html
[cache_dir]: https://docs.rs/dirs/5.0.0/dirs/fn.cache_dir.html
[config_dir]: https://docs.rs/etcetera/0.8.0/etcetera/base_strategy/trait.BaseStrategy.html#tymethod.config_dir
[cache_dir]: https://docs.rs/etcetera/0.8.0/etcetera/base_strategy/trait.BaseStrategy.html#tymethod.cache_dir

### Publishing a package

Expand Down
2 changes: 1 addition & 1 deletion crates/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ tracing = { workspace = true }
itertools = { workspace = true }
wasmparser = { workspace = true }
wasm-compose = { workspace = true }
dirs = { workspace = true }
etcetera = { workspace = true }
once_cell = { workspace = true }
walkdir = { workspace = true }
normpath = { workspace = true }
Expand Down
13 changes: 11 additions & 2 deletions crates/client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use crate::{ClientError, RegistryUrl};
use anyhow::{anyhow, Context, Result};
use etcetera::BaseStrategy;
use indexmap::IndexSet;
use normpath::PathExt;
use once_cell::sync::Lazy;
Expand All @@ -12,8 +13,16 @@ use std::{
path::{Component, Path, PathBuf},
};

static CACHE_DIR: Lazy<Option<PathBuf>> = Lazy::new(dirs::cache_dir);
static CONFIG_DIR: Lazy<Option<PathBuf>> = Lazy::new(dirs::config_dir);
static CACHE_DIR: Lazy<Option<PathBuf>> = Lazy::new(|| {
etcetera::choose_base_strategy()
.ok()
.map(|strat| strat.cache_dir())
});
static CONFIG_DIR: Lazy<Option<PathBuf>> = Lazy::new(|| {
etcetera::choose_base_strategy()
.ok()
.map(|strat| strat.config_dir())
});
static CONFIG_FILE_NAME: &str = "warg-config.json";

fn find_warg_config(cwd: &Path) -> Option<PathBuf> {
Expand Down
5 changes: 4 additions & 1 deletion crates/client/src/keyring/flatfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use keyring::credential::{Credential, CredentialApi, CredentialBuilderApi};

use etcetera::BaseStrategy;
use std::fs::File;
use std::io::{Read, Write};
use std::path::PathBuf;
Expand All @@ -27,7 +28,9 @@ impl FlatfileCredentialBuilder {
/// Construct the credential builder, storing credentials in
/// `$XDG_CONFIG_HOME/warg/keyring`.
pub fn new() -> keyring::Result<Self> {
let dir = dirs::config_dir()
let dir = etcetera::choose_base_strategy()
.ok()
.map(|strat| strat.config_dir())
.ok_or(keyring::Error::NoEntry)?
.join("warg")
.join("keyring");
Expand Down

0 comments on commit c9ac18b

Please sign in to comment.