diff options
| author | Ellie Huxtable <ellie@elliehuxtable.com> | 2023-06-14 21:18:24 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-14 21:18:24 +0100 |
| commit | ae1709dafd22ac3c64441472e90df8799253292e (patch) | |
| tree | 88d1cb17af6af9948d44ffb7242d69be5743785d /atuin-client/src/settings.rs | |
| parent | Bump debian from bullseye-20230502-slim to bullseye-20230612-slim (#1047) (diff) | |
| download | atuin-ae1709dafd22ac3c64441472e90df8799253292e.zip | |
Key values (#1038)
* wip
* Start testing
* Store host IDs, not hostnames
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.
* Mostly just write a fuckload of tests
* Add a v0 kv store I can push to
* Appending works
* Add next() and iterate, test the pointer chain
* Fix sig
* Make clippy happy and thaw the ICE
* Fix tests'
* Fix tests
* typed builder and cleaner db trait
---------
Co-authored-by: Conrad Ludgate <conrad.ludgate@truelayer.com>
Diffstat (limited to 'atuin-client/src/settings.rs')
| -rw-r--r-- | atuin-client/src/settings.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/atuin-client/src/settings.rs b/atuin-client/src/settings.rs index 524b2fd7..dd072451 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 { @@ -140,6 +141,7 @@ pub struct Settings { pub sync_address: String, pub sync_frequency: String, pub db_path: String, + pub record_store_path: String, pub key_path: String, pub session_path: String, pub search_mode: SearchMode, @@ -226,6 +228,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); @@ -321,11 +338,14 @@ impl Settings { config_file.push("config.toml"); let db_path = data_dir.join("history.db"); + let record_store_path = data_dir.join("records.db"); + let key_path = data_dir.join("key"); let session_path = data_dir.join("session"); let mut config_builder = Config::builder() .set_default("db_path", db_path.to_str())? + .set_default("record_store_path", record_store_path.to_str())? .set_default("key_path", key_path.to_str())? .set_default("session_path", session_path.to_str())? .set_default("dialect", "us")? |
