From f0fca3d7f34814a8a3cf5d3be3578f747ecda562 Mon Sep 17 00:00:00 2001 From: Benjamin Weinstein-Raun Date: Mon, 24 Mar 2025 04:00:16 -0700 Subject: fixes #1884: HISTFILE can be a directory or a file (#2630) Xonsh history import was failing (in the default xonsh configuration) because $HISTFILE is actually a directory in that case. This change sets up the xonsh import to check for a *directory* instead of a regular file, and makes it clearer that other importers expect a regular file. --- crates/atuin-client/src/import/mod.rs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'crates/atuin-client/src/import/mod.rs') diff --git a/crates/atuin-client/src/import/mod.rs b/crates/atuin-client/src/import/mod.rs index 1d4f29f3..1be850f9 100644 --- a/crates/atuin-client/src/import/mod.rs +++ b/crates/atuin-client/src/import/mod.rs @@ -73,12 +73,26 @@ where D: FnOnce() -> Result, { if let Ok(p) = std::env::var("HISTFILE") { - is_file(PathBuf::from(p)) + Ok(PathBuf::from(p)) } else { - is_file(def()?) + def() } } +fn get_histfile_path(def: D) -> Result +where + D: FnOnce() -> Result, +{ + get_histpath(def).and_then(is_file) +} + +fn get_histdir_path(def: D) -> Result +where + D: FnOnce() -> Result, +{ + get_histpath(def).and_then(is_dir) +} + fn read_to_end(path: PathBuf) -> Result> { let mut bytes = Vec::new(); let mut f = File::open(path)?; @@ -92,6 +106,16 @@ fn is_file(p: PathBuf) -> Result { bail!("Could not find history file {:?}. Try setting $HISTFILE", p) } } +fn is_dir(p: PathBuf) -> Result { + if p.is_dir() { + Ok(p) + } else { + bail!( + "Could not find history directory {:?}. Try setting $HISTFILE", + p + ) + } +} #[cfg(test)] mod tests { -- cgit v1.3.1