Skip to content

Commit

Permalink
Drop MPL licensed dependency dirs-sys
Browse files Browse the repository at this point in the history
Get state dir from env variables instead
  • Loading branch information
pacak committed Jan 21, 2024
1 parent de229ce commit d5b2278
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ tokio = { version = "1", features = [ "process", "io-util", "macros" ] }
tokio-pipe = "0.2.8"

once_cell = "1.8.0"
dirs = "5.0.0"

openssh-mux-client = { version = "0.17.0", optional = true }

Expand Down
26 changes: 23 additions & 3 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,32 @@ use std::process::Stdio;
use std::str;
use std::{fs, io};

use dirs::state_dir;
use once_cell::sync::OnceCell;
use tempfile::{Builder, TempDir};
use tokio::process;

#[cfg(not(windows))]
fn state_dir() -> Option<PathBuf> {
fn get_absolute_path(path: OsString) -> Option<PathBuf> {
let path = PathBuf::from(path);
path.is_absolute().then_some(path)
}

#[allow(deprecated)]
if let Some(xdg) = std::env::var_os("XDG_STATE_HOME") {
get_absolute_path(xdg)
} else if let Some(home) = std::env::home_dir() {
Some(get_absolute_path(home.into())?.join(".local/state"))
} else {
None
}
}

#[cfg(windows)]
fn state_dir() -> Option<PathBuf> {
None
}

/// The returned `&'static Path` can be coreced to any lifetime.
fn get_default_control_dir<'a>() -> Result<&'a Path, Error> {
static DEFAULT_CONTROL_DIR: OnceCell<Option<Box<Path>>> = OnceCell::new();
Expand Down Expand Up @@ -157,10 +178,9 @@ impl SessionBuilder {
/// Set the directory in which the temporary directory containing the control socket will
/// be created.
///
/// If not set, openssh will try to use [`dirs::state_dir`] and fallback to
/// If not set, openssh will try to use `$XDG_STATE_HOME`, `$HOME/.local/state` and fallback to
/// `./` (the current directory) if it failed.
///
/// [`dirs::state_dir`]: https://docs.rs/dirs/latest/dirs/fn.state_dir.html
#[cfg(not(windows))]
#[cfg_attr(docsrs, doc(cfg(not(windows))))]
pub fn control_directory(&mut self, p: impl AsRef<Path>) -> &mut Self {
Expand Down
2 changes: 2 additions & 0 deletions src/changelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
use crate::*;

/// TODO: RENAME THIS INTO THE NEXT VERSION BEFORE RELEASE
/// ## Changed
/// - Removed dependency on MPL licensed dirs-sys in favor of local implementation
#[doc(hidden)]
pub mod unreleased {}

Expand Down

0 comments on commit d5b2278

Please sign in to comment.