Verify that _ZO_DATA_DIR is an absolute path
This commit is contained in:
parent
dbe6f185cf
commit
b881866216
|
@ -2,19 +2,21 @@ use std::env;
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{ensure, Context, Result};
|
||||||
use glob::Pattern;
|
use glob::Pattern;
|
||||||
|
|
||||||
use crate::db::Rank;
|
use crate::db::Rank;
|
||||||
|
|
||||||
pub fn data_dir() -> Result<PathBuf> {
|
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),
|
Some(path) => PathBuf::from(path),
|
||||||
None => dirs::data_local_dir()
|
None => dirs::data_local_dir()
|
||||||
.context("could not find data directory, please set _ZO_DATA_DIR manually")?
|
.context("could not find data directory, please set _ZO_DATA_DIR manually")?
|
||||||
.join("zoxide"),
|
.join("zoxide"),
|
||||||
};
|
};
|
||||||
Ok(path)
|
|
||||||
|
ensure!(dir.is_absolute(), "_ZO_DATA_DIR must be an absolute path");
|
||||||
|
Ok(dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn echo() -> bool {
|
pub fn echo() -> bool {
|
||||||
|
|
Loading…
Reference in New Issue