diff options
| author | Rain <rain@sunshowers.io> | 2024-03-05 01:49:40 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-05 09:49:40 +0000 |
| commit | 95e9530dad098e69de560a3f4d198b5c05cc53ba (patch) | |
| tree | dcb77716883d7c1bf32212945bf2bebababd3d29 /atuin-client/src/import | |
| parent | fix(sync): record size limiter (#1827) (diff) | |
| download | atuin-95e9530dad098e69de560a3f4d198b5c05cc53ba.zip | |
fix(build): make atuin compile on non-win/mac/linux platforms (#1825)
Hi!
I've been trying to get atuin set up on the illumos machine I built for work
@oxidecomputer, and I ran into a few issues which are fixed here:
1. The `clipboard` feature was only supported on Windows, Mac and Linux. I've
added a platform gate for that.
2. The `atomic-write-file` crate needed an update to the version of `nix` --
that is included.
3. As part of this, I found a [security
bug](https://rustsec.org/advisories/RUSTSEC-2024-0020.html) in the whoami
crate. The bug has been fixed upstream and I've included it.
whoami 1.5.0 deprecates the `hostname` function, which produced some fresh
warnings. While fixing the warnings I also took the liberty of doing some
code rearrangement, adding a few functions that wrap some common operations. I
didn't really know where to put those functions, so I created a new `utils`
module for it. If you have a better place to put them, I'm happy to change
the PR.
Feel free to make any changes to this PR if you like before landing it, or to
ask for review.
As a followup I'm also happy to set up a cross-compile build for atuin on
illumos. It's a bit harder to run tests in CI for illumos at the moment, but
I'm trying to get a project started up to make that happen in the future as
well.
Diffstat (limited to 'atuin-client/src/import')
| -rw-r--r-- | atuin-client/src/import/xonsh.rs | 11 | ||||
| -rw-r--r-- | atuin-client/src/import/xonsh_sqlite.rs | 11 | ||||
| -rw-r--r-- | atuin-client/src/import/zsh_histdb.rs | 10 |
3 files changed, 5 insertions, 27 deletions
diff --git a/atuin-client/src/import/xonsh.rs b/atuin-client/src/import/xonsh.rs index 8a37c715..19ce4cf6 100644 --- a/atuin-client/src/import/xonsh.rs +++ b/atuin-client/src/import/xonsh.rs @@ -12,6 +12,7 @@ use uuid::Uuid; use super::{get_histpath, Importer, Loader}; use crate::history::History; +use crate::utils::get_host_user; // Note: both HistoryFile and HistoryData have other keys present in the JSON, we don't // care about them so we leave them unspecified so as to avoid deserializing unnecessarily. @@ -60,14 +61,6 @@ fn xonsh_hist_dir(xonsh_data_dir: Option<String>) -> Result<PathBuf> { } } -fn get_hostname() -> String { - format!( - "{}:{}", - env::var("ATUIN_HOST_NAME").unwrap_or_else(|_| whoami::hostname()), - env::var("ATUIN_HOST_USER").unwrap_or_else(|_| whoami::username()), - ) -} - fn load_sessions(hist_dir: &Path) -> Result<Vec<HistoryData>> { let mut sessions = vec![]; for entry in fs::read_dir(hist_dir)? { @@ -111,7 +104,7 @@ impl Importer for Xonsh { let xonsh_data_dir = env::var("XONSH_DATA_DIR").ok(); let hist_dir = get_histpath(|| xonsh_hist_dir(xonsh_data_dir))?; let sessions = load_sessions(&hist_dir)?; - let hostname = get_hostname(); + let hostname = get_host_user(); Ok(Xonsh { sessions, hostname }) } diff --git a/atuin-client/src/import/xonsh_sqlite.rs b/atuin-client/src/import/xonsh_sqlite.rs index de59d477..2817dc63 100644 --- a/atuin-client/src/import/xonsh_sqlite.rs +++ b/atuin-client/src/import/xonsh_sqlite.rs @@ -12,6 +12,7 @@ use uuid::Uuid; use super::{get_histpath, Importer, Loader}; use crate::history::History; +use crate::utils::get_host_user; #[derive(Debug, FromRow)] struct HistDbEntry { @@ -79,14 +80,6 @@ fn xonsh_db_path(xonsh_data_dir: Option<String>) -> Result<PathBuf> { } } -fn get_hostname() -> String { - format!( - "{}:{}", - env::var("ATUIN_HOST_NAME").unwrap_or_else(|_| whoami::hostname()), - env::var("ATUIN_HOST_USER").unwrap_or_else(|_| whoami::username()), - ) -} - #[derive(Debug)] pub struct XonshSqlite { pool: SqlitePool, @@ -109,7 +102,7 @@ impl Importer for XonshSqlite { })?; let pool = SqlitePool::connect(connection_str).await?; - let hostname = get_hostname(); + let hostname = get_host_user(); Ok(XonshSqlite { pool, hostname }) } diff --git a/atuin-client/src/import/zsh_histdb.rs b/atuin-client/src/import/zsh_histdb.rs index f58fd049..eb72baa3 100644 --- a/atuin-client/src/import/zsh_histdb.rs +++ b/atuin-client/src/import/zsh_histdb.rs @@ -33,7 +33,6 @@ // use std::collections::HashMap; -use std::env; use std::path::{Path, PathBuf}; use async_trait::async_trait; @@ -46,6 +45,7 @@ use time::PrimitiveDateTime; use super::Importer; use crate::history::History; use crate::import::Loader; +use crate::utils::{get_hostname, get_username}; #[derive(sqlx::FromRow, Debug)] pub struct HistDbEntryCount { @@ -64,14 +64,6 @@ pub struct HistDbEntry { pub session: i64, } -fn get_hostname() -> String { - env::var("ATUIN_HOST_NAME").unwrap_or_else(|_| whoami::hostname()) -} - -fn get_username() -> String { - env::var("ATUIN_HOST_USER").unwrap_or_else(|_| whoami::username()) -} - #[derive(Debug)] pub struct ZshHistDb { histdb: Vec<HistDbEntry>, |
