hyper-tls = "0.5"
ipnet = "2"
itertools = "0.10"
+libc = "0.2" # just for EISDIR due to IsADirectory
mime = "0.3"
parking_lot = "0.11"
regex = "1.5"
thiserror = "1"
void = "1"
+# for daemonic behaviours
+# daemonize 0.4.1 in sid
+# syslog 4.0 in sid, 5.0 in upstream, ideally want 5.0 (new API)
+
# Not in sid:
extend = "1" # no deps not in sid
eyre = "0.6" # deps not in sid: indenter (see below)
sections: HashMap<SectionName, ini::Section>,
}
-type OkAnyway<'f,A> = &'f dyn Fn(ErrorKind) -> Option<A>;
+type OkAnyway<'f,A> = &'f dyn Fn(&io::Error) -> Option<A>;
#[ext]
impl<'f,A> OkAnyway<'f,A> {
fn ok<T>(self, r: &Result<T, io::Error>) -> Option<A> {
let e = r.as_ref().err()?;
- let k = e.kind();
- let a = self(k)?;
+ let a = self(e)?;
Some(a)
}
}
#[throws(AE)] // AE includes everything
fn read_toplevel(&mut self, toplevel: &Path) {
enum Anyway { None, Dir }
- match self.read_file(toplevel, &|k| match k {
- EK::NotFound => Some(Anyway::None),
- EK::IsADirectory => Some(Anyway::Dir),
+ match self.read_file(toplevel, &|e| match e {
+ e if e.kind() == EK::NotFound => Some(Anyway::None),
+ e if e.is_is_a_directory() => Some(Anyway::Dir),
_ => None,
})
.dcontext(toplevel).context("top-level config directory (or file)")?
Some(Anyway::Dir) => {
struct AnywayNone;
- let anyway_none = |k| match k {
- EK::NotFound => Some(AnywayNone),
+ let anyway_none = |e: &io::Error| match e {
+ e if e.kind() == EK::NotFound => Some(AnywayNone),
_ => None,
};
fn read_extra(&mut self, extra: &Path) {
struct AnywayDir;
- match self.read_file(extra, &|k| match k {
- EK::IsADirectory => Some(AnywayDir),
+ match self.read_file(extra, &|e| match e {
+ e if e.is_is_a_directory() => Some(AnywayDir),
_ => None,
})
.dcontext(extra)?
}
}
+// Works around the lack of ErrorKind::IsADirectory
+// #![feature(io_error_more)]
+// https://github.com/rust-lang/rust/issues/86442
+#[ext(pub)]
+impl io::Error {
+ fn is_is_a_directory(&self) -> bool {
+ self.raw_os_error()
+ .unwrap_or_else(|| panic!(
+ "trying to tell whether Kind is IsADirectory for non-OS error io::Error {}",
+ self))
+ == libc::EISDIR
+ }
+}
+
#[throws(ReadLimitedError)]
pub async fn read_limited_bytes<S>(limit: usize, initial: Box<[u8]>,
capacity: usize,