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 9e31280
Show file tree
Hide file tree
Showing 2 changed files with 16 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
19 changes: 16 additions & 3 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,25 @@ 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;

fn state_dir() -> Option<PathBuf> {
fn get_absolute_path(path: OsString) -> Option<PathBuf> {
let path = PathBuf::from(path);
path.is_absolute().then_some(path)
}

if let Some(xdg) = std::env::var_os("XDG_STATE_HOME") {
get_absolute_path(xdg)
} else if let Some(home) = std::env::var_os("HOME") {
Some(get_absolute_path(home)?.join(".local/state"))
} else {
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 +171,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

0 comments on commit 9e31280

Please sign in to comment.