Skip to content

Commit 36731f8

Browse files
committed
Disambiguate symlink argument names
Mirrors rust-lang/rust#79060.
1 parent 2757ca8 commit 36731f8

File tree

4 files changed

+41
-38
lines changed

4 files changed

+41
-38
lines changed

gen/build/src/out.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,39 +28,39 @@ pub(crate) fn write(path: impl AsRef<Path>, content: &[u8]) -> Result<()> {
2828
}
2929
}
3030

31-
pub(crate) fn symlink_file(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> Result<()> {
32-
let src = src.as_ref();
33-
let dst = dst.as_ref();
31+
pub(crate) fn symlink_file(original: impl AsRef<Path>, link: impl AsRef<Path>) -> Result<()> {
32+
let original = original.as_ref();
33+
let link = link.as_ref();
3434

3535
let mut create_dir_error = None;
36-
if dst.exists() {
37-
let _ = fs::remove_file(dst).unwrap();
36+
if link.exists() {
37+
let _ = fs::remove_file(link).unwrap();
3838
} else {
39-
let parent = dst.parent().unwrap();
39+
let parent = link.parent().unwrap();
4040
create_dir_error = fs::create_dir_all(parent).err();
4141
}
4242

43-
match paths::symlink_or_copy(src, dst) {
43+
match paths::symlink_or_copy(original, link) {
4444
// As long as symlink_or_copy succeeded, ignore any create_dir_all error.
4545
Ok(()) => Ok(()),
4646
// If create_dir_all and symlink_or_copy both failed, prefer the first error.
4747
Err(err) => Err(Error::Fs(create_dir_error.unwrap_or(err))),
4848
}
4949
}
5050

51-
pub(crate) fn symlink_dir(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> Result<()> {
52-
let src = src.as_ref();
53-
let dst = dst.as_ref();
51+
pub(crate) fn symlink_dir(original: impl AsRef<Path>, link: impl AsRef<Path>) -> Result<()> {
52+
let original = original.as_ref();
53+
let link = link.as_ref();
5454

5555
let mut create_dir_error = None;
56-
if dst.exists() {
57-
let _ = paths::remove_symlink_dir(dst).unwrap();
56+
if link.exists() {
57+
let _ = paths::remove_symlink_dir(link).unwrap();
5858
} else {
59-
let parent = dst.parent().unwrap();
59+
let parent = link.parent().unwrap();
6060
create_dir_error = fs::create_dir_all(parent).err();
6161
}
6262

63-
match paths::symlink_dir(src, dst) {
63+
match paths::symlink_dir(original, link) {
6464
// As long as symlink_dir succeeded, ignore any create_dir_all error.
6565
Ok(()) => Ok(()),
6666
// If create_dir_all and symlink_dir both failed, prefer the first error.

gen/build/src/paths.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,16 @@ impl PathExt for Path {
4343
pub(crate) use self::fs::symlink_file as symlink_or_copy;
4444

4545
#[cfg(windows)]
46-
pub(crate) fn symlink_or_copy(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> fs::Result<()> {
46+
pub(crate) fn symlink_or_copy(
47+
original: impl AsRef<Path>,
48+
link: impl AsRef<Path>,
49+
) -> fs::Result<()> {
4750
// Pre-Windows 10, symlinks require admin privileges. Since Windows 10, they
4851
// require Developer Mode. If it fails, fall back to copying the file.
49-
let src = src.as_ref();
50-
let dst = dst.as_ref();
51-
if fs::symlink_file(src, dst).is_err() {
52-
fs::copy(src, dst)?;
52+
let original = original.as_ref();
53+
let link = link.as_ref();
54+
if fs::symlink_file(original, link).is_err() {
55+
fs::copy(original, link)?;
5356
}
5457
Ok(())
5558
}
@@ -61,7 +64,7 @@ pub(crate) use self::fs::copy as symlink_or_copy;
6164
pub(crate) use self::fs::symlink_dir;
6265

6366
#[cfg(not(any(unix, windows)))]
64-
pub(crate) fn symlink_dir(_src: impl AsRef<Path>, _dst: impl AsRef<Path>) -> fs::Result<()> {
67+
pub(crate) fn symlink_dir(_original: impl AsRef<Path>, _link: impl AsRef<Path>) -> fs::Result<()> {
6568
Ok(())
6669
}
6770

gen/src/fs.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,17 @@ pub(crate) fn remove_dir(path: impl AsRef<Path>) -> Result<()> {
9191
}
9292

9393
fn symlink<'a>(
94-
src: &'a Path,
95-
dst: &'a Path,
94+
original: &'a Path,
95+
link: &'a Path,
9696
fun: fn(&'a Path, &'a Path) -> io::Result<()>,
9797
) -> Result<()> {
98-
match fun(src, dst) {
98+
match fun(original, link) {
9999
Ok(()) => Ok(()),
100100
Err(e) => err!(
101101
e,
102102
"Failed to create symlink `{}` pointing to `{}`",
103-
dst,
104-
src,
103+
link,
104+
original,
105105
),
106106
}
107107
}
@@ -111,24 +111,24 @@ fn symlink<'a>(
111111
pub(crate) use self::symlink_file as symlink_dir;
112112

113113
#[cfg(unix)]
114-
pub(crate) fn symlink_file(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> Result<()> {
115-
symlink(src.as_ref(), dst.as_ref(), std::os::unix::fs::symlink)
114+
pub(crate) fn symlink_file(original: impl AsRef<Path>, link: impl AsRef<Path>) -> Result<()> {
115+
symlink(original.as_ref(), link.as_ref(), std::os::unix::fs::symlink)
116116
}
117117

118118
#[cfg(windows)]
119-
pub(crate) fn symlink_file(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> Result<()> {
119+
pub(crate) fn symlink_file(original: impl AsRef<Path>, link: impl AsRef<Path>) -> Result<()> {
120120
symlink(
121-
src.as_ref(),
122-
dst.as_ref(),
121+
original.as_ref(),
122+
link.as_ref(),
123123
std::os::windows::fs::symlink_file,
124124
)
125125
}
126126

127127
#[cfg(windows)]
128-
pub(crate) fn symlink_dir(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> Result<()> {
128+
pub(crate) fn symlink_dir(original: impl AsRef<Path>, link: impl AsRef<Path>) -> Result<()> {
129129
symlink(
130-
src.as_ref(),
131-
dst.as_ref(),
130+
original.as_ref(),
131+
link.as_ref(),
132132
std::os::windows::fs::symlink_dir,
133133
)
134134
}

tools/cargo/build.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ fn main() {
5858
#[cfg(windows)]
5959
if let Some(out_dir) = env::var_os("OUT_DIR") {
6060
let parent_dir = Path::new(&out_dir).join("symlink");
61-
let from_dir = parent_dir.join("from");
62-
let to_dir = parent_dir.join("to");
63-
if fs::create_dir_all(&from_dir).is_ok()
64-
&& (!to_dir.exists() || fs::remove_dir(&to_dir).is_ok())
65-
&& windows::symlink_dir(&from_dir, &to_dir).is_err()
61+
let original_dir = parent_dir.join("original");
62+
let link_dir = parent_dir.join("link");
63+
if fs::create_dir_all(&original_dir).is_ok()
64+
&& (!link_dir.exists() || fs::remove_dir(&link_dir).is_ok())
65+
&& windows::symlink_dir(&original_dir, &link_dir).is_err()
6666
{
6767
message = DENIED;
6868
}

0 commit comments

Comments
 (0)