Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop MPL licensed dependency dirs-sys #141

Merged
merged 1 commit into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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") {
NobodyXu marked this conversation as resolved.
Show resolved Hide resolved
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` on unix, 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
Loading