Skip to content

Commit

Permalink
Fix wipe command leaving database in inconsistent state if lock acqui…
Browse files Browse the repository at this point in the history
…sition fails
  • Loading branch information
Alex Saveau committed Nov 30, 2024
1 parent d650890 commit ba8edcb
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,29 +735,35 @@ fn wipe() -> Result<(), CliError> {
std::process::exit(1)
};

let data_dir = data_dir();
let mut tmp_data_dir = data_dir.with_extension("tmp");
match fs::rename(&data_dir, &tmp_data_dir) {
Err(e) if e.kind() == ErrorKind::NotFound => {
println!("Nothing to delete");
return Ok(());
}
r => r,
}
.map_io_err(|| format!("Failed to rename dir: {data_dir:?} -> {tmp_data_dir:?}"))?;
let mut data_dir = data_dir();

data_dir.push(".nuke.server.lock");
let mut extra_buffer = data_dir.clone();
data_dir.pop();

tmp_data_dir.push("server.lock");
data_dir.push("server.lock");
acquire_lock_file(
&mut false,
CWD,
tmp_data_dir.parent().unwrap(),
&tmp_data_dir.with_file_name(".nuke.server.lock"),
&tmp_data_dir,
data_dir.parent().unwrap(),
&extra_buffer,
&data_dir,
SendQuitAndWait,
)?;
tmp_data_dir.pop();
data_dir.pop();

extra_buffer.pop();
extra_buffer.set_extension("tmp");
match fs::rename(&data_dir, &extra_buffer) {
Err(e) if e.kind() == ErrorKind::NotFound => {
println!("Nothing to delete");
return Ok(());
}
r => r,
}
.map_io_err(|| format!("Failed to rename dir: {data_dir:?} -> {extra_buffer:?}"))?;

fuc_engine::remove_dir_all(tmp_data_dir)?;
fuc_engine::remove_dir_all(extra_buffer)?;
println!("Wiped.");

Ok(())
Expand Down

0 comments on commit ba8edcb

Please sign in to comment.