From 10a6f3b683f976c6eb4f3f843b4ba93fa5254a7b Mon Sep 17 00:00:00 2001 From: Lapo Luchini Date: Wed, 7 Jun 2023 13:20:01 +0200 Subject: [PATCH] Add FreeBSD support. Just like Linux, it uses $XDG_RUNTIME_DIR/org.keepassxc.KeePassXC.BrowserServer --- src/utils/socket.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/utils/socket.rs b/src/utils/socket.rs index f9676a5..9e2d491 100644 --- a/src/utils/socket.rs +++ b/src/utils/socket.rs @@ -25,6 +25,7 @@ pub fn get_socket_path() -> Result { Box::new(LinuxSocketPath272), Box::new(WindowsSocketPath262), Box::new(WindowsSocketPathNatMsg), + Box::new(FreeBSDSocketPath274), ]; let winner = candidates .iter() @@ -50,6 +51,23 @@ trait SocketPath { fn matches_os(&self) -> bool; } +struct FreeBSDSocketPath274; +impl SocketPath for FreeBSDSocketPath274 { + fn get_path(&self) -> Result { + let base_dirs = directories_next::BaseDirs::new() + .ok_or_else(|| anyhow!("Failed to initialise base_dirs"))?; + let result = base_dirs + .runtime_dir() + .ok_or_else(|| anyhow!("Failed to locate runtime_dir automatically"))? + .join(KEEPASS_SOCKET_NAME); + exist_or_error(result) + } + + fn matches_os(&self) -> bool { + cfg!(target_os = "freebsd") + } +} + struct LinuxSocketPathLegacy; impl SocketPath for LinuxSocketPathLegacy { fn get_path(&self) -> Result {