Skip to content

Commit 3218e36

Browse files
authored
Use fs_err for paths in symlinking errors (#13303)
In #13302, there was an IO error without context. This error seems to be caused by a symlink error. Switching as symlinking to `fs_err` ensures these errors will carry context in the future.
1 parent f557ea3 commit 3218e36

File tree

9 files changed

+18
-14
lines changed

9 files changed

+18
-14
lines changed

clippy.toml

+3
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,7 @@ disallowed-methods = [
3535
"std::fs::soft_link",
3636
"std::fs::symlink_metadata",
3737
"std::fs::write",
38+
"std::os::unix::fs::symlink",
39+
"std::os::windows::fs::symlink_dir",
40+
"std::os::windows::fs::symlink_file",
3841
]

crates/uv-cache/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -653,13 +653,13 @@ impl Cache {
653653
let dst = dst.as_ref();
654654

655655
// Attempt to create the symlink directly.
656-
match std::os::unix::fs::symlink(&src, dst) {
656+
match fs_err::os::unix::fs::symlink(&src, dst) {
657657
Ok(()) => Ok(()),
658658
Err(err) if err.kind() == io::ErrorKind::AlreadyExists => {
659659
// Create a symlink, using a temporary file to ensure atomicity.
660660
let temp_dir = tempfile::tempdir_in(dst.parent().unwrap())?;
661661
let temp_file = temp_dir.path().join("link");
662-
std::os::unix::fs::symlink(&src, &temp_file)?;
662+
fs_err::os::unix::fs::symlink(&src, &temp_file)?;
663663

664664
// Move the symlink into the target location.
665665
fs_err::rename(&temp_file, dst)?;

crates/uv-fs/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ pub fn replace_symlink(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> std::io:
121121
#[cfg(unix)]
122122
pub fn replace_symlink(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> std::io::Result<()> {
123123
// Attempt to create the symlink directly.
124-
match std::os::unix::fs::symlink(src.as_ref(), dst.as_ref()) {
124+
match fs_err::os::unix::fs::symlink(src.as_ref(), dst.as_ref()) {
125125
Ok(()) => Ok(()),
126126
Err(err) if err.kind() == std::io::ErrorKind::AlreadyExists => {
127127
// Create a symlink, using a temporary file to ensure atomicity.
128128
let temp_dir = tempfile::tempdir_in(dst.as_ref().parent().unwrap())?;
129129
let temp_file = temp_dir.path().join("link");
130-
std::os::unix::fs::symlink(src, &temp_file)?;
130+
fs_err::os::unix::fs::symlink(src, &temp_file)?;
131131

132132
// Move the symlink into the target location.
133133
fs_err::rename(&temp_file, dst.as_ref())?;

crates/uv-install-wheel/src/linker.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -493,14 +493,14 @@ fn synchronized_copy(from: &Path, to: &Path, locks: &Locks) -> std::io::Result<(
493493

494494
#[cfg(unix)]
495495
fn create_symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> std::io::Result<()> {
496-
std::os::unix::fs::symlink(original, link)
496+
fs_err::os::unix::fs::symlink(original, link)
497497
}
498498

499499
#[cfg(windows)]
500500
fn create_symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> std::io::Result<()> {
501501
if original.as_ref().is_dir() {
502-
std::os::windows::fs::symlink_dir(original, link)
502+
fs_err::os::windows::fs::symlink_dir(original, link)
503503
} else {
504-
std::os::windows::fs::symlink_file(original, link)
504+
fs_err::os::windows::fs::symlink_file(original, link)
505505
}
506506
}

crates/uv-python/src/downloads.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ impl ManagedPythonDownload {
761761
// to that date do not.
762762
#[cfg(unix)]
763763
{
764-
match std::os::unix::fs::symlink(
764+
match fs_err::os::unix::fs::symlink(
765765
format!("python{}.{}", self.key.major, self.key.minor),
766766
extracted.join("bin").join("python"),
767767
) {

crates/uv-virtualenv/src/virtualenv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ pub(crate) fn create(
384384
&& interpreter.markers().os_name() == "posix"
385385
&& interpreter.markers().sys_platform() != "darwin"
386386
{
387-
match std::os::unix::fs::symlink("lib", location.join("lib64")) {
387+
match fs_err::os::unix::fs::symlink("lib", location.join("lib64")) {
388388
Ok(()) => {}
389389
Err(err) if err.kind() == io::ErrorKind::AlreadyExists => {}
390390
Err(err) => {

crates/uv/tests/it/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,7 @@ fn build_with_symlink() -> Result<()> {
17651765
requires = ["hatchling"]
17661766
build-backend = "hatchling.build"
17671767
"#})?;
1768-
std::os::unix::fs::symlink(
1768+
fs_err::os::unix::fs::symlink(
17691769
context.temp_dir.child("pyproject.toml.real"),
17701770
context.temp_dir.child("pyproject.toml"),
17711771
)?;

crates/uv/tests/it/pip_install.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3723,7 +3723,7 @@ fn launcher_with_symlink() -> Result<()> {
37233723
);
37243724

37253725
#[cfg(windows)]
3726-
if let Err(error) = std::os::windows::fs::symlink_file(
3726+
if let Err(error) = fs_err::os::windows::fs::symlink_file(
37273727
context.venv.join("Scripts\\simple_launcher.exe"),
37283728
context.temp_dir.join("simple_launcher.exe"),
37293729
) {
@@ -3736,7 +3736,7 @@ fn launcher_with_symlink() -> Result<()> {
37363736
}
37373737

37383738
#[cfg(unix)]
3739-
std::os::unix::fs::symlink(
3739+
fs_err::os::unix::fs::symlink(
37403740
context.venv.join("bin/simple_launcher"),
37413741
context.temp_dir.join("simple_launcher"),
37423742
)?;
@@ -8123,7 +8123,7 @@ fn install_relocatable() -> Result<()> {
81238123
#[cfg(unix)]
81248124
{
81258125
let script_symlink_path = context.temp_dir.join("black");
8126-
std::os::unix::fs::symlink(script_path, script_symlink_path.clone())?;
8126+
fs_err::os::unix::fs::symlink(script_path, script_symlink_path.clone())?;
81278127
Command::new(script_symlink_path.as_os_str())
81288128
.assert()
81298129
.success()

crates/uv/tests/it/python_find.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,8 @@ fn python_required_python_major_minor() {
746746

747747
// Symlink it to `python3.11`.
748748
fs_err::create_dir_all(context.temp_dir.child("child")).unwrap();
749-
std::os::unix::fs::symlink(path, context.temp_dir.child("child").join("python3.11")).unwrap();
749+
fs_err::os::unix::fs::symlink(path, context.temp_dir.child("child").join("python3.11"))
750+
.unwrap();
750751

751752
// Find `python3.11`, which is `>=3.11.4`.
752753
uv_snapshot!(context.filters(), context.python_find().arg(">=3.11.4, <3.12").env(EnvVars::UV_TEST_PYTHON_PATH, context.temp_dir.child("child").path()), @r###"

0 commit comments

Comments
 (0)