Fix imports

This commit is contained in:
Ajeet D'Souza 2020-06-28 00:21:28 +05:30
parent 11ba2af20e
commit c5bc49884d
4 changed files with 16 additions and 16 deletions

View File

@ -1,6 +1,6 @@
use crate::config;
use crate::db::{Db, Dir, Rank};
use crate::util::{canonicalize, get_current_time, get_db, path_to_str};
use crate::util;
use anyhow::{Context, Result};
use structopt::StructOpt;
@ -32,15 +32,15 @@ impl Add {
fn add<P: AsRef<Path>>(path: P) -> Result<()> {
let path = path.as_ref();
let path = canonicalize(&path)?;
let path = util::canonicalize(&path)?;
if config::zo_exclude_dirs().contains(&path) {
return Ok(());
}
let mut db = get_db()?;
let now = get_current_time()?;
let path = path_to_str(&path)?;
let mut db = util::get_db()?;
let now = util::get_current_time()?;
let path = util::path_to_str(&path)?;
let maxage = config::zo_maxage()?;
match db.dirs.iter_mut().find(|dir| dir.path == path) {

View File

@ -1,5 +1,5 @@
use crate::db::{Db, Dir};
use crate::util::{canonicalize, get_db, path_to_str};
use crate::util;
use anyhow::{bail, Context, Result};
use structopt::StructOpt;
@ -26,7 +26,7 @@ impl Import {
fn import<P: AsRef<Path>>(path: P, merge: bool) -> Result<()> {
let path = path.as_ref();
let mut db = get_db()?;
let mut db = util::get_db()?;
if !db.dirs.is_empty() && !merge {
bail!(
@ -70,8 +70,8 @@ fn import_line(db: &mut Db, line: &str) -> Result<()> {
.parse::<f64>()
.with_context(|| format!("invalid rank: {}", rank_str))?;
let path = canonicalize(&path)?;
let path = path_to_str(&path)?;
let path = util::canonicalize(&path)?;
let path = util::path_to_str(&path)?;
// If the path exists in the database, add the ranks and set the epoch to
// the more recent of the parsed epoch and the already present epoch.

View File

@ -1,5 +1,5 @@
use super::{HookConfig, ShellConfig};
use crate::util::path_to_str;
use crate::util;
use anyhow::Result;
use uuid::Uuid;
@ -80,10 +80,10 @@ esac
fn hook_pwd() -> Result<Cow<'static, str>> {
let mut tmp_path = std::env::temp_dir();
tmp_path.push("zoxide");
let tmp_path_str = path_to_str(&tmp_path)?;
let tmp_path_str = util::path_to_str(&tmp_path)?;
let pwd_path = tmp_path.join(format!("pwd-{}", Uuid::new_v4()));
let pwd_path_str = path_to_str(&pwd_path)?;
let pwd_path_str = util::path_to_str(&pwd_path)?;
let hook_pwd = format!(
r#"

View File

@ -1,4 +1,4 @@
use crate::util::{canonicalize, get_db, path_to_str};
use crate::util;
use anyhow::{bail, Result};
use structopt::StructOpt;
@ -17,7 +17,7 @@ impl Remove {
}
fn remove(path: &str) -> Result<()> {
let mut db = get_db()?;
let mut db = util::get_db()?;
if let Some(idx) = db.dirs.iter().position(|dir| dir.path == path) {
db.dirs.swap_remove(idx);
@ -25,8 +25,8 @@ fn remove(path: &str) -> Result<()> {
return Ok(());
}
let path = canonicalize(&path)?;
let path = path_to_str(&path)?;
let path = util::canonicalize(&path)?;
let path = util::path_to_str(&path)?;
if let Some(idx) = db.dirs.iter().position(|dir| dir.path == path) {
db.dirs.swap_remove(idx);