Skip to content

Commit f3ced9d

Browse files
authored
Rollup merge of #126140 - eduardosm:stabilize-fs_try_exists, r=Amanieu
Rename `std::fs::try_exists` to `std::fs::exists` and stabilize fs_try_exists FCP completed in tracking issue. Tracking issue: #83186 Closes #83186 Stabilized API: ```rust mod fs { pub fn exists<P: AsRef<Path>>(path: P) -> io::Result<bool>; } ```
2 parents ac47dba + 6a04dfe commit f3ced9d

File tree

10 files changed

+18
-19
lines changed

10 files changed

+18
-19
lines changed

library/std/src/fs.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2742,18 +2742,15 @@ impl AsInnerMut<fs_imp::DirBuilder> for DirBuilder {
27422742
/// # Examples
27432743
///
27442744
/// ```no_run
2745-
/// #![feature(fs_try_exists)]
27462745
/// use std::fs;
27472746
///
2748-
/// assert!(!fs::try_exists("does_not_exist.txt").expect("Can't check existence of file does_not_exist.txt"));
2749-
/// assert!(fs::try_exists("/root/secret_file.txt").is_err());
2747+
/// assert!(!fs::exists("does_not_exist.txt").expect("Can't check existence of file does_not_exist.txt"));
2748+
/// assert!(fs::exists("/root/secret_file.txt").is_err());
27502749
/// ```
27512750
///
27522751
/// [`Path::exists`]: crate::path::Path::exists
2753-
// FIXME: stabilization should modify documentation of `exists()` to recommend this method
2754-
// instead.
2755-
#[unstable(feature = "fs_try_exists", issue = "83186")]
2752+
#[stable(feature = "fs_try_exists", since = "CURRENT_RUSTC_VERSION")]
27562753
#[inline]
2757-
pub fn try_exists<P: AsRef<Path>>(path: P) -> io::Result<bool> {
2758-
fs_imp::try_exists(path.as_ref())
2754+
pub fn exists<P: AsRef<Path>>(path: P) -> io::Result<bool> {
2755+
fs_imp::exists(path.as_ref())
27592756
}

library/std/src/path.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2907,6 +2907,8 @@ impl Path {
29072907
/// prevent time-of-check to time-of-use (TOCTOU) bugs. You should only use it in scenarios
29082908
/// where those bugs are not an issue.
29092909
///
2910+
/// This is an alias for [`std::fs::exists`](crate::fs::exists).
2911+
///
29102912
/// # Examples
29112913
///
29122914
/// ```no_run
@@ -2919,7 +2921,7 @@ impl Path {
29192921
#[stable(feature = "path_try_exists", since = "1.63.0")]
29202922
#[inline]
29212923
pub fn try_exists(&self) -> io::Result<bool> {
2922-
fs::try_exists(self)
2924+
fs::exists(self)
29232925
}
29242926

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

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

Lines changed: 1 addition & 1 deletion
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);

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

Lines changed: 1 addition & 1 deletion
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)]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ use libc::{
9797
))]
9898
use libc::{dirent64, fstat64, ftruncate64, lseek64, lstat64, off64_t, open64, stat64};
9999

100-
pub use crate::sys_common::fs::try_exists;
100+
pub use crate::sys_common::fs::exists;
101101

102102
pub struct File(FileDesc);
103103

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ mod cgroups {
478478
479479
use crate::borrow::Cow;
480480
use crate::ffi::OsString;
481-
use crate::fs::{try_exists, File};
481+
use crate::fs::{exists, File};
482482
use crate::io::Read;
483483
use crate::io::{BufRead, BufReader};
484484
use crate::os::unix::ffi::OsStringExt;
@@ -556,7 +556,7 @@ mod cgroups {
556556
path.push("cgroup.controllers");
557557

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

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

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

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

Lines changed: 1 addition & 1 deletion
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

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

Lines changed: 1 addition & 1 deletion
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,

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

Lines changed: 1 addition & 1 deletion
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.

library/std/src/sys_common/fs.rs

Lines changed: 1 addition & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy