Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Windows-reserved paths consistently on all platforms #10461

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions src/cargo/sources/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,17 +623,15 @@ impl<'cfg> RegistrySource<'cfg> {
prefix
)
}
// Unpacking failed
let mut result = entry.unpack_in(parent).map_err(anyhow::Error::from);
if cfg!(windows) && restricted_names::is_windows_reserved_path(&entry_path) {
result = result.with_context(|| {
format!(
"`{}` appears to contain a reserved Windows path, \
it cannot be extracted on Windows",
entry_path.display()
)
});
if restricted_names::is_windows_reserved_path(&entry_path) {
anyhow::bail!(
"`{}` appears to contain a reserved Windows path, \
it cannot be extracted on Windows",
entry_path.display()
)
}
// Unpacking failed
let result = entry.unpack_in(parent).map_err(anyhow::Error::from);
result
.with_context(|| format!("failed to unpack entry at `{}`", entry_path.display()))?;
}
Expand Down
12 changes: 1 addition & 11 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1888,7 +1888,6 @@ src/lib.rs
}

#[cargo_test]
#[cfg(windows)]
fn reserved_windows_name() {
Package::new("bar", "1.0.0")
.file("src/lib.rs", "pub mod aux;")
Expand Down Expand Up @@ -1925,16 +1924,7 @@ Caused by:
failed to unpack package `[..] `[..]`)`

Caused by:
failed to unpack entry at `[..]aux.rs`

Caused by:
`[..]aux.rs` appears to contain a reserved Windows path, it cannot be extracted on Windows

Caused by:
failed to unpack `[..]aux.rs`

Caused by:
failed to unpack `[..]aux.rs` into `[..]aux.rs`",
`[..]aux.rs` appears to contain a reserved Windows path, it cannot be extracted on Windows",
)
.run();
}
Expand Down