diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2021-03-27 20:37:11 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-27 20:37:11 +0100 |
| commit | aee7b9e7d64f446847e5c18649c88e3267130a6d (patch) | |
| tree | 07845efcc219ea9531cc70268e36c31f1adf3474 | |
| parent | f665e5a491341b79654509aadbc9c43cf0183ac2 (diff) | |
| parent | 6c6ef7317bf87321c5eaefb1322380c8f297ff1b (diff) | |
| download | rust-aee7b9e7d64f446847e5c18649c88e3267130a6d.tar.gz rust-aee7b9e7d64f446847e5c18649c88e3267130a6d.zip | |
Rollup merge of #83522 - pickfire:patch-6, r=JohnTitor
Improve fs error open_from unix Consistency for #79399 Suggested by JohnTitor r? `@JohnTitor` Not user if the error is too long now, do we handle long errors well?
| -rw-r--r-- | library/std/src/sys/unix/fs.rs | 8 | ||||
| -rw-r--r-- | library/std/src/sys_common/fs.rs | 10 |
2 files changed, 9 insertions, 9 deletions
diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs index f25a6280cd0..759565bab73 100644 --- a/library/std/src/sys/unix/fs.rs +++ b/library/std/src/sys/unix/fs.rs @@ -2,7 +2,7 @@ use crate::os::unix::prelude::*; use crate::ffi::{CStr, CString, OsStr, OsString}; use crate::fmt; -use crate::io::{self, Error, ErrorKind, IoSlice, IoSliceMut, SeekFrom}; +use crate::io::{self, Error, IoSlice, IoSliceMut, SeekFrom}; use crate::mem; use crate::path::{Path, PathBuf}; use crate::ptr; @@ -1152,14 +1152,12 @@ pub fn canonicalize(p: &Path) -> io::Result<PathBuf> { fn open_from(from: &Path) -> io::Result<(crate::fs::File, crate::fs::Metadata)> { use crate::fs::File; + use crate::sys_common::fs::NOT_FILE_ERROR; let reader = File::open(from)?; let metadata = reader.metadata()?; if !metadata.is_file() { - return Err(Error::new_const( - ErrorKind::InvalidInput, - &"the source path is not an existing regular file", - )); + return Err(NOT_FILE_ERROR); } Ok((reader, metadata)) } diff --git a/library/std/src/sys_common/fs.rs b/library/std/src/sys_common/fs.rs index 92d0cc60850..30908824dd6 100644 --- a/library/std/src/sys_common/fs.rs +++ b/library/std/src/sys_common/fs.rs @@ -4,15 +4,17 @@ use crate::fs; use crate::io::{self, Error, ErrorKind}; use crate::path::Path; +pub(crate) const NOT_FILE_ERROR: Error = Error::new_const( + ErrorKind::InvalidInput, + &"the source path is neither a regular file nor a symlink to a regular file", +); + pub fn copy(from: &Path, to: &Path) -> io::Result<u64> { let mut reader = fs::File::open(from)?; let metadata = reader.metadata()?; if !metadata.is_file() { - return Err(Error::new_const( - ErrorKind::InvalidInput, - &"the source path is not an existing regular file", - )); + return Err(NOT_FILE_ERROR); } let mut writer = fs::File::create(to)?; |
