From b881866216d53239d0337feac4e19008f9a7f340 Mon Sep 17 00:00:00 2001 From: Ajeet D'Souza <98ajeet@gmail.com> Date: Thu, 20 Jun 2024 20:41:20 +0530 Subject: [PATCH] Verify that _ZO_DATA_DIR is an absolute path --- src/config.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/config.rs b/src/config.rs index 4a1b6b4..4b46a78 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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 { - 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 {