Skip to content

Commit 5999a5f

Browse files
Make tests pass on old macos
On old macos systems, `fs::hard_link()` will follow symlinks. This changes the test `symlink_hard_link` to exit early on these systems, so that tests can pass.
1 parent fd0cb0c commit 5999a5f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

library/std/src/fs/tests.rs

+18
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ use crate::os::unix::fs::symlink as symlink_junction;
1919
use crate::os::windows::fs::{symlink_dir, symlink_file};
2020
#[cfg(windows)]
2121
use crate::sys::fs::symlink_junction;
22+
#[cfg(target_os = "macos")]
23+
use crate::sys::weak::weak;
24+
#[cfg(target_os = "macos")]
25+
use libc::{c_char, c_int};
2226

2327
macro_rules! check {
2428
($e:expr) => {
@@ -79,6 +83,17 @@ pub fn got_symlink_permission(tmpdir: &TempDir) -> bool {
7983
}
8084
}
8185

86+
#[cfg(target_os = "macos")]
87+
fn able_to_not_follow_symlinks_while_hard_linking() -> bool {
88+
weak!(fn linkat(c_int, *const c_char, c_int, *const c_char, c_int) -> c_int);
89+
linkat.get().is_some()
90+
}
91+
92+
#[cfg(not(target_os = "macos"))]
93+
fn able_to_not_follow_symlinks_while_hard_linking() -> bool {
94+
return true;
95+
}
96+
8297
#[test]
8398
fn file_test_io_smoke_test() {
8499
let message = "it's alright. have a good time";
@@ -1347,6 +1362,9 @@ fn symlink_hard_link() {
13471362
if !got_symlink_permission(&tmpdir) {
13481363
return;
13491364
};
1365+
if !able_to_not_follow_symlinks_while_hard_linking() {
1366+
return;
1367+
}
13501368

13511369
// Create "file", a file.
13521370
check!(fs::File::create(tmpdir.join("file")));

0 commit comments

Comments
 (0)