mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 10:18:54 +00:00
refactor(rust): move known_dirs to bin-shared (#9026)
The `known_dirs` module is used across the headless-client and the GUI client. It should live in `bin-shared` where all the other cross-platform modules are. --------- Signed-off-by: Thomas Eizinger <thomas@eizinger.io>
This commit is contained in:
2
rust/Cargo.lock
generated
2
rust/Cargo.lock
generated
@@ -2097,6 +2097,7 @@ dependencies = [
|
||||
"bufferpool",
|
||||
"bytes",
|
||||
"clap",
|
||||
"dirs 5.0.1",
|
||||
"firezone-logging",
|
||||
"flume",
|
||||
"futures",
|
||||
@@ -2272,7 +2273,6 @@ dependencies = [
|
||||
"clap",
|
||||
"connlib-client-shared",
|
||||
"connlib-model",
|
||||
"dirs 5.0.1",
|
||||
"dns-types",
|
||||
"firezone-bin-shared",
|
||||
"firezone-logging",
|
||||
|
||||
@@ -28,6 +28,7 @@ bytes = { workspace = true }
|
||||
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
dirs = { workspace = true }
|
||||
flume = { workspace = true }
|
||||
libc = { workspace = true }
|
||||
netlink-packet-core = { version = "0.7" }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use firezone_bin_shared::BUNDLE_ID;
|
||||
use crate::BUNDLE_ID;
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// Path for IPC service config that the IPC service can write
|
||||
@@ -1,7 +1,20 @@
|
||||
use firezone_bin_shared::{BUNDLE_ID, platform::app_local_data_dir};
|
||||
use crate::BUNDLE_ID;
|
||||
use anyhow::{Context as _, Result};
|
||||
use known_folders::{KnownFolder, get_known_folder_path};
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// Returns e.g. `C:/Users/User/AppData/Local/dev.firezone.client
|
||||
///
|
||||
/// This is where we can save config, logs, crash dumps, etc.
|
||||
/// It's per-user and doesn't roam across different PCs in the same domain.
|
||||
/// It's read-write for non-elevated processes.
|
||||
pub fn app_local_data_dir() -> Result<PathBuf> {
|
||||
let path = get_known_folder_path(KnownFolder::LocalAppData)
|
||||
.context("Can't find %LOCALAPPDATA% dir")?
|
||||
.join(crate::BUNDLE_ID);
|
||||
Ok(path)
|
||||
}
|
||||
|
||||
/// Path for IPC service config that the IPC service can write
|
||||
///
|
||||
/// All writes should use `atomicwrites`.
|
||||
@@ -23,6 +23,7 @@ pub mod macos;
|
||||
#[cfg(target_os = "macos")]
|
||||
pub use macos as platform;
|
||||
|
||||
pub mod known_dirs;
|
||||
pub mod uptime;
|
||||
|
||||
pub const TOKEN_ENV_KEY: &str = "FIREZONE_TOKEN";
|
||||
|
||||
@@ -630,7 +630,7 @@ fn file_length(f: &std::fs::File) -> Result<usize> {
|
||||
///
|
||||
/// e.g. `C:\Users\User\AppData\Local\dev.firezone.client\data\wintun.dll`
|
||||
fn wintun_dll_path() -> Result<PathBuf> {
|
||||
let path = crate::windows::app_local_data_dir()?
|
||||
let path = crate::known_dirs::platform::app_local_data_dir()?
|
||||
.join("data")
|
||||
.join("wintun.dll");
|
||||
Ok(path)
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
use crate::TUNNEL_NAME;
|
||||
use anyhow::{Context as _, Result};
|
||||
use anyhow::Result;
|
||||
use firezone_logging::err_with_src;
|
||||
use known_folders::{KnownFolder, get_known_folder_path};
|
||||
use socket_factory::{TcpSocket, UdpSocket};
|
||||
use std::{
|
||||
cmp::Ordering,
|
||||
io,
|
||||
mem::MaybeUninit,
|
||||
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6},
|
||||
path::PathBuf,
|
||||
ptr::null,
|
||||
};
|
||||
use uuid::Uuid;
|
||||
@@ -106,18 +104,6 @@ impl Default for DnsControlMethod {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns e.g. `C:/Users/User/AppData/Local/dev.firezone.client
|
||||
///
|
||||
/// This is where we can save config, logs, crash dumps, etc.
|
||||
/// It's per-user and doesn't roam across different PCs in the same domain.
|
||||
/// It's read-write for non-elevated processes.
|
||||
pub fn app_local_data_dir() -> Result<PathBuf> {
|
||||
let path = get_known_folder_path(KnownFolder::LocalAppData)
|
||||
.context("Can't find %LOCALAPPDATA% dir")?
|
||||
.join(crate::BUNDLE_ID);
|
||||
Ok(path)
|
||||
}
|
||||
|
||||
pub fn tcp_socket_factory(addr: &SocketAddr) -> io::Result<TcpSocket> {
|
||||
delete_all_routing_entries_matching(addr.ip())?;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Fulfills <https://github.com/firezone/firezone/issues/2823>
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use firezone_headless_client::known_dirs;
|
||||
use firezone_bin_shared::known_dirs;
|
||||
use firezone_logging::err_with_src;
|
||||
use rand::{RngCore, thread_rng};
|
||||
use secrecy::{ExposeSecret, SecretString};
|
||||
|
||||
@@ -26,6 +26,6 @@ pub(crate) async fn set() -> Result<()> {
|
||||
|
||||
fn path() -> Result<PathBuf> {
|
||||
let session_dir =
|
||||
firezone_headless_client::known_dirs::session().context("Couldn't find session dir")?;
|
||||
firezone_bin_shared::known_dirs::session().context("Couldn't find session dir")?;
|
||||
Ok(session_dir.join("ran_before.txt"))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use anyhow::{Context, Result, bail};
|
||||
use firezone_headless_client::known_dirs;
|
||||
use firezone_bin_shared::known_dirs;
|
||||
use secrecy::{ExposeSecret, Secret};
|
||||
use std::{io::ErrorKind, path::PathBuf, process::Command};
|
||||
use tokio::{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Everything for logging to files, zipping up the files for export, and counting the files
|
||||
|
||||
use anyhow::{Context as _, Result, bail};
|
||||
use firezone_headless_client::known_dirs;
|
||||
use firezone_bin_shared::known_dirs;
|
||||
use serde::Serialize;
|
||||
use std::{
|
||||
fs,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
use anyhow::{Context as _, Result};
|
||||
use connlib_model::ResourceId;
|
||||
use firezone_headless_client::known_dirs;
|
||||
use firezone_bin_shared::known_dirs;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{collections::HashSet, path::PathBuf};
|
||||
use url::Url;
|
||||
|
||||
@@ -205,7 +205,7 @@ impl Checker {
|
||||
}
|
||||
|
||||
fn version_file_path() -> Result<PathBuf> {
|
||||
Ok(firezone_headless_client::known_dirs::session()
|
||||
Ok(firezone_bin_shared::known_dirs::session()
|
||||
.context("Couldn't find session dir")?
|
||||
.join("latest_version_seen.txt"))
|
||||
}
|
||||
|
||||
@@ -51,7 +51,6 @@ tempfile = { workspace = true }
|
||||
mutants = "0.0.3" # Needed to mark functions as exempt from `cargo-mutants` testing
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
dirs = { workspace = true }
|
||||
libc = { workspace = true }
|
||||
nix = { workspace = true, features = ["fs", "user", "socket"] }
|
||||
resolv-conf = { workspace = true }
|
||||
|
||||
@@ -15,7 +15,7 @@ pub struct DeviceId {
|
||||
/// e.g. `C:\ProgramData\dev.firezone.client/firezone-id.json` or
|
||||
/// `/var/lib/dev.firezone.client/config/firezone-id.json`.
|
||||
pub(crate) fn path() -> Result<PathBuf> {
|
||||
let path = crate::known_dirs::ipc_service_config()
|
||||
let path = firezone_bin_shared::known_dirs::ipc_service_config()
|
||||
.context("Failed to compute path for firezone-id file")?
|
||||
.join("firezone-id.json");
|
||||
Ok(path)
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
use crate::{
|
||||
CallbackHandler, CliCommon, ConnlibMsg, device_id, dns_control::DnsController, known_dirs,
|
||||
signals,
|
||||
CallbackHandler, CliCommon, ConnlibMsg, device_id, dns_control::DnsController, signals,
|
||||
};
|
||||
use anyhow::{Context as _, Result, bail};
|
||||
use atomicwrites::{AtomicFile, OverwriteBehavior};
|
||||
use clap::Parser;
|
||||
use connlib_model::ResourceView;
|
||||
use firezone_bin_shared::{
|
||||
TOKEN_ENV_KEY, TunDeviceManager,
|
||||
TOKEN_ENV_KEY, TunDeviceManager, known_dirs,
|
||||
platform::{DnsControlMethod, tcp_socket_factory, udp_socket_factory},
|
||||
};
|
||||
use firezone_logging::{FilterReloadHandle, err_with_src, sentry_layer, telemetry_span};
|
||||
@@ -472,7 +471,8 @@ impl<'a> Handler<'a> {
|
||||
match msg {
|
||||
ClientMsg::ClearLogs => {
|
||||
let result = crate::clear_logs(
|
||||
&crate::known_dirs::ipc_service_logs().context("Can't compute logs dir")?,
|
||||
&firezone_bin_shared::known_dirs::ipc_service_logs()
|
||||
.context("Can't compute logs dir")?,
|
||||
)
|
||||
.await;
|
||||
self.send_ipc(ServerMsg::ClearedLogs(result.map_err(|e| e.to_string())))
|
||||
|
||||
@@ -87,7 +87,7 @@ impl Server {
|
||||
fn ipc_path(id: ServiceId) -> PathBuf {
|
||||
match id {
|
||||
ServiceId::Prod => PathBuf::from("/run").join(BUNDLE_ID).join("ipc.sock"),
|
||||
ServiceId::Test(id) => crate::known_dirs::runtime()
|
||||
ServiceId::Test(id) => firezone_bin_shared::known_dirs::runtime()
|
||||
.expect("`known_dirs::runtime()` should always work")
|
||||
.join(format!("ipc_test_{id}.sock")),
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ pub mod device_id;
|
||||
// Pub because the GUI reads the system resolvers
|
||||
pub mod dns_control;
|
||||
mod ipc_service;
|
||||
pub mod known_dirs;
|
||||
// TODO: Move to `bin-shared`?
|
||||
pub mod signals;
|
||||
|
||||
@@ -170,8 +169,8 @@ pub(crate) fn get_log_filter() -> Result<String> {
|
||||
return Ok(filter);
|
||||
}
|
||||
|
||||
if let Ok(filter) =
|
||||
std::fs::read_to_string(known_dirs::ipc_log_filter()?).map(|s| s.trim().to_string())
|
||||
if let Ok(filter) = std::fs::read_to_string(firezone_bin_shared::known_dirs::ipc_log_filter()?)
|
||||
.map(|s| s.trim().to_string())
|
||||
{
|
||||
return Ok(filter);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user