mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-17 05:47:45 +00:00
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:
parent
80708dea6e
commit
d052427c37
3 changed files with 11 additions and 11 deletions
|
@ -847,7 +847,7 @@ fn executable_path_from_base(
|
||||||
/// Create a link to a managed Python executable.
|
/// Create a link to a managed Python executable.
|
||||||
///
|
///
|
||||||
/// If the file already exists at the link path, an error will be returned.
|
/// 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)?;
|
let link_parent = link.parent().ok_or(Error::NoExecutableDirectory)?;
|
||||||
fs_err::create_dir_all(link_parent).map_err(|err| Error::ExecutableDirectory {
|
fs_err::create_dir_all(link_parent).map_err(|err| Error::ExecutableDirectory {
|
||||||
to: link_parent.to_path_buf(),
|
to: link_parent.to_path_buf(),
|
||||||
|
@ -856,20 +856,20 @@ pub fn create_link_to_executable(link: &Path, executable: PathBuf) -> Result<(),
|
||||||
|
|
||||||
if cfg!(unix) {
|
if cfg!(unix) {
|
||||||
// Note this will never copy on Unix — we use it here to allow compilation on Windows
|
// 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(()),
|
Ok(()) => Ok(()),
|
||||||
Err(err) if err.kind() == io::ErrorKind::NotFound => {
|
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 {
|
Err(err) => Err(Error::LinkExecutable {
|
||||||
from: executable,
|
from: executable.to_path_buf(),
|
||||||
to: link.to_path_buf(),
|
to: link.to_path_buf(),
|
||||||
err,
|
err,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
} else if cfg!(windows) {
|
} else if cfg!(windows) {
|
||||||
// TODO(zanieb): Install GUI launchers as well
|
// 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
|
// OK to use `std::fs` here, `fs_err` does not support `File::create_new` and we attach
|
||||||
// error context anyway
|
// error context anyway
|
||||||
|
@ -878,7 +878,7 @@ pub fn create_link_to_executable(link: &Path, executable: PathBuf) -> Result<(),
|
||||||
std::fs::File::create_new(link)
|
std::fs::File::create_new(link)
|
||||||
.and_then(|mut file| file.write_all(launcher.as_ref()))
|
.and_then(|mut file| file.write_all(launcher.as_ref()))
|
||||||
.map_err(|err| Error::LinkExecutable {
|
.map_err(|err| Error::LinkExecutable {
|
||||||
from: executable,
|
from: executable.to_path_buf(),
|
||||||
to: link.to_path_buf(),
|
to: link.to_path_buf(),
|
||||||
err,
|
err,
|
||||||
})
|
})
|
||||||
|
|
|
@ -262,10 +262,10 @@ pub(crate) fn create(
|
||||||
if cfg!(windows) {
|
if cfg!(windows) {
|
||||||
if using_minor_version_link {
|
if using_minor_version_link {
|
||||||
let target = scripts.join(WindowsExecutable::Python.exe(interpreter));
|
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)?;
|
.map_err(Error::Python)?;
|
||||||
let targetw = scripts.join(WindowsExecutable::Pythonw.exe(interpreter));
|
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)?;
|
.map_err(Error::Python)?;
|
||||||
} else {
|
} else {
|
||||||
// Always copy `python.exe`.
|
// Always copy `python.exe`.
|
||||||
|
|
|
@ -768,7 +768,7 @@ fn create_bin_links(
|
||||||
installation.executable(false)
|
installation.executable(false)
|
||||||
};
|
};
|
||||||
|
|
||||||
match create_link_to_executable(&target, executable.clone()) {
|
match create_link_to_executable(&target, &executable) {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
debug!(
|
debug!(
|
||||||
"Installed executable at `{}` for {}",
|
"Installed executable at `{}` for {}",
|
||||||
|
@ -925,7 +925,7 @@ fn create_bin_links(
|
||||||
.remove(&target);
|
.remove(&target);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(err) = create_link_to_executable(&target, executable) {
|
if let Err(err) = create_link_to_executable(&target, &executable) {
|
||||||
errors.push((
|
errors.push((
|
||||||
InstallErrorKind::Bin,
|
InstallErrorKind::Bin,
|
||||||
installation.key().clone(),
|
installation.key().clone(),
|
||||||
|
@ -953,7 +953,7 @@ fn create_bin_links(
|
||||||
errors.push((
|
errors.push((
|
||||||
InstallErrorKind::Bin,
|
InstallErrorKind::Bin,
|
||||||
installation.key().clone(),
|
installation.key().clone(),
|
||||||
anyhow::Error::new(err),
|
Error::new(err),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue