summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEllie Huxtable <ellie@elliehuxtable.com>2023-05-09 17:31:06 -0400
committerEllie Huxtable <ellie@elliehuxtable.com>2023-05-09 17:31:06 -0400
commit0fa1537fbdd7af00ef89c2bf728e9de0b7aaf1eb (patch)
tree0144cf9a8ae6899a2b3cbcc8e9429fcac58274b0
parentc65e7528f41fb5ca666c50ce6e95edc34671e504 (diff)
Store host IDs, not hostnamesellie/hostname-to-uuid
Why? Hostnames can change a lot, and therefore host filtering can be funky. Really, all we want is a unique ID per machine + do not care what it might be.
-rw-r--r--atuin-client/src/database.rs5
-rw-r--r--atuin-client/src/settings.rs16
2 files changed, 20 insertions, 1 deletions
diff --git a/atuin-client/src/database.rs b/atuin-client/src/database.rs
index c4a9ddc3..0b145ca4 100644
--- a/atuin-client/src/database.rs
+++ b/atuin-client/src/database.rs
@@ -16,13 +16,14 @@ use sqlx::{
use super::{
history::History,
ordering,
- settings::{FilterMode, SearchMode},
+ settings::{FilterMode, SearchMode, Settings},
};
pub struct Context {
pub session: String,
pub cwd: String,
pub hostname: String,
+ pub host_id: String,
}
#[derive(Default, Clone)]
@@ -45,11 +46,13 @@ pub fn current_context() -> Context {
};
let hostname = format!("{}:{}", whoami::hostname(), whoami::username());
let cwd = utils::get_current_dir();
+ let host_id = Settings::host_id().expect("failed to load host ID");
Context {
session,
hostname,
cwd,
+ host_id,
}
}
diff --git a/atuin-client/src/settings.rs b/atuin-client/src/settings.rs
index 0a723fb2..f7731ab1 100644
--- a/atuin-client/src/settings.rs
+++ b/atuin-client/src/settings.rs
@@ -17,6 +17,7 @@ pub const HISTORY_PAGE_SIZE: i64 = 100;
pub const LAST_SYNC_FILENAME: &str = "last_sync_time";
pub const LAST_VERSION_CHECK_FILENAME: &str = "last_version_check_time";
pub const LATEST_VERSION_FILENAME: &str = "latest_version";
+pub const HOST_ID_FILENAME: &str = "host_id";
#[derive(Clone, Debug, Deserialize, Copy, ValueEnum, PartialEq)]
pub enum SearchMode {
@@ -222,6 +223,21 @@ impl Settings {
Settings::load_time_from_file(LAST_VERSION_CHECK_FILENAME)
}
+ pub fn host_id() -> Option<String> {
+ let id = Settings::read_from_data_dir(HOST_ID_FILENAME);
+
+ if id.is_some() {
+ return id;
+ }
+
+ let uuid = atuin_common::utils::uuid_v7();
+
+ Settings::save_to_data_dir(HOST_ID_FILENAME, uuid.as_simple().to_string().as_ref())
+ .expect("Could not write host ID to data dir");
+
+ Some(uuid.as_simple().to_string())
+ }
+
pub fn should_sync(&self) -> Result<bool> {
if !self.auto_sync || !PathBuf::from(self.session_path.as_str()).exists() {
return Ok(false);