Remove compatibility with v0.2.x databases

This commit is contained in:
Ajeet D'Souza 2020-05-04 01:09:01 +05:30
parent 23eea59c70
commit 0c3a8a79c3
3 changed files with 1 additions and 48 deletions

View File

@ -16,8 +16,6 @@ pub struct DB {
data: DBData,
modified: bool,
path: PathBuf,
// FIXME: remove after next breaking version
path_old: Option<PathBuf>,
}
impl DB {
@ -44,34 +42,6 @@ impl DB {
data,
modified: false,
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) {
if let Err(e) = self.save() {
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);
}
}
}
}

View File

@ -13,7 +13,7 @@ use structopt::StructOpt;
use std::process;
#[derive(Debug, StructOpt)]
#[structopt(about = "A cd command that learns your habits", version = env!("ZOXIDE_VERSION"))]
#[structopt(about, version = env!("ZOXIDE_VERSION"))]
enum Zoxide {
Add(subcommand::Add),
Import(subcommand::Import),

View File

@ -47,17 +47,6 @@ pub fn get_db() -> Result<DB> {
let mut db_path = config::zo_data_dir()?;
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)
}
@ -94,7 +83,6 @@ where
dir_frecencies.sort_unstable_by_key(|&(dir, frecency)| Reverse((frecency, &dir.path)));
for &(dir, frecency) in dir_frecencies.iter() {
// ensure that frecency fits in 4 characters
if let Ok(path_bytes) = path_to_bytes(&dir.path) {
(|| {
write!(fzf_stdin, "{:>4} ", frecency)?;