Accept &Path when creating executable links (#14791)

## Summary

I don't see a great reason for this to take an owned value. It only
needs an owned value for error cases.
This commit is contained in:
Charlie Marsh 2025-07-21 11:53:28 -04:00 committed by GitHub
parent 80708dea6e
commit d052427c37
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 11 deletions

View file

@ -847,7 +847,7 @@ fn executable_path_from_base(
/// Create a link to a managed Python executable.
///
/// If the file already exists at the link path, an error will be returned.
pub fn create_link_to_executable(link: &Path, executable: PathBuf) -> Result<(), Error> {
pub fn create_link_to_executable(link: &Path, executable: &Path) -> Result<(), Error> {
let link_parent = link.parent().ok_or(Error::NoExecutableDirectory)?;
fs_err::create_dir_all(link_parent).map_err(|err| Error::ExecutableDirectory {
to: link_parent.to_path_buf(),
@ -856,20 +856,20 @@ pub fn create_link_to_executable(link: &Path, executable: PathBuf) -> Result<(),
if cfg!(unix) {
// Note this will never copy on Unix — we use it here to allow compilation on Windows
match symlink_or_copy_file(&executable, link) {
match symlink_or_copy_file(executable, link) {
Ok(()) => Ok(()),
Err(err) if err.kind() == io::ErrorKind::NotFound => {
Err(Error::MissingExecutable(executable.clone()))
Err(Error::MissingExecutable(executable.to_path_buf()))
}
Err(err) => Err(Error::LinkExecutable {
from: executable,
from: executable.to_path_buf(),
to: link.to_path_buf(),
err,
}),
}
} else if cfg!(windows) {
// TODO(zanieb): Install GUI launchers as well
let launcher = windows_python_launcher(&executable, false)?;
let launcher = windows_python_launcher(executable, false)?;
// OK to use `std::fs` here, `fs_err` does not support `File::create_new` and we attach
// error context anyway
@ -878,7 +878,7 @@ pub fn create_link_to_executable(link: &Path, executable: PathBuf) -> Result<(),
std::fs::File::create_new(link)
.and_then(|mut file| file.write_all(launcher.as_ref()))
.map_err(|err| Error::LinkExecutable {
from: executable,
from: executable.to_path_buf(),
to: link.to_path_buf(),
err,
})

View file

@ -262,10 +262,10 @@ pub(crate) fn create(
if cfg!(windows) {
if using_minor_version_link {
let target = scripts.join(WindowsExecutable::Python.exe(interpreter));
create_link_to_executable(target.as_path(), executable_target.clone())
create_link_to_executable(target.as_path(), &executable_target)
.map_err(Error::Python)?;
let targetw = scripts.join(WindowsExecutable::Pythonw.exe(interpreter));
create_link_to_executable(targetw.as_path(), executable_target)
create_link_to_executable(targetw.as_path(), &executable_target)
.map_err(Error::Python)?;
} else {
// Always copy `python.exe`.

View file

@ -768,7 +768,7 @@ fn create_bin_links(
installation.executable(false)
};
match create_link_to_executable(&target, executable.clone()) {
match create_link_to_executable(&target, &executable) {
Ok(()) => {
debug!(
"Installed executable at `{}` for {}",
@ -925,7 +925,7 @@ fn create_bin_links(
.remove(&target);
}
if let Err(err) = create_link_to_executable(&target, executable) {
if let Err(err) = create_link_to_executable(&target, &executable) {
errors.push((
InstallErrorKind::Bin,
installation.key().clone(),
@ -953,7 +953,7 @@ fn create_bin_links(
errors.push((
InstallErrorKind::Bin,
installation.key().clone(),
anyhow::Error::new(err),
Error::new(err),
));
}
}