Support old msgpack (#794)

* Support old msgpack

I forgot it isn't backwards compatible... This should fix any sync
issues resulting from the deletion PR

* Update atuin-client/src/encryption.rs

Co-authored-by: Conrad Ludgate <conradludgate@gmail.com>

* Bye bye unwrap

---------

Co-authored-by: Conrad Ludgate <conradludgate@gmail.com>
This commit is contained in:
Ellie Huxtable 2023-03-20 21:26:37 +00:00 committed by GitHub
parent 26a1b93098
commit 13514b635c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 2 deletions

View file

@ -15,7 +15,10 @@ use fs_err as fs;
use serde::{Deserialize, Serialize};
use sodiumoxide::crypto::secretbox;
use crate::{history::History, settings::Settings};
use crate::{
history::{History, HistoryWithoutDelete},
settings::Settings,
};
#[derive(Debug, Serialize, Deserialize)]
pub struct EncryptedHistory {
@ -98,7 +101,23 @@ pub fn decrypt(encrypted_history: &EncryptedHistory, key: &secretbox::Key) -> Re
let plaintext = secretbox::open(&encrypted_history.ciphertext, &encrypted_history.nonce, key)
.map_err(|_| eyre!("failed to open secretbox - invalid key?"))?;
let history = rmp_serde::from_slice(&plaintext)?;
let history = rmp_serde::from_slice(&plaintext);
let Ok(history) = history else {
let history: HistoryWithoutDelete = rmp_serde::from_slice(&plaintext)?;
return Ok(History {
id: history.id,
cwd: history.cwd,
exit: history.exit,
command: history.command,
session: history.session,
duration: history.duration,
hostname: history.hostname,
timestamp: history.timestamp,
deleted_at: None,
});
};
Ok(history)
}

View file

@ -19,6 +19,21 @@ pub struct History {
pub deleted_at: Option<chrono::DateTime<Utc>>,
}
// Forgive me, for I have sinned
// I need to replace rmp with something that is more backwards-compatible.
// Protobuf, or maybe just json
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, sqlx::FromRow)]
pub struct HistoryWithoutDelete {
pub id: String,
pub timestamp: chrono::DateTime<Utc>,
pub duration: i64,
pub exit: i64,
pub command: String,
pub cwd: String,
pub session: String,
pub hostname: String,
}
impl History {
#[allow(clippy::too_many_arguments)]
pub fn new(