diff options
| author | Alexis Bourget <alexis.bourget@gmail.com> | 2020-06-27 22:59:47 +0200 |
|---|---|---|
| committer | Alexis Bourget <alexis.bourget@gmail.com> | 2020-06-27 22:59:47 +0200 |
| commit | 8e8c54aa3a8d92d8443ec4596754d14b2d196899 (patch) | |
| tree | c2f4b0eb952888b1d197bb99b82bcdfd31034fcc /src/libstd | |
| parent | d25d6c5bd8c211a5e606b2ac37bbecb9be1ac12b (diff) | |
| download | rust-8e8c54aa3a8d92d8443ec4596754d14b2d196899.tar.gz rust-8e8c54aa3a8d92d8443ec4596754d14b2d196899.zip | |
Added the parapgrah to path::Path::is_file too
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/path.rs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/libstd/path.rs b/src/libstd/path.rs index fa54b2063b4..f14a9ff72f6 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -2506,12 +2506,17 @@ impl Path { /// check errors, call [`fs::metadata`] and handle its Result. Then call /// [`fs::Metadata::is_file`] if it was Ok. /// - /// Note that the explanation about using `open` instead of `is_file` - /// that is present in the [`fs::Metadata`] documentation also applies here. + /// When the goal is simply to read from (or write to) the source, the most + /// reliable way to test the source can be read (or written to) is to open + /// it. Only using `is_file` can break workflows like `diff <( prog_a )` on + /// a Unix-like system for example. See [`File::open`] or + /// [`OpenOptions::open`] for more information. /// /// [`fs::metadata`]: ../../std/fs/fn.metadata.html /// [`fs::Metadata`]: ../../std/fs/struct.Metadata.html /// [`fs::Metadata::is_file`]: ../../std/fs/struct.Metadata.html#method.is_file + /// [`File::open`]: ../../std/fs/struct.File.html#method.open + /// [`OpenOptions::open`]: ../../std/fs/struct.OpenOptions.html#method.open #[stable(feature = "path_ext", since = "1.5.0")] pub fn is_file(&self) -> bool { fs::metadata(self).map(|m| m.is_file()).unwrap_or(false) |
