Expose `windows-pipe` and `unix-socket` regardless of platform

pull/137/head
Chip Senkbeil 2 years ago
parent 44b0dc065c
commit 0633530a13
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

@ -24,6 +24,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
(defaulting to distant); this means that subsequent use of
`distant client launch [user@]host[:port]` will now default to ssh instead of
failing due to lack of distant launch handler
- Expose `windows-pipe` and `unix-socket` config and cli options regardless of
platform (so they can be provided without worrying about which OS)
## [0.17.1] - 2022-08-16
### Added

@ -261,7 +261,9 @@ impl ManagerSubcommand {
info!(
"Starting manager (network = {})",
if network.as_opt().is_some() {
if (cfg!(windows) && network.windows_pipe.is_some())
|| (cfg!(unix) && network.unix_socket.is_some())
{
"custom"
} else if user {
"user"

@ -41,13 +41,11 @@ pub struct NetworkConfig {
#[clap(long, value_enum)]
pub access: Option<AccessControl>,
/// Override the path to the Unix socket used by the manager
#[cfg(unix)]
/// Override the path to the Unix socket used by the manager (unix-only)
#[clap(long)]
pub unix_socket: Option<std::path::PathBuf>,
/// Override the name of the local named Windows pipe used by the manager
#[cfg(windows)]
/// Override the name of the local named Windows pipe used by the manager (windows-only)
#[clap(long)]
pub windows_pipe: Option<String>,
}
@ -56,30 +54,23 @@ impl NetworkConfig {
pub fn merge(self, other: Self) -> Self {
Self {
access: self.access.or(other.access),
#[cfg(unix)]
unix_socket: self.unix_socket.or(other.unix_socket),
#[cfg(windows)]
windows_pipe: self.windows_pipe.or(other.windows_pipe),
}
}
/// Returns option containing reference to unix path if configured
#[cfg(unix)]
pub fn as_opt(&self) -> Option<&std::path::Path> {
pub fn as_unix_socket_opt(&self) -> Option<&std::path::Path> {
self.unix_socket.as_deref()
}
/// Returns option containing reference to windows pipe name if configured
#[cfg(windows)]
pub fn as_opt(&self) -> Option<&str> {
pub fn as_windows_pipe_opt(&self) -> Option<&str> {
self.windows_pipe.as_deref()
}
/// Returns a collection of candidate unix socket paths, which will either be
/// the config-provided unix socket path or the default user and global socket paths
#[cfg(unix)]
pub fn to_unix_socket_path_candidates(&self) -> Vec<&std::path::Path> {
match self.unix_socket.as_deref() {
Some(path) => vec![path],
@ -92,7 +83,6 @@ impl NetworkConfig {
/// Returns a collection of candidate windows pipe names, which will either be
/// the config-provided windows pipe name or the default user and global pipe names
#[cfg(windows)]
pub fn to_windows_pipe_name_candidates(&self) -> Vec<&str> {
match self.windows_pipe.as_deref() {
Some(name) => vec![name],

@ -2,7 +2,6 @@ use directories::ProjectDirs;
use once_cell::sync::Lazy;
use std::path::PathBuf;
#[cfg(unix)]
const SOCKET_FILE_STR: &str = "distant.sock";
/// User-oriented paths
@ -46,7 +45,6 @@ pub mod user {
/// * `/run/user/1001/distant/{user}.distant.sock` on Linux
/// * `/var/run/{user}.distant.sock` on BSD
/// * `/tmp/{user}.distant.dock` on MacOS
#[cfg(unix)]
pub static UNIX_SOCKET_PATH: Lazy<PathBuf> = Lazy::new(|| {
// Form of {user}.distant.sock
let mut file_name = whoami::username_os();
@ -61,7 +59,6 @@ pub mod user {
});
/// Name of the pipe used by Windows in the form of `{user}.distant`
#[cfg(windows)]
pub static WINDOWS_PIPE_NAME: Lazy<String> =
Lazy::new(|| format!("{}.distant", whoami::username()));
}
@ -90,7 +87,6 @@ pub mod global {
/// * `/run/distant.sock` on Linux
/// * `/var/run/distant.sock` on BSD
/// * `/tmp/distant.dock` on MacOS
#[cfg(unix)]
pub static UNIX_SOCKET_PATH: Lazy<PathBuf> = Lazy::new(|| {
if cfg!(target_os = "macos") {
std::env::temp_dir().join(SOCKET_FILE_STR)
@ -107,6 +103,5 @@ pub mod global {
});
/// Name of the pipe used by Windows
#[cfg(windows)]
pub static WINDOWS_PIPE_NAME: Lazy<String> = Lazy::new(|| "distant".to_string());
}

Loading…
Cancel
Save