aboutsummaryrefslogtreecommitdiffstats
path: root/crates/atuin-client/src/import/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/atuin-client/src/import/mod.rs')
-rw-r--r--crates/atuin-client/src/import/mod.rs28
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 {