Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f56c023

Browse files
committedJun 11, 2024
Rename std::fs::try_exists to std::fs::exists and stabilize fs_try_exists
1 parent 05a92c2 commit f56c023

File tree

10 files changed

+18
-19
lines changed

10 files changed

+18
-19
lines changed
 

‎std/src/fs.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -2739,18 +2739,15 @@ impl AsInnerMut<fs_imp::DirBuilder> for DirBuilder {
27392739
/// # Examples
27402740
///
27412741
/// ```no_run
2742-
/// #![feature(fs_try_exists)]
27432742
/// use std::fs;
27442743
///
2745-
/// assert!(!fs::try_exists("does_not_exist.txt").expect("Can't check existence of file does_not_exist.txt"));
2746-
/// assert!(fs::try_exists("/root/secret_file.txt").is_err());
2744+
/// assert!(!fs::exists("does_not_exist.txt").expect("Can't check existence of file does_not_exist.txt"));
2745+
/// assert!(fs::exists("/root/secret_file.txt").is_err());
27472746
/// ```
27482747
///
27492748
/// [`Path::exists`]: crate::path::Path::exists
2750-
// FIXME: stabilization should modify documentation of `exists()` to recommend this method
2751-
// instead.
2752-
#[unstable(feature = "fs_try_exists", issue = "83186")]
2749+
#[stable(feature = "fs_try_exists", since = "CURRENT_RUSTC_VERSION")]
27532750
#[inline]
2754-
pub fn try_exists<P: AsRef<Path>>(path: P) -> io::Result<bool> {
2755-
fs_imp::try_exists(path.as_ref())
2751+
pub fn exists<P: AsRef<Path>>(path: P) -> io::Result<bool> {
2752+
fs_imp::exists(path.as_ref())
27562753
}

‎std/src/path.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2888,6 +2888,8 @@ impl Path {
28882888
/// prevent time-of-check to time-of-use (TOCTOU) bugs. You should only use it in scenarios
28892889
/// where those bugs are not an issue.
28902890
///
2891+
/// This is an alias for [`std::fs::exists`](crate::fs::exists).
2892+
///
28912893
/// # Examples
28922894
///
28932895
/// ```no_run
@@ -2900,7 +2902,7 @@ impl Path {
29002902
#[stable(feature = "path_try_exists", since = "1.63.0")]
29012903
#[inline]
29022904
pub fn try_exists(&self) -> io::Result<bool> {
2903-
fs::try_exists(self)
2905+
fs::exists(self)
29042906
}
29052907

29062908
/// Returns `true` if the path exists on disk and is pointing at a regular file.

‎std/src/sys/pal/hermit/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::sys::time::SystemTime;
1818
use crate::sys::unsupported;
1919
use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
2020

21-
pub use crate::sys_common::fs::{copy, try_exists};
21+
pub use crate::sys_common::fs::{copy, exists};
2222

2323
#[derive(Debug)]
2424
pub struct File(FileDesc);

‎std/src/sys/pal/solid/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
sys::unsupported,
1313
};
1414

15-
pub use crate::sys_common::fs::try_exists;
15+
pub use crate::sys_common::fs::exists;
1616

1717
/// A file descriptor.
1818
#[derive(Clone, Copy)]

‎std/src/sys/pal/unix/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ use libc::{
101101
))]
102102
use libc::{dirent64, fstat64, ftruncate64, lseek64, lstat64, off64_t, open64, stat64};
103103

104-
pub use crate::sys_common::fs::try_exists;
104+
pub use crate::sys_common::fs::exists;
105105

106106
pub struct File(FileDesc);
107107

‎std/src/sys/pal/unix/thread.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ mod cgroups {
477477
//! output and we don't unescape
478478
use crate::borrow::Cow;
479479
use crate::ffi::OsString;
480-
use crate::fs::{try_exists, File};
480+
use crate::fs::{exists, File};
481481
use crate::io::Read;
482482
use crate::io::{BufRead, BufReader};
483483
use crate::os::unix::ffi::OsStringExt;
@@ -555,7 +555,7 @@ mod cgroups {
555555
path.push("cgroup.controllers");
556556

557557
// skip if we're not looking at cgroup2
558-
if matches!(try_exists(&path), Err(_) | Ok(false)) {
558+
if matches!(exists(&path), Err(_) | Ok(false)) {
559559
return usize::MAX;
560560
};
561561

@@ -612,7 +612,7 @@ mod cgroups {
612612
path.push(&group_path);
613613

614614
// skip if we guessed the mount incorrectly
615-
if matches!(try_exists(&path), Err(_) | Ok(false)) {
615+
if matches!(exists(&path), Err(_) | Ok(false)) {
616616
continue;
617617
}
618618

‎std/src/sys/pal/unsupported/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ pub fn remove_dir_all(_path: &Path) -> io::Result<()> {
291291
unsupported()
292292
}
293293

294-
pub fn try_exists(_path: &Path) -> io::Result<bool> {
294+
pub fn exists(_path: &Path) -> io::Result<bool> {
295295
unsupported()
296296
}
297297

‎std/src/sys/pal/wasi/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::sys::time::SystemTime;
1717
use crate::sys::unsupported;
1818
use crate::sys_common::{AsInner, FromInner, IntoInner};
1919

20-
pub use crate::sys_common::fs::try_exists;
20+
pub use crate::sys_common::fs::exists;
2121

2222
pub struct File {
2323
fd: WasiFd,

‎std/src/sys/pal/windows/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1531,7 +1531,7 @@ pub fn junction_point(original: &Path, link: &Path) -> io::Result<()> {
15311531
}
15321532

15331533
// Try to see if a file exists but, unlike `exists`, report I/O errors.
1534-
pub fn try_exists(path: &Path) -> io::Result<bool> {
1534+
pub fn exists(path: &Path) -> io::Result<bool> {
15351535
// Open the file to ensure any symlinks are followed to their target.
15361536
let mut opts = OpenOptions::new();
15371537
// No read, write, etc access rights are needed.

‎std/src/sys_common/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn remove_dir_all_recursive(path: &Path) -> io::Result<()> {
4242
fs::remove_dir(path)
4343
}
4444

45-
pub fn try_exists(path: &Path) -> io::Result<bool> {
45+
pub fn exists(path: &Path) -> io::Result<bool> {
4646
match fs::metadata(path) {
4747
Ok(_) => Ok(true),
4848
Err(error) if error.kind() == io::ErrorKind::NotFound => Ok(false),

0 commit comments

Comments
 (0)
Failed to load comments.