From d6fd90693ee92bdc76f574a88137a9374b943324 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Thu, 12 Mar 2020 14:24:01 -0700 Subject: [PATCH] cleanup --- src/db.rs | 38 ++++++++++---------------------------- src/main.rs | 2 -- 2 files changed, 10 insertions(+), 30 deletions(-) diff --git a/src/db.rs b/src/db.rs index d9b50ed..607261a 100644 --- a/src/db.rs +++ b/src/db.rs @@ -73,8 +73,6 @@ impl DB { pub fn migrate>(&mut self, path: P) -> Result<()> { if !self.dirs.is_empty() { - // FIXME: just for testing - #[cfg(not(debug_assertions))] return Err(anyhow!( "To prevent conflicts, you can only migrate from z with an empty \ zoxide database!" @@ -97,38 +95,23 @@ impl DB { match split_line.as_slice() { [_, rank_str, path_str] => { - let path = PathBuf::from(path_str); - let rank = rank_str - .parse::() - .with_context(|| anyhow!("could not parse rank"))?; - - // otherwise, the rank will get scaled down, depending on - // how old the entry is (import in-place and let zoxide + // Set last_accessed to current time; otherwise, the rank will get scaled down, + // depending on how old the imported entry is (import in-place and let zoxide // scale down organically) let epoch = util::get_current_time()?; + let rank = rank_str + .parse::() + .with_context(|| anyhow!("could not parse rank: '{}'", rank_str))?; - // TODO: does this *need* to be canonicalized? - // 1) the z db already stores canonicalized paths - // 2) zoxide purges nonexistent paths upon query invocation - let path_abs = match path.canonicalize() { - Ok(path) => path, - Err(_) => continue, // ignore dead paths - }; - - // FIXME: Remove when we switch to PathBuf for storing - // diectories inside Dir and just pass `path` (the PathBuf - // constructed from `path-str`) - let path_str = path_abs.to_str().ok_or_else(|| { - anyhow!("invalid unicode in path: {}", path_abs.display()) - })?; - + // FIXME: When we switch to PathBuf for storing directories inside Dir, just + // pass `PathBuf::from(path_str)` self.dirs.push(Dir { - path: path_str.to_owned(), + path: path_str.to_string(), last_accessed: epoch, rank, }); } - [] | [""] => (), + [] | [""] => {} // ignore blank lines line => { eprintln!("invalid line {}: {:?}", line_number, line); continue; @@ -136,8 +119,7 @@ impl DB { }; } - // FIXME: just for testing - self.modified = false; + self.modified = true; Ok(()) } diff --git a/src/main.rs b/src/main.rs index 7b95e5d..7a60442 100644 --- a/src/main.rs +++ b/src/main.rs @@ -99,9 +99,7 @@ pub fn main() -> Result<()> { } Zoxide::Migrate { path } => { let mut db = get_db()?; - db.migrate(path)?; - db.save()?; } Zoxide::Init { shell,