Skip to content

Commit a23612d

Browse files
committedJan 28, 2019
First try opening the package source lock read-only.
1 parent 1f87b6d commit a23612d

File tree

1 file changed

+14
-1
lines changed
  • src/cargo/sources/registry

1 file changed

+14
-1
lines changed
 

‎src/cargo/sources/registry/mod.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ use crate::util::to_url::ToUrl;
179179
use crate::util::{internal, CargoResult, Config, FileLock, Filesystem};
180180

181181
const INDEX_LOCK: &str = ".cargo-index-lock";
182+
const PACKAGE_SOURCE_LOCK: &str = ".cargo-ok";
182183
pub const CRATES_IO_INDEX: &str = "https://github.com/rust-lang/crates.io-index";
183184
pub const CRATES_IO_REGISTRY: &str = "crates-io";
184185
const CRATE_TEMPLATE: &str = "{crate}";
@@ -434,7 +435,19 @@ impl<'cfg> RegistrySource<'cfg> {
434435
.src_path
435436
.join(&package_dir);
436437
dst.create_dir()?;
437-
dst.open_rw(".cargo-ok", self.config, &package_dir)?
438+
439+
// Attempt to open a read-only copy first to avoid an exclusive write
440+
// lock and also work with read-only filesystems. If the file has
441+
// any data, assume the source is already unpacked.
442+
if let Ok(ok) = dst.open_ro(PACKAGE_SOURCE_LOCK, self.config, &package_dir) {
443+
let meta = ok.file().metadata()?;
444+
if meta.len() > 0 {
445+
let unpack_dir = ok.parent().to_path_buf();
446+
return Ok(unpack_dir);
447+
}
448+
}
449+
450+
dst.open_rw(PACKAGE_SOURCE_LOCK, self.config, &package_dir)?
438451
};
439452
let unpack_dir = ok.parent().to_path_buf();
440453

0 commit comments

Comments
 (0)