fix(client): always read session_path from settings (#757)

* fix(client): always read session_path from settings

* fixup! fix(client): always read session_path from settings

* fixup! fix(client): always read session_path from settings
This commit is contained in:
Luke Karrys 2023-03-06 15:46:03 -07:00 committed by GitHub
parent e9c5e1d85c
commit ca5bbea0d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 10 deletions

View file

@ -197,9 +197,7 @@ impl Settings {
} }
pub fn should_sync(&self) -> Result<bool> { pub fn should_sync(&self) -> Result<bool> {
let session_path = atuin_common::utils::data_dir().join("session"); if !self.auto_sync || !PathBuf::from(self.session_path.as_str()).exists() {
if !self.auto_sync || !session_path.exists() {
return Ok(false); return Ok(false);
} }

View file

@ -39,7 +39,7 @@ impl Cmd {
match self { match self {
Self::Sync { force } => run(&settings, force, db).await, Self::Sync { force } => run(&settings, force, db).await,
Self::Login(l) => l.run(&settings).await, Self::Login(l) => l.run(&settings).await,
Self::Logout => logout::run(), Self::Logout => logout::run(&settings),
Self::Register(r) => r.run(&settings).await, Self::Register(r) => r.run(&settings).await,
Self::Key { base64 } => { Self::Key { base64 } => {
use atuin_client::encryption::{encode_key, load_key}; use atuin_client::encryption::{encode_key, load_key};

View file

@ -33,9 +33,9 @@ fn get_input() -> Result<String> {
impl Cmd { impl Cmd {
pub async fn run(&self, settings: &Settings) -> Result<()> { pub async fn run(&self, settings: &Settings) -> Result<()> {
let session_path = atuin_common::utils::data_dir().join("session"); let session_path = settings.session_path.as_str();
if session_path.exists() { if PathBuf::from(session_path).exists() {
println!( println!(
"You are already logged in! Please run 'atuin logout' if you wish to login again" "You are already logged in! Please run 'atuin logout' if you wish to login again"
); );

View file

@ -1,11 +1,15 @@
use std::path::PathBuf;
use eyre::{Context, Result}; use eyre::{Context, Result};
use fs_err::remove_file; use fs_err::remove_file;
pub fn run() -> Result<()> { use atuin_client::settings::Settings;
let session_path = atuin_common::utils::data_dir().join("session");
if session_path.exists() { pub fn run(settings: &Settings) -> Result<()> {
remove_file(session_path.as_path()).context("Failed to remove session file")?; let session_path = settings.session_path.as_str();
if PathBuf::from(session_path).exists() {
remove_file(session_path).context("Failed to remove session file")?;
println!("You have logged out!"); println!("You have logged out!");
} else { } else {
println!("You are not logged in"); println!("You are not logged in");