Allow symlinks to files in scripts directory (#5380)

## Summary

Closes https://github.com/astral-sh/uv/issues/5359.

## Test Plan

Unfortunately, the only packages I know of that use this are Ruff and
uv, and both are too heavy to install in a recurring test, so:

`uv tool install hatch==1.12.0 --with uv==0.2.27 --force
--link-mode=symlink`
This commit is contained in:
Charlie Marsh 2024-07-23 18:24:43 -04:00 committed by GitHub
parent 8942ec36c0
commit ad4a15d0c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 82 additions and 11 deletions

View file

@ -441,13 +441,31 @@ fn install_script(
record: &mut [RecordEntry],
file: &DirEntry,
) -> Result<(), Error> {
if !file.file_type()?.is_file() {
let file_type = file.file_type()?;
if file_type.is_dir() {
return Err(Error::InvalidWheel(format!(
"Wheel contains entry in scripts directory that is not a file: {}",
file.path().display()
"Wheel contains an invalid entry (directory) in the `scripts` directory: {}",
file.path().simplified_display()
)));
}
if file_type.is_symlink() {
let Ok(target) = file.path().canonicalize() else {
return Err(Error::InvalidWheel(format!(
"Wheel contains an invalid entry (broken symlink) in the `scripts` directory: {}",
file.path().simplified_display(),
)));
};
if target.is_dir() {
return Err(Error::InvalidWheel(format!(
"Wheel contains an invalid entry (directory symlink) in the `scripts` directory: {} ({})",
file.path().simplified_display(),
target.simplified_display()
)));
}
}
let script_absolute = layout.scheme.scripts.join(file.file_name());
let script_relative =
pathdiff::diff_paths(&script_absolute, site_packages).ok_or_else(|| {