Skip to content

Commit 5f6997f

Browse files
committed
Make restore more robust
1 parent b984283 commit 5f6997f

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

xtask/src/documentation.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ fn cargo_doc(workspace: &Path, package: Package, chip: Option<Chip>) -> Result<P
190190
cargo_doc_res
191191
} else {
192192
// Restore the original Cargo.toml
193-
restore_cargo_toml(package_path).ok();
193+
restore_cargo_toml(package_path)?;
194194
Err(pre_process_res.err().unwrap())
195195
}
196196
}
@@ -370,13 +370,16 @@ fn pre_process_cargo_toml(chip: Option<Chip>, package_path: &PathBuf) -> Result<
370370

371371
/// Restore the original Cargo.toml file
372372
fn restore_cargo_toml(package_path: PathBuf) -> Result<(), anyhow::Error> {
373-
std::fs::remove_file(windows_safe_path(&package_path.join("Cargo.toml"))).ok();
373+
if std::fs::exists(windows_safe_path(&package_path.join("Cargo.toml_original")))? {
374+
if std::fs::exists(windows_safe_path(&package_path.join("Cargo.toml")))? {
375+
std::fs::remove_file(windows_safe_path(&package_path.join("Cargo.toml")))?;
376+
}
374377

375-
std::fs::rename(
376-
windows_safe_path(&package_path.join("Cargo.toml_original")),
377-
windows_safe_path(&package_path.join("Cargo.toml")),
378-
)
379-
.ok();
378+
std::fs::rename(
379+
windows_safe_path(&package_path.join("Cargo.toml_original")),
380+
windows_safe_path(&package_path.join("Cargo.toml")),
381+
)?;
382+
}
380383

381384
Ok(())
382385
}

0 commit comments

Comments
 (0)