]> git.proxmox.com Git - cargo.git/commitdiff
Only treat missing crate lists as empty
authorTobias Bucher <tobiasbucher5991@gmail.com>
Fri, 18 Dec 2015 12:27:08 +0000 (12:27 +0000)
committerTobias Bucher <tobiasbucher5991@gmail.com>
Mon, 11 Jan 2016 00:54:21 +0000 (01:54 +0100)
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`, ...).

src/cargo/ops/cargo_install.rs

index dc02233809e63b2e7176c6f968a2a9236019864d..dfe9ea3614134c2b911ab18b71e0fa1bb71e7639 100644 (file)
@@ -4,6 +4,7 @@ use std::env;
 use std::ffi::OsString;
 use std::fs::{self, File};
 use std::io::prelude::*;
+use std::io;
 use std::path::{Path, PathBuf};
 
 use toml;
@@ -222,7 +223,15 @@ fn read_crate_list(path: &Path) -> CargoResult<CrateListingV1> {
     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();