From a01c91c8bc251f46b94c5124f31df6bc094fb0a1 Mon Sep 17 00:00:00 2001 From: Havvy Date: Tue, 27 Jun 2017 03:59:07 -0700 Subject: Document error coercion to false in path-ext methods + see also sections --- src/libstd/path.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/libstd') diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 42a54ed6d75..f0feb82cd01 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -2215,12 +2215,22 @@ impl Path { /// This function will traverse symbolic links to query information about the /// destination file. In case of broken symbolic links this will return `false`. /// + /// If you cannot access the directory containing the file, e.g. because of a + /// permission error, this will return `false`. + /// /// # Examples /// /// ```no_run /// use std::path::Path; /// assert_eq!(Path::new("does_not_exist.txt").exists(), false); /// ``` + /// + /// # See Also + /// + /// This is a convenience function that coerces errors to false. If you want to + /// check errors, call [fs::metadata]. + /// + /// [fs::metadata]: ../../std/fs/fn.metadata.html #[stable(feature = "path_ext", since = "1.5.0")] pub fn exists(&self) -> bool { fs::metadata(self).is_ok() @@ -2231,6 +2241,9 @@ impl Path { /// This function will traverse symbolic links to query information about the /// destination file. In case of broken symbolic links this will return `false`. /// + /// If you cannot access the directory containing the file, e.g. because of a + /// permission error, this will return `false`. + /// /// # Examples /// /// ```no_run @@ -2238,6 +2251,15 @@ impl Path { /// assert_eq!(Path::new("./is_a_directory/").is_file(), false); /// assert_eq!(Path::new("a_file.txt").is_file(), true); /// ``` + /// + /// # See Also + /// + /// This is a convenience function that coerces errors to false. If you want to + /// check errors, call [fs::metadata] and handle its Result. Then call + /// [fs::Metadata::is_file] if it was Ok. + /// + /// [fs::metadata]: ../../std/fs/fn.metadata.html + /// [fs::Metadata::is_file]: ../../std/fs/struct.Metadata.html#method.is_file #[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) @@ -2248,6 +2270,9 @@ impl Path { /// This function will traverse symbolic links to query information about the /// destination file. In case of broken symbolic links this will return `false`. /// + /// If you cannot access the directory containing the file, e.g. because of a + /// permission error, this will return `false`. + /// /// # Examples /// /// ```no_run @@ -2255,6 +2280,15 @@ impl Path { /// assert_eq!(Path::new("./is_a_directory/").is_dir(), true); /// assert_eq!(Path::new("a_file.txt").is_dir(), false); /// ``` + /// + /// # See Also + /// + /// This is a convenience function that coerces errors to false. If you want to + /// check errors, call [fs::metadata] and handle its Result. Then call + /// [fs::Metadata::is_dir] if it was Ok. + /// + /// [fs::metadata]: ../../std/fs/fn.metadata.html + /// [fs::Metadata::is_dir]: ../../std/fs/struct.Metadata.html#method.is_dir #[stable(feature = "path_ext", since = "1.5.0")] pub fn is_dir(&self) -> bool { fs::metadata(self).map(|m| m.is_dir()).unwrap_or(false) -- cgit 1.4.1-3-g733a5 From bd9428a46b7290b8f87d830655b473099207ae0d Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 12 Jul 2017 20:39:02 -0600 Subject: Update mod.rs --- src/libstd/sys/redox/mod.rs | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/sys/redox/mod.rs b/src/libstd/sys/redox/mod.rs index 31c40ea58b1..bd5b40de9a0 100644 --- a/src/libstd/sys/redox/mod.rs +++ b/src/libstd/sys/redox/mod.rs @@ -40,23 +40,7 @@ pub mod time; #[cfg(not(test))] pub fn init() { - use alloc::oom; - - oom::set_oom_handler(oom_handler); - - // A nicer handler for out-of-memory situations than the default one. This - // one prints a message to stderr before aborting. It is critical that this - // code does not allocate any memory since we are in an OOM situation. Any - // errors are ignored while printing since there's nothing we can do about - // them and we are about to exit anyways. - fn oom_handler() -> ! { - use intrinsics; - let msg = "fatal runtime error: out of memory\n"; - unsafe { - let _ = syscall::write(2, msg.as_bytes()); - intrinsics::abort(); - } - } + } pub fn decode_error_kind(errno: i32) -> ErrorKind { -- cgit 1.4.1-3-g733a5 From 362dd8a98690adaf3a3f6b5b9f6edc697fbd3ed9 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 12 Jul 2017 20:40:43 -0600 Subject: Update fs.rs --- src/libstd/sys/redox/fs.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/sys/redox/fs.rs b/src/libstd/sys/redox/fs.rs index 87e50c40148..27ded432b95 100644 --- a/src/libstd/sys/redox/fs.rs +++ b/src/libstd/sys/redox/fs.rs @@ -384,8 +384,9 @@ pub fn unlink(p: &Path) -> io::Result<()> { } pub fn rename(_old: &Path, _new: &Path) -> io::Result<()> { - ::sys_common::util::dumb_print(format_args!("Rename\n")); - unimplemented!(); + copy(old, new)?; + unlink(old)?; + Ok(()) } pub fn set_perm(p: &Path, perm: FilePermissions) -> io::Result<()> { -- cgit 1.4.1-3-g733a5 From 21f2ace8cfaa6c6cd137cfa3b11222f4a06a0b87 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 12 Jul 2017 20:48:04 -0600 Subject: Update mod.rs --- src/libstd/sys/redox/mod.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/sys/redox/mod.rs b/src/libstd/sys/redox/mod.rs index bd5b40de9a0..7c728ebb1af 100644 --- a/src/libstd/sys/redox/mod.rs +++ b/src/libstd/sys/redox/mod.rs @@ -39,9 +39,7 @@ pub mod thread_local; pub mod time; #[cfg(not(test))] -pub fn init() { - -} +pub fn init() {} pub fn decode_error_kind(errno: i32) -> ErrorKind { match errno { -- cgit 1.4.1-3-g733a5 From 4259ae64755f3b72296b95a9eeabaf883321069b Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 12 Jul 2017 22:16:35 -0600 Subject: Update fs.rs --- src/libstd/sys/redox/fs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libstd') diff --git a/src/libstd/sys/redox/fs.rs b/src/libstd/sys/redox/fs.rs index 27ded432b95..918893097f8 100644 --- a/src/libstd/sys/redox/fs.rs +++ b/src/libstd/sys/redox/fs.rs @@ -383,7 +383,7 @@ pub fn unlink(p: &Path) -> io::Result<()> { Ok(()) } -pub fn rename(_old: &Path, _new: &Path) -> io::Result<()> { +pub fn rename(old: &Path, new: &Path) -> io::Result<()> { copy(old, new)?; unlink(old)?; Ok(()) -- cgit 1.4.1-3-g733a5