Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions cap-primitives/src/rustix/linux/fs/open_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#[cfg(racy_asserts)]
use crate::fs::is_same_file;
use crate::fs::FollowSymlinks;
use crate::fs::{manually, OpenOptions};
use std::path::Path;
use std::{fs, io};
Expand Down Expand Up @@ -82,13 +83,11 @@ pub(crate) fn open_beneath(
// times, because there's no limit on how often this can happen. The actual
// number here is currently an arbitrarily chosen guess.
for _ in 0..4 {
match openat2(
start,
path_c_str,
oflags,
mode,
ResolveFlags::BENEATH | ResolveFlags::NO_MAGICLINKS,
) {
let mut resolve_flags = ResolveFlags::BENEATH | ResolveFlags::NO_MAGICLINKS;
if options.follow == FollowSymlinks::No {
resolve_flags |= ResolveFlags::NO_SYMLINKS;
}
match openat2(start, path_c_str, oflags, mode, resolve_flags) {
Ok(file) => {
let file = fs::File::from_into_fd(file);

Expand Down
24 changes: 16 additions & 8 deletions tests/symlinks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,19 +258,19 @@ fn open_dir_nofollow() {
let name = format!("{}{}", symlink_dir, suffix);
check!(tmpdir.open_dir(&name));
// On Windows, a trailing dot is stripped early.
if cfg!(not(windows)) || suffix != &"/." {
check!(tmpdir.open_dir_nofollow(&name));
} else {
if (cfg!(windows) && suffix == &"/.") || cfg!(target_os = "linux") {
assert!(tmpdir.open_dir_nofollow(&name).is_err());
} else {
check!(tmpdir.open_dir_nofollow(&name));
}
for dir_name in &["dir", "symlink_dir"] {
let name = format!("{}/../{}", dir_name, name);
check!(tmpdir.open_dir(&name));
// On Windows, a trailing dot is stripped early.
if cfg!(not(windows)) || suffix != &"/." {
check!(tmpdir.open_dir_nofollow(&name));
} else {
if (cfg!(windows) && suffix == &"/.") || cfg!(target_os = "linux") {
assert!(tmpdir.open_dir_nofollow(&name).is_err());
} else {
check!(tmpdir.open_dir_nofollow(&name));
}
}
}
Expand All @@ -296,7 +296,11 @@ fn open_dir_nofollow() {
#[cfg(not(windows))]
{
check!(tmpdir.open_dir(&name));
check!(tmpdir.open_dir_nofollow(&name));
if cfg!(target_os = "linux") {
assert!(tmpdir.open_dir_nofollow(&name).is_err());
} else {
check!(tmpdir.open_dir_nofollow(&name));
}
}
for dir_name in &["dir", "symlink_dir"] {
let name = format!("{}/../{}", dir_name, name);
Expand All @@ -308,7 +312,11 @@ fn open_dir_nofollow() {
#[cfg(not(windows))]
{
check!(tmpdir.open_dir(&name));
check!(tmpdir.open_dir_nofollow(&name));
if cfg!(target_os = "linux") {
assert!(tmpdir.open_dir_nofollow(&name).is_err());
} else {
check!(tmpdir.open_dir_nofollow(&name));
}
}
}
}
Expand Down
Loading