Mercurial > public > mercurial-scm > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
47779:6df528ed47a9 | 47780:cf5f8da2244c |
---|---|
45 } | 45 } |
46 | 46 |
47 /// Details about where an I/O error happened | 47 /// Details about where an I/O error happened |
48 #[derive(Debug)] | 48 #[derive(Debug)] |
49 pub enum IoErrorContext { | 49 pub enum IoErrorContext { |
50 /// `std::fs::metadata` | |
51 ReadingMetadata(std::path::PathBuf), | |
50 ReadingFile(std::path::PathBuf), | 52 ReadingFile(std::path::PathBuf), |
51 WritingFile(std::path::PathBuf), | 53 WritingFile(std::path::PathBuf), |
52 RemovingFile(std::path::PathBuf), | 54 RemovingFile(std::path::PathBuf), |
53 RenamingFile { | 55 RenamingFile { |
54 from: std::path::PathBuf, | 56 from: std::path::PathBuf, |
106 | 108 |
107 // TODO: use `DisplayBytes` instead to show non-Unicode filenames losslessly? | 109 // TODO: use `DisplayBytes` instead to show non-Unicode filenames losslessly? |
108 impl fmt::Display for IoErrorContext { | 110 impl fmt::Display for IoErrorContext { |
109 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | 111 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
110 match self { | 112 match self { |
113 IoErrorContext::ReadingMetadata(path) => { | |
114 write!(f, "when reading metadata of {}", path.display()) | |
115 } | |
111 IoErrorContext::ReadingFile(path) => { | 116 IoErrorContext::ReadingFile(path) => { |
112 write!(f, "when reading {}", path.display()) | 117 write!(f, "when reading {}", path.display()) |
113 } | 118 } |
114 IoErrorContext::WritingFile(path) => { | 119 IoErrorContext::WritingFile(path) => { |
115 write!(f, "when writing {}", path.display()) | 120 write!(f, "when writing {}", path.display()) |