mirror of
https://github.com/astral-sh/uv.git
synced 2025-09-29 13:34:47 +00:00
Revert pyproject.toml
modifications on Ctrl-C (#7024)
## Summary Not perfect, but an improvement at least for an interactive experience. Closes #6818.
This commit is contained in:
parent
2b294b90f2
commit
ae144e05ac
3 changed files with 23 additions and 2 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -4463,6 +4463,7 @@ dependencies = [
|
|||
"byteorder",
|
||||
"cache-key",
|
||||
"clap",
|
||||
"ctrlc",
|
||||
"distribution-types",
|
||||
"etcetera",
|
||||
"filetime",
|
||||
|
|
|
@ -48,6 +48,7 @@ anstream = { workspace = true }
|
|||
anyhow = { workspace = true }
|
||||
axoupdater = { workspace = true, features = ["github_releases", "tokio"], optional = true }
|
||||
clap = { workspace = true, features = ["derive", "string", "wrap_help"] }
|
||||
ctrlc = { workspace = true }
|
||||
flate2 = { workspace = true, default-features = false }
|
||||
fs-err = { workspace = true, features = ["tokio"] }
|
||||
futures = { workspace = true }
|
||||
|
|
|
@ -488,6 +488,25 @@ pub(crate) async fn add(
|
|||
.with_pyproject_toml(toml::from_str(&content).map_err(ProjectError::TomlParse)?)
|
||||
.ok_or(ProjectError::TomlUpdate)?;
|
||||
|
||||
// Set the Ctrl-C handler to revert changes on exit.
|
||||
let _ = ctrlc::set_handler({
|
||||
let root = root.clone();
|
||||
let existing = existing.clone();
|
||||
move || {
|
||||
// Revert the changes to the `pyproject.toml`, if necessary.
|
||||
if modified {
|
||||
let _ = fs_err::write(root.join("pyproject.toml"), &existing);
|
||||
}
|
||||
|
||||
#[allow(clippy::exit, clippy::cast_possible_wrap)]
|
||||
std::process::exit(if cfg!(windows) {
|
||||
0xC000_013A_u32 as i32
|
||||
} else {
|
||||
130
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
match lock_and_sync(
|
||||
project,
|
||||
&mut toml,
|
||||
|
@ -518,7 +537,7 @@ pub(crate) async fn add(
|
|||
|
||||
// Revert the changes to the `pyproject.toml`, if necessary.
|
||||
if modified {
|
||||
fs_err::write(root.join("pyproject.toml"), existing)?;
|
||||
fs_err::write(root.join("pyproject.toml"), &existing)?;
|
||||
}
|
||||
|
||||
Ok(ExitStatus::Failure)
|
||||
|
@ -526,7 +545,7 @@ pub(crate) async fn add(
|
|||
Err(err) => {
|
||||
// Revert the changes to the `pyproject.toml`, if necessary.
|
||||
if modified {
|
||||
fs_err::write(root.join("pyproject.toml"), existing)?;
|
||||
fs_err::write(root.join("pyproject.toml"), &existing)?;
|
||||
}
|
||||
Err(err.into())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue