The motivation is that errors other than "file not found" could lead to
the file being overwritten by an empty config, e.g. if the `open` call
is interrupted and returns `EINTR`, then this code would read an empty
config and write it back later on. This can probably happen for other
errors as well (`ENFILE`, ...).
use std::ffi::OsString;
use std::fs::{self, File};
use std::io::prelude::*;
+use std::io;
use std::path::{Path, PathBuf};
use toml;
let metadata = path.join(".crates.toml");
let mut f = match File::open(&metadata) {
Ok(f) => f,
- Err(..) => return Ok(CrateListingV1 { v1: BTreeMap::new() }),
+ Err(e) => {
+ if e.kind() == io::ErrorKind::NotFound {
+ return Ok(CrateListingV1 { v1: BTreeMap::new() });
+ }
+ return Err(e).chain_error(|| {
+ human(format!("failed to open crate metadata at `{}`",
+ metadata.display()))
+ });
+ }
};
(|| -> CargoResult<_> {
let mut contents = String::new();