Rename std::fs::try_exists
to std::fs::exists
and stabilize fs_t… · model-checking/verify-rust-std@f56c023 (original) (raw)
10 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2739,18 +2739,15 @@ impl AsInnerMut<fs_imp::DirBuilder> for DirBuilder { | ||
2739 | 2739 | /// # Examples |
2740 | 2740 | /// |
2741 | 2741 | /// ```no_run |
2742 | -/// #![feature(fs_try_exists)] | |
2743 | 2742 | /// use std::fs; |
2744 | 2743 | /// |
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()); | |
2747 | 2746 | /// ``` |
2748 | 2747 | /// |
2749 | 2748 | /// [`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")] | |
2753 | 2750 | #[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()) | |
2756 | 2753 | } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2888,6 +2888,8 @@ impl Path { | ||
2888 | 2888 | /// prevent time-of-check to time-of-use (TOCTOU) bugs. You should only use it in scenarios |
2889 | 2889 | /// where those bugs are not an issue. |
2890 | 2890 | /// |
2891 | + /// This is an alias for [`std::fs::exists`](crate::fs::exists). | |
2892 | + /// | |
2891 | 2893 | /// # Examples |
2892 | 2894 | /// |
2893 | 2895 | /// ```no_run |
@@ -2900,7 +2902,7 @@ impl Path { | ||
2900 | 2902 | #[stable(feature = "path_try_exists", since = "1.63.0")] |
2901 | 2903 | #[inline] |
2902 | 2904 | pub fn try_exists(&self) -> io::Result<bool> { |
2903 | - fs::try_exists(self) | |
2905 | + fs::exists(self) | |
2904 | 2906 | } |
2905 | 2907 | |
2906 | 2908 | /// 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 |
---|---|---|
@@ -101,7 +101,7 @@ use libc::{ | ||
101 | 101 | ))] |
102 | 102 | use libc::{dirent64, fstat64, ftruncate64, lseek64, lstat64, off64_t, open64, stat64}; |
103 | 103 | |
104 | -pub use crate::sys_common::fs::try_exists; | |
104 | +pub use crate::sys_common::fs::exists; | |
105 | 105 | |
106 | 106 | pub struct File(FileDesc); |
107 | 107 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -477,7 +477,7 @@ mod cgroups { | ||
477 | 477 | //! output and we don't unescape |
478 | 478 | use crate::borrow::Cow; |
479 | 479 | use crate::ffi::OsString; |
480 | -use crate::fs::{try_exists, File}; | |
480 | +use crate::fs::{exists, File}; | |
481 | 481 | use crate::io::Read; |
482 | 482 | use crate::io::{BufRead, BufReader}; |
483 | 483 | use crate::os::unix::ffi::OsStringExt; |
@@ -555,7 +555,7 @@ mod cgroups { | ||
555 | 555 | path.push("cgroup.controllers"); |
556 | 556 | |
557 | 557 | // 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)) { | |
559 | 559 | return usize::MAX; |
560 | 560 | }; |
561 | 561 | |
@@ -612,7 +612,7 @@ mod cgroups { | ||
612 | 612 | path.push(&group_path); |
613 | 613 | |
614 | 614 | // skip if we guessed the mount incorrectly |
615 | -if matches!(try_exists(&path), Err(_) | Ok(false)) { | |
615 | +if matches!(exists(&path), Err(_) | Ok(false)) { | |
616 | 616 | continue; |
617 | 617 | } |
618 | 618 |
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), |