diff options
| author | Benjamin Weinstein-Raun <b@w-r.me> | 2025-03-24 04:00:16 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-24 11:00:16 +0000 |
| commit | f0fca3d7f34814a8a3cf5d3be3578f747ecda562 (patch) | |
| tree | 58239d17449b03155022fc448478b4817554e668 /crates/atuin-client/src/import/mod.rs | |
| parent | chore(deps): bump cachix/install-nix-action from 30 to 31 (#2633) (diff) | |
| download | atuin-f0fca3d7f34814a8a3cf5d3be3578f747ecda562.zip | |
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.
Diffstat (limited to 'crates/atuin-client/src/import/mod.rs')
| -rw-r--r-- | crates/atuin-client/src/import/mod.rs | 28 |
1 files changed, 26 insertions, 2 deletions
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<PathBuf>, { 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<D>(def: D) -> Result<PathBuf> +where + D: FnOnce() -> Result<PathBuf>, +{ + get_histpath(def).and_then(is_file) +} + +fn get_histdir_path<D>(def: D) -> Result<PathBuf> +where + D: FnOnce() -> Result<PathBuf>, +{ + get_histpath(def).and_then(is_dir) +} + fn read_to_end(path: PathBuf) -> Result<Vec<u8>> { let mut bytes = Vec::new(); let mut f = File::open(path)?; @@ -92,6 +106,16 @@ fn is_file(p: PathBuf) -> Result<PathBuf> { bail!("Could not find history file {:?}. Try setting $HISTFILE", p) } } +fn is_dir(p: PathBuf) -> Result<PathBuf> { + if p.is_dir() { + Ok(p) + } else { + bail!( + "Could not find history directory {:?}. Try setting $HISTFILE", + p + ) + } +} #[cfg(test)] mod tests { |
