aboutsummaryrefslogtreecommitdiffstats
path: root/crates/daemon/src/aclient/history
diff options
context:
space:
mode:
Diffstat (limited to 'crates/daemon/src/aclient/history')
-rw-r--r--crates/daemon/src/aclient/history/mod.rs31
-rw-r--r--crates/daemon/src/aclient/history/store.rs8
2 files changed, 27 insertions, 12 deletions
diff --git a/crates/daemon/src/aclient/history/mod.rs b/crates/daemon/src/aclient/history/mod.rs
index ae7654a6..35abc89d 100644
--- a/crates/daemon/src/aclient/history/mod.rs
+++ b/crates/daemon/src/aclient/history/mod.rs
@@ -1,7 +1,9 @@
+use std::time::Duration;
+
use rmp::decode::DecodeStringError;
use rmp::decode::ValueReadError;
use rmp::{Marker, decode::Bytes};
-use turtle::history::History;
+use turtle_api::history::History;
use turtle_common::record::DecryptedData;
@@ -40,9 +42,12 @@ impl HistoryExt for History {
let include_intent = self.intent.is_some();
encode::write_array_len(&mut output, 10 + u32::from(include_intent))?;
- encode::write_str(&mut output, &self.id.0)?;
+ encode::write_str(&mut output, &self.id.to_string())?;
encode::write_u64(&mut output, self.timestamp.unix_timestamp_nanos() as u64)?;
- encode::write_sint(&mut output, self.duration)?;
+ encode::write_sint(
+ &mut output,
+ i64::try_from(self.duration.as_nanos()).expect("should be small enough"),
+ )?;
encode::write_sint(&mut output, self.exit)?;
encode::write_str(&mut output, &self.command)?;
encode::write_str(&mut output, &self.cwd)?;
@@ -107,7 +112,11 @@ impl HistoryExt for History {
let mut bytes = Bytes::new(bytes);
let timestamp = decode::read_u64(&mut bytes).map_err(error_report)?;
- let duration = decode::read_int(&mut bytes).map_err(error_report)?;
+ let duration = decode::read_int(&mut bytes)
+ .map(|int: i64| {
+ Duration::from_nanos(u64::try_from(int).expect("should be small enough"))
+ })
+ .map_err(error_report)?;
let exit = decode::read_int(&mut bytes).map_err(error_report)?;
let bytes = bytes.remaining_slice();
@@ -171,7 +180,9 @@ impl HistoryExt for History {
let mut bytes = Bytes::new(bytes);
let timestamp = decode::read_u64(&mut bytes).map_err(error_report)?;
- let duration = decode::read_int(&mut bytes).map_err(error_report)?;
+ let duration = decode::read_int(&mut bytes)
+ .map(|int: i64| Duration::from_nanos(u64::try_from(int).expect("to be small enough")))
+ .map_err(error_report)?;
let exit = decode::read_int(&mut bytes).map_err(error_report)?;
let bytes = bytes.remaining_slice();
@@ -228,6 +239,8 @@ impl HistoryExt for History {
#[cfg(test)]
mod tests {
+ use std::time::Duration;
+
use time::macros::datetime;
use crate::aclient::history::{HISTORY_VERSION, HistoryExt};
@@ -239,7 +252,7 @@ mod tests {
let history = History {
id: "66d16cbee7cd47538e5c5b8b44e9006e".to_owned().into(),
timestamp: datetime!(2023-05-28 18:35:40.633872 +00:00),
- duration: 49_206_000,
+ duration: Duration::from_nanos(49_206_000),
exit: 0,
command: "git status".to_owned(),
cwd: "/Users/conrad.ludgate/Documents/code/atuin".to_owned(),
@@ -267,7 +280,7 @@ mod tests {
let history = History {
id: "66d16cbee7cd47538e5c5b8b44e9006e".to_owned().into(),
timestamp: datetime!(2023-05-28 18:35:40.633872 +00:00),
- duration: 49_206_000,
+ duration: Duration::from_nanos(49_206_000),
exit: 0,
command: "git status".to_owned(),
cwd: "/Users/conrad.ludgate/Documents/code/atuin".to_owned(),
@@ -291,7 +304,7 @@ mod tests {
let history = History {
id: "66d16cbee7cd47538e5c5b8b44e9006e".to_owned().into(),
timestamp: datetime!(2023-05-28 18:35:40.633872 +00:00),
- duration: 49_206_000,
+ duration: Duration::from_nanos(49_206_000),
exit: 0,
command: "git status".to_owned(),
cwd: "/Users/conrad.ludgate/Documents/code/atuin".to_owned(),
@@ -333,7 +346,7 @@ mod tests {
let current = History {
id: "66d16cbee7cd47538e5c5b8b44e9006e".to_owned().into(),
timestamp: datetime!(2023-05-28 18:35:40.633872 +00:00),
- duration: 49_206_000,
+ duration: Duration::from_nanos(49_206_000),
exit: 0,
command: "git status".to_owned(),
cwd: "/Users/conrad.ludgate/Documents/code/atuin".to_owned(),
diff --git a/crates/daemon/src/aclient/history/store.rs b/crates/daemon/src/aclient/history/store.rs
index 952f2070..a6d6a627 100644
--- a/crates/daemon/src/aclient/history/store.rs
+++ b/crates/daemon/src/aclient/history/store.rs
@@ -1,6 +1,6 @@
use eyre::{Result, bail, eyre};
use rmp::decode::Bytes;
-use turtle::history::{History, HistoryId};
+use turtle_api::history::{History, HistoryId};
use crate::aclient::{
database::ClientSqlite,
@@ -56,7 +56,7 @@ impl HistoryRecord {
Self::Delete(id) => {
// 1 -> a history delete
encode::write_u8(&mut output, 1)?;
- encode::write_str(&mut output, id.0.as_str())?;
+ encode::write_str(&mut output, id.to_string().as_str())?;
}
}
@@ -221,6 +221,8 @@ impl HistoryStore {
#[cfg(test)]
mod tests {
+ use std::time::Duration;
+
use time::macros::datetime;
use turtle_common::record::DecryptedData;
@@ -244,7 +246,7 @@ mod tests {
let history = History {
id: "018cd4fe81757cd2aee65cd7861f9c81".to_owned().into(),
timestamp: datetime!(2024-01-04 00:00:00.000000 +00:00),
- duration: 100,
+ duration: Duration::from_nanos(100),
exit: 0,
command: "ls".to_owned(),
cwd: "/Users/ellie/src/github.com/atuinsh/atuin".to_owned(),