Don't migrate existing data dir without version number
If there is a directory but no version number, we have no idea what's going on. If we continue the migration, we might overwrite or break some other program's data.
This commit is contained in:
parent
1f76854aa7
commit
4909aa0a29
2 changed files with 5 additions and 2 deletions
|
|
@ -15,10 +15,12 @@ pub use self::{
|
||||||
|
|
||||||
fn migrate(dir: &LockedDataDir) -> anyhow::Result<()> {
|
fn migrate(dir: &LockedDataDir) -> anyhow::Result<()> {
|
||||||
loop {
|
loop {
|
||||||
match dir.read_version()? {
|
let version = dir.read_version().context("failed to migrate data dir")?;
|
||||||
0 => v0::migrate(dir)?,
|
match version {
|
||||||
|
0 => v0::migrate(dir),
|
||||||
_ => break Ok(()),
|
_ => break Ok(()),
|
||||||
}
|
}
|
||||||
|
.with_context(|| format!("failed to migrate data dir from version {version}"))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,7 @@ impl UnlockedDataDir {
|
||||||
pub(super) fn read_version(&self) -> anyhow::Result<u32> {
|
pub(super) fn read_version(&self) -> anyhow::Result<u32> {
|
||||||
let path = self.version_file();
|
let path = self.version_file();
|
||||||
match self.read_string_optional(&path)? {
|
match self.read_string_optional(&path)? {
|
||||||
|
None if self.path.exists() => Err(anyhow!("found data dir without version number")),
|
||||||
None => Ok(0),
|
None => Ok(0),
|
||||||
Some(string) => Ok(string.trim().parse().with_context(|| {
|
Some(string) => Ok(string.trim().parse().with_context(|| {
|
||||||
format!("failed to parse {} as version number", path.display())
|
format!("failed to parse {} as version number", path.display())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue