Skip to content

Commit

Permalink
First try opening the package source lock read-only.
Browse files Browse the repository at this point in the history
  • Loading branch information
hugwijst committed Jan 28, 2019
1 parent 1f87b6d commit a23612d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/cargo/sources/registry/mod.rs
Expand Up @@ -179,6 +179,7 @@ use crate::util::to_url::ToUrl;
use crate::util::{internal, CargoResult, Config, FileLock, Filesystem};

const INDEX_LOCK: &str = ".cargo-index-lock";
const PACKAGE_SOURCE_LOCK: &str = ".cargo-ok";
pub const CRATES_IO_INDEX: &str = "https://github.com/rust-lang/crates.io-index";
pub const CRATES_IO_REGISTRY: &str = "crates-io";
const CRATE_TEMPLATE: &str = "{crate}";
Expand Down Expand Up @@ -434,7 +435,19 @@ impl<'cfg> RegistrySource<'cfg> {
.src_path
.join(&package_dir);
dst.create_dir()?;
dst.open_rw(".cargo-ok", self.config, &package_dir)?

// Attempt to open a read-only copy first to avoid an exclusive write
// lock and also work with read-only filesystems. If the file has
// any data, assume the source is already unpacked.
if let Ok(ok) = dst.open_ro(PACKAGE_SOURCE_LOCK, self.config, &package_dir) {
let meta = ok.file().metadata()?;
if meta.len() > 0 {
let unpack_dir = ok.parent().to_path_buf();
return Ok(unpack_dir);
}
}

dst.open_rw(PACKAGE_SOURCE_LOCK, self.config, &package_dir)?
};
let unpack_dir = ok.parent().to_path_buf();

Expand Down

0 comments on commit a23612d

Please sign in to comment.