diff rust/hg-core/src/errors.rs @ 47780:cf5f8da2244c stable

rhg: Propagate permission errors when finding a repository The Rust standard library has a `Path::is_dir` method that returns false for any I/O error (such as a permission error), not just "No such file or directory". Instead add an `is_dir` function that returns false for non-directories and for "No such file or directory" errors, but propagates other I/O errors. Differential Revision: https://phab.mercurial-scm.org/D11230
author Simon Sapin <simon.sapin@octobus.net>
date Thu, 29 Jul 2021 12:22:25 +0200
parents 6e49769b7f97
children abeae090ce67
line wrap: on
line diff
--- a/rust/hg-core/src/errors.rs	Thu Jul 29 11:53:03 2021 +0200
+++ b/rust/hg-core/src/errors.rs	Thu Jul 29 12:22:25 2021 +0200
@@ -47,6 +47,8 @@
 /// Details about where an I/O error happened
 #[derive(Debug)]
 pub enum IoErrorContext {
+    /// `std::fs::metadata`
+    ReadingMetadata(std::path::PathBuf),
     ReadingFile(std::path::PathBuf),
     WritingFile(std::path::PathBuf),
     RemovingFile(std::path::PathBuf),
@@ -108,6 +110,9 @@
 impl fmt::Display for IoErrorContext {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match self {
+            IoErrorContext::ReadingMetadata(path) => {
+                write!(f, "when reading metadata of {}", path.display())
+            }
             IoErrorContext::ReadingFile(path) => {
                 write!(f, "when reading {}", path.display())
             }