Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use openat when encountering ENAMETOOLONG #88731

Closed
wants to merge 7 commits into from
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
23 changes: 23 additions & 0 deletions library/std/src/fs/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1707,3 +1707,26 @@ fn test_file_times() {
assert_eq!(metadata.created().unwrap(), created);
}
}

#[test]
#[cfg(any(target_os = "linux", target_os = "android"))]
fn deep_traversal() -> crate::io::Result<()> {
use crate::fs::{create_dir_all, metadata, remove_dir_all, write};
use crate::iter::repeat;

let tmpdir = tmpdir();

let segment = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";

let mut dir = tmpdir.join(segment);
repeat(segment).take(100).for_each(|name| dir.push(name));
assert!(dir.as_os_str().len() > libc::PATH_MAX as usize);
let file = dir.join("b");

create_dir_all(&dir).expect("deep create tailed");
write(&file, "foo").expect("deep write failed");
metadata(&file).expect("deep stat failed");
remove_dir_all(&dir).expect("deep remove failed");

Ok(())
}
1 change: 1 addition & 0 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@
#![feature(int_roundings)]
#![feature(ip)]
#![feature(ip_in_core)]
#![feature(iter_advance_by)]
#![feature(maybe_uninit_slice)]
#![feature(maybe_uninit_uninit_array)]
#![feature(maybe_uninit_write_slice)]
Expand Down
7 changes: 3 additions & 4 deletions library/std/src/sys/common/small_c_string.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::ffi::{CStr, CString};
use crate::ffi::{CStr, CString, OsStr};
use crate::mem::MaybeUninit;
use crate::path::Path;
use crate::slice;
use crate::{io, ptr};

Expand All @@ -15,11 +14,11 @@ const NUL_ERR: io::Error =
io::const_io_error!(io::ErrorKind::InvalidInput, "file name contained an unexpected NUL byte");

#[inline]
pub fn run_path_with_cstr<T, F>(path: &Path, f: F) -> io::Result<T>
pub fn run_path_with_cstr<T, F>(path: &(impl AsRef<OsStr> + ?Sized), f: F) -> io::Result<T>
where
F: FnOnce(&CStr) -> io::Result<T>,
{
run_with_cstr(path.as_os_str().as_os_str_bytes(), f)
run_with_cstr(path.as_ref().as_os_str_bytes(), f)
}

#[inline]
Expand Down
Loading
Loading