Remove compatibility with v0.2.x databases
This commit is contained in:
parent
23eea59c70
commit
0c3a8a79c3
35
src/db.rs
35
src/db.rs
|
@ -16,8 +16,6 @@ pub struct DB {
|
||||||
data: DBData,
|
data: DBData,
|
||||||
modified: bool,
|
modified: bool,
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
// FIXME: remove after next breaking version
|
|
||||||
path_old: Option<PathBuf>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DB {
|
impl DB {
|
||||||
|
@ -44,34 +42,6 @@ impl DB {
|
||||||
data,
|
data,
|
||||||
modified: false,
|
modified: false,
|
||||||
path: path.as_ref().to_path_buf(),
|
path: path.as_ref().to_path_buf(),
|
||||||
path_old: None,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: remove after next breaking version
|
|
||||||
pub fn open_and_migrate<P1, P2>(path_old: P1, path: P2) -> Result<DB>
|
|
||||||
where
|
|
||||||
P1: AsRef<Path>,
|
|
||||||
P2: AsRef<Path>,
|
|
||||||
{
|
|
||||||
let file = File::open(&path_old).context("could not open old database file")?;
|
|
||||||
let reader = BufReader::new(&file);
|
|
||||||
|
|
||||||
let dirs = bincode::config()
|
|
||||||
.limit(config::DB_MAX_SIZE)
|
|
||||||
.deserialize_from(reader)
|
|
||||||
.context("could not deserialize old database")?;
|
|
||||||
|
|
||||||
let data = DBData {
|
|
||||||
version: config::DB_VERSION,
|
|
||||||
dirs,
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(DB {
|
|
||||||
data,
|
|
||||||
modified: true,
|
|
||||||
path: path.as_ref().to_path_buf(),
|
|
||||||
path_old: Some(path_old.as_ref().to_path_buf()),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,11 +265,6 @@ impl Drop for DB {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if let Err(e) = self.save() {
|
if let Err(e) = self.save() {
|
||||||
eprintln!("{:#}", e);
|
eprintln!("{:#}", e);
|
||||||
} else if let Some(path_old) = &self.path_old {
|
|
||||||
// FIXME: remove this branch after next breaking release
|
|
||||||
if let Err(e) = fs::remove_file(path_old).context("could not remove old database") {
|
|
||||||
eprintln!("{:#}", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ use structopt::StructOpt;
|
||||||
use std::process;
|
use std::process;
|
||||||
|
|
||||||
#[derive(Debug, StructOpt)]
|
#[derive(Debug, StructOpt)]
|
||||||
#[structopt(about = "A cd command that learns your habits", version = env!("ZOXIDE_VERSION"))]
|
#[structopt(about, version = env!("ZOXIDE_VERSION"))]
|
||||||
enum Zoxide {
|
enum Zoxide {
|
||||||
Add(subcommand::Add),
|
Add(subcommand::Add),
|
||||||
Import(subcommand::Import),
|
Import(subcommand::Import),
|
||||||
|
|
12
src/util.rs
12
src/util.rs
|
@ -47,17 +47,6 @@ pub fn get_db() -> Result<DB> {
|
||||||
let mut db_path = config::zo_data_dir()?;
|
let mut db_path = config::zo_data_dir()?;
|
||||||
db_path.push("db.zo");
|
db_path.push("db.zo");
|
||||||
|
|
||||||
// FIXME: fallback to old database location; remove in next breaking version
|
|
||||||
if !db_path.is_file() {
|
|
||||||
if let Some(mut old_db_path) = dirs::home_dir() {
|
|
||||||
old_db_path.push(".zo");
|
|
||||||
|
|
||||||
if old_db_path.is_file() {
|
|
||||||
return DB::open_and_migrate(old_db_path, db_path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DB::open(db_path)
|
DB::open(db_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +83,6 @@ where
|
||||||
dir_frecencies.sort_unstable_by_key(|&(dir, frecency)| Reverse((frecency, &dir.path)));
|
dir_frecencies.sort_unstable_by_key(|&(dir, frecency)| Reverse((frecency, &dir.path)));
|
||||||
|
|
||||||
for &(dir, frecency) in dir_frecencies.iter() {
|
for &(dir, frecency) in dir_frecencies.iter() {
|
||||||
// ensure that frecency fits in 4 characters
|
|
||||||
if let Ok(path_bytes) = path_to_bytes(&dir.path) {
|
if let Ok(path_bytes) = path_to_bytes(&dir.path) {
|
||||||
(|| {
|
(|| {
|
||||||
write!(fzf_stdin, "{:>4} ", frecency)?;
|
write!(fzf_stdin, "{:>4} ", frecency)?;
|
||||||
|
|
Loading…
Reference in New Issue