Verify that _ZO_DATA_DIR is an absolute path

This commit is contained in:
Ajeet D'Souza 2024-06-20 20:41:20 +05:30 committed by GitHub
parent dbe6f185cf
commit b881866216
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 3 deletions

View File

@ -2,19 +2,21 @@ use std::env;
use std::ffi::OsString;
use std::path::PathBuf;
use anyhow::{Context, Result};
use anyhow::{ensure, Context, Result};
use glob::Pattern;
use crate::db::Rank;
pub fn data_dir() -> Result<PathBuf> {
let path = match env::var_os("_ZO_DATA_DIR") {
let dir = match env::var_os("_ZO_DATA_DIR") {
Some(path) => PathBuf::from(path),
None => dirs::data_local_dir()
.context("could not find data directory, please set _ZO_DATA_DIR manually")?
.join("zoxide"),
};
Ok(path)
ensure!(dir.is_absolute(), "_ZO_DATA_DIR must be an absolute path");
Ok(dir)
}
pub fn echo() -> bool {