Skip to content

Commit 6c7019b

Browse files
authored
refactor: replace dirs crate with etcetera (#736)
I recently learned that [`dirs`](https://crates.io/crates/dirs) depends on [`option-ext`](https://crates.io/crates/option-ext) via [`dir-sys`](https://crates.io/crates/dirs-sys) (as of `dir-sys` 0.4.1 that came in as part of `dirs` 5.0.1), which is MPL 2.0 licensed. [It does not appear that the author is interested reconsidering their stance on licensing](dirs-dev/dirs-sys-rs#21 (comment)), which unfortunately creates some complications for projects under the CNCF umbrella (as well as many corporate projects), and so I thought I would propose switching `dirs` out for `etcetera` since it is MIT or Apache 2.0 licensed. As you can see from the linked thread, this is a fairly common limitation for adoption, so in the interest of enabling further adoption, I believe it would be in the best interest for `testcontainers-rs` to reconsider this dependency, especially considering how trivial it is to replace 🙂 FWIW, I have done testing on my end to ensure that the changes I'm proposing produce similar results under Mac OS and Linux, but since I don't have direct access to Windows I can't say with 100% certainty that they do though from reading through the code across both libraries, I feel fairly confident that they should. Signed-off-by: Joonas Bergius <joonas@bergi.us>
1 parent 3168f25 commit 6c7019b

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

testcontainers/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ bollard = { version = "0.17.0", features = ["ssl"] }
2121
bollard-stubs = "=1.45.0-rc.26.0.1"
2222
bytes = "1.6.0"
2323
conquer-once = { version = "0.4", optional = true }
24-
dirs = "5.0.1"
2524
docker_credential = "1.3.1"
2625
either = "1.12.0"
26+
etcetera = "0.8.0"
2727
futures = "0.3"
2828
log = "0.4"
2929
memchr = "2.7.2"

testcontainers/src/core/env/config.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{
44
str::FromStr,
55
};
66

7-
use dirs::{home_dir, runtime_dir};
7+
use etcetera::BaseStrategy;
88

99
use crate::core::env::GetEnvValue;
1010

@@ -62,7 +62,7 @@ struct TestcontainersProperties {
6262
#[cfg(feature = "properties-config")]
6363
impl TestcontainersProperties {
6464
async fn load() -> Option<Result<Self, ConfigurationError>> {
65-
let home_dir = dirs::home_dir()?;
65+
let home_dir = home_dir()?;
6666
let properties_path = home_dir.join(TESTCONTAINERS_PROPERTIES);
6767

6868
let content = tokio::fs::read(properties_path).await.ok()?;
@@ -195,6 +195,14 @@ fn validate_path(path: String) -> Option<String> {
195195
}
196196
}
197197

198+
fn home_dir() -> Option<PathBuf> {
199+
etcetera::home_dir().ok()
200+
}
201+
202+
fn runtime_dir() -> Option<PathBuf> {
203+
etcetera::choose_base_strategy().ok()?.runtime_dir()
204+
}
205+
198206
/// Read the Docker authentication configuration in the following order:
199207
///
200208
/// 1. `DOCKER_AUTH_CONFIG` environment variable, unmarshalling the string value from its JSON representation and using it as the Docker config.
@@ -210,7 +218,7 @@ where
210218
let mut path_to_config = match E::get_env_value("DOCKER_CONFIG").map(PathBuf::from) {
211219
Some(path_to_config) => path_to_config,
212220
None => {
213-
let home_dir = dirs::home_dir()?;
221+
let home_dir = home_dir()?;
214222
home_dir.join(DEFAULT_DOCKER_CONFIG_PATH)
215223
}
216224
};

0 commit comments

Comments
 (0)