cleanup
This commit is contained in:
parent
5637996171
commit
d6fd90693e
38
src/db.rs
38
src/db.rs
|
|
@ -73,8 +73,6 @@ impl DB {
|
||||||
|
|
||||||
pub fn migrate<P: AsRef<Path>>(&mut self, path: P) -> Result<()> {
|
pub fn migrate<P: AsRef<Path>>(&mut self, path: P) -> Result<()> {
|
||||||
if !self.dirs.is_empty() {
|
if !self.dirs.is_empty() {
|
||||||
// FIXME: just for testing
|
|
||||||
#[cfg(not(debug_assertions))]
|
|
||||||
return Err(anyhow!(
|
return Err(anyhow!(
|
||||||
"To prevent conflicts, you can only migrate from z with an empty \
|
"To prevent conflicts, you can only migrate from z with an empty \
|
||||||
zoxide database!"
|
zoxide database!"
|
||||||
|
|
@ -97,38 +95,23 @@ impl DB {
|
||||||
|
|
||||||
match split_line.as_slice() {
|
match split_line.as_slice() {
|
||||||
[_, rank_str, path_str] => {
|
[_, rank_str, path_str] => {
|
||||||
let path = PathBuf::from(path_str);
|
// Set last_accessed to current time; otherwise, the rank will get scaled down,
|
||||||
let rank = rank_str
|
// depending on how old the imported entry is (import in-place and let zoxide
|
||||||
.parse::<f64>()
|
|
||||||
.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
|
|
||||||
// scale down organically)
|
// scale down organically)
|
||||||
let epoch = util::get_current_time()?;
|
let epoch = util::get_current_time()?;
|
||||||
|
let rank = rank_str
|
||||||
|
.parse::<f64>()
|
||||||
|
.with_context(|| anyhow!("could not parse rank: '{}'", rank_str))?;
|
||||||
|
|
||||||
// TODO: does this *need* to be canonicalized?
|
// FIXME: When we switch to PathBuf for storing directories inside Dir, just
|
||||||
// 1) the z db already stores canonicalized paths
|
// pass `PathBuf::from(path_str)`
|
||||||
// 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())
|
|
||||||
})?;
|
|
||||||
|
|
||||||
self.dirs.push(Dir {
|
self.dirs.push(Dir {
|
||||||
path: path_str.to_owned(),
|
path: path_str.to_string(),
|
||||||
last_accessed: epoch,
|
last_accessed: epoch,
|
||||||
rank,
|
rank,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
[] | [""] => (),
|
[] | [""] => {} // ignore blank lines
|
||||||
line => {
|
line => {
|
||||||
eprintln!("invalid line {}: {:?}", line_number, line);
|
eprintln!("invalid line {}: {:?}", line_number, line);
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -136,8 +119,7 @@ impl DB {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: just for testing
|
self.modified = true;
|
||||||
self.modified = false;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -99,9 +99,7 @@ pub fn main() -> Result<()> {
|
||||||
}
|
}
|
||||||
Zoxide::Migrate { path } => {
|
Zoxide::Migrate { path } => {
|
||||||
let mut db = get_db()?;
|
let mut db = get_db()?;
|
||||||
|
|
||||||
db.migrate(path)?;
|
db.migrate(path)?;
|
||||||
db.save()?;
|
|
||||||
}
|
}
|
||||||
Zoxide::Init {
|
Zoxide::Init {
|
||||||
shell,
|
shell,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue