Rollup merge of #126140 - eduardosm:stabilize-fs_try_exists, r=Amanieu · model-checking/verify-rust-std@6d6ba92 (original) (raw)
10 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2742,18 +2742,15 @@ impl AsInnerMut<fs_imp::DirBuilder> for DirBuilder { | ||
2742 | 2742 | /// # Examples |
2743 | 2743 | /// |
2744 | 2744 | /// ```no_run |
2745 | -/// #![feature(fs_try_exists)] | |
2746 | 2745 | /// use std::fs; |
2747 | 2746 | /// |
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()); | |
2750 | 2749 | /// ``` |
2751 | 2750 | /// |
2752 | 2751 | /// [`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")] | |
2756 | 2753 | #[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()) | |
2759 | 2756 | } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2907,6 +2907,8 @@ impl Path { | ||
2907 | 2907 | /// prevent time-of-check to time-of-use (TOCTOU) bugs. You should only use it in scenarios |
2908 | 2908 | /// where those bugs are not an issue. |
2909 | 2909 | /// |
2910 | + /// This is an alias for [`std::fs::exists`](crate::fs::exists). | |
2911 | + /// | |
2910 | 2912 | /// # Examples |
2911 | 2913 | /// |
2912 | 2914 | /// ```no_run |
@@ -2919,7 +2921,7 @@ impl Path { | ||
2919 | 2921 | #[stable(feature = "path_try_exists", since = "1.63.0")] |
2920 | 2922 | #[inline] |
2921 | 2923 | pub fn try_exists(&self) -> io::Result<bool> { |
2922 | - fs::try_exists(self) | |
2924 | + fs::exists(self) | |
2923 | 2925 | } |
2924 | 2926 | |
2925 | 2927 | /// Returns `true` if the path exists on disk and is pointing at a regular file. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -18,7 +18,7 @@ use crate::sys::time::SystemTime; | ||
18 | 18 | use crate::sys::unsupported; |
19 | 19 | use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner}; |
20 | 20 | |
21 | -pub use crate::sys_common::fs::{copy, try_exists}; | |
21 | +pub use crate::sys_common::fs::{copy, exists}; | |
22 | 22 | |
23 | 23 | #[derive(Debug)] |
24 | 24 | pub struct File(FileDesc); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -12,7 +12,7 @@ use crate::{ | ||
12 | 12 | sys::unsupported, |
13 | 13 | }; |
14 | 14 | |
15 | -pub use crate::sys_common::fs::try_exists; | |
15 | +pub use crate::sys_common::fs::exists; | |
16 | 16 | |
17 | 17 | /// A file descriptor. |
18 | 18 | #[derive(Clone, Copy)] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -97,7 +97,7 @@ use libc::{ | ||
97 | 97 | ))] |
98 | 98 | use libc::{dirent64, fstat64, ftruncate64, lseek64, lstat64, off64_t, open64, stat64}; |
99 | 99 | |
100 | -pub use crate::sys_common::fs::try_exists; | |
100 | +pub use crate::sys_common::fs::exists; | |
101 | 101 | |
102 | 102 | pub struct File(FileDesc); |
103 | 103 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -478,7 +478,7 @@ mod cgroups { | ||
478 | 478 | |
479 | 479 | use crate::borrow::Cow; |
480 | 480 | use crate::ffi::OsString; |
481 | -use crate::fs::{try_exists, File}; | |
481 | +use crate::fs::{exists, File}; | |
482 | 482 | use crate::io::Read; |
483 | 483 | use crate::io::{BufRead, BufReader}; |
484 | 484 | use crate::os::unix::ffi::OsStringExt; |
@@ -556,7 +556,7 @@ mod cgroups { | ||
556 | 556 | path.push("cgroup.controllers"); |
557 | 557 | |
558 | 558 | // 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)) { | |
560 | 560 | return usize::MAX; |
561 | 561 | }; |
562 | 562 | |
@@ -613,7 +613,7 @@ mod cgroups { | ||
613 | 613 | path.push(&group_path); |
614 | 614 | |
615 | 615 | // skip if we guessed the mount incorrectly |
616 | -if matches!(try_exists(&path), Err(_) | Ok(false)) { | |
616 | +if matches!(exists(&path), Err(_) | Ok(false)) { | |
617 | 617 | continue; |
618 | 618 | } |
619 | 619 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -291,7 +291,7 @@ pub fn remove_dir_all(_path: &Path) -> io::Result<()> { | ||
291 | 291 | unsupported() |
292 | 292 | } |
293 | 293 | |
294 | -pub fn try_exists(_path: &Path) -> io::Result<bool> { | |
294 | +pub fn exists(_path: &Path) -> io::Result<bool> { | |
295 | 295 | unsupported() |
296 | 296 | } |
297 | 297 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -17,7 +17,7 @@ use crate::sys::time::SystemTime; | ||
17 | 17 | use crate::sys::unsupported; |
18 | 18 | use crate::sys_common::{AsInner, FromInner, IntoInner}; |
19 | 19 | |
20 | -pub use crate::sys_common::fs::try_exists; | |
20 | +pub use crate::sys_common::fs::exists; | |
21 | 21 | |
22 | 22 | pub struct File { |
23 | 23 | fd: WasiFd, |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1531,7 +1531,7 @@ pub fn junction_point(original: &Path, link: &Path) -> io::Result<()> { | ||
1531 | 1531 | } |
1532 | 1532 | |
1533 | 1533 | // 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> { | |
1535 | 1535 | // Open the file to ensure any symlinks are followed to their target. |
1536 | 1536 | let mut opts = OpenOptions::new(); |
1537 | 1537 | // No read, write, etc access rights are needed. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -42,7 +42,7 @@ fn remove_dir_all_recursive(path: &Path) -> io::Result<()> { | ||
42 | 42 | fs::remove_dir(path) |
43 | 43 | } |
44 | 44 | |
45 | -pub fn try_exists(path: &Path) -> io::Result<bool> { | |
45 | +pub fn exists(path: &Path) -> io::Result<bool> { | |
46 | 46 | match fs::metadata(path) { |
47 | 47 | Ok(_) => Ok(true), |
48 | 48 | Err(error) if error.kind() == io::ErrorKind::NotFound => Ok(false), |