Skip to content

Commit db60a09

Browse files
committed
Auto merge of #2534 - alexcrichton:lock-with-git-repos, r=brson
Replace existing sources before updating Currently sources may acquire file locks to ensure that they're not tampered with while they're in use. We may load two sources to the same location, however, in the case of git repositories which need to be updated. Cargo will first load a locked version of the source and then may load an unlocked version, and these two loads currently deadlock. This commit tweaks the logic when updating a source to only update it after the previous source has been replaced. Closes #2533
2 parents 72690ba + 18e5930 commit db60a09

File tree

2 files changed

+51
-10
lines changed

2 files changed

+51
-10
lines changed

src/cargo/core/registry.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,21 +158,16 @@ impl<'cfg> PackageRegistry<'cfg> {
158158

159159
fn load(&mut self, source_id: &SourceId, kind: Kind) -> CargoResult<()> {
160160
(|| {
161-
let mut source = source_id.load(self.config);
162-
163-
// Ensure the source has fetched all necessary remote data.
164-
let p = profile::start(format!("updating: {}", source_id));
165-
try!(source.update());
166-
drop(p);
167-
161+
// Save off the source
162+
let source = source_id.load(self.config);
168163
if kind == Kind::Override {
169164
self.overrides.push(source_id.clone());
170165
}
171-
172-
// Save off the source
173166
self.add_source(source_id, source, kind);
174167

175-
Ok(())
168+
// Ensure the source has fetched all necessary remote data.
169+
let _p = profile::start(format!("updating: {}", source_id));
170+
self.sources.get_mut(source_id).unwrap().update()
176171
}).chain_error(|| human(format!("Unable to update {}", source_id)))
177172
}
178173

tests/test_cargo_compile_git_deps.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,3 +1749,49 @@ test!(denied_lints_are_allowed {
17491749
{compiling} foo v0.0.1 ([..])
17501750
", compiling = COMPILING, updating = UPDATING)));
17511751
});
1752+
1753+
test!(add_a_git_dep {
1754+
let git = git::new("git", |p| {
1755+
p.file("Cargo.toml", r#"
1756+
[project]
1757+
name = "git"
1758+
version = "0.5.0"
1759+
authors = []
1760+
"#)
1761+
.file("src/lib.rs", "")
1762+
}).unwrap();
1763+
1764+
let p = project("foo")
1765+
.file("Cargo.toml", &format!(r#"
1766+
[package]
1767+
name = "foo"
1768+
version = "0.0.1"
1769+
authors = []
1770+
1771+
[dependencies]
1772+
a = {{ path = 'a' }}
1773+
git = {{ git = '{}' }}
1774+
"#, git.url()))
1775+
.file("src/lib.rs", "")
1776+
.file("a/Cargo.toml", r#"
1777+
[package]
1778+
name = "a"
1779+
version = "0.0.1"
1780+
authors = []
1781+
"#)
1782+
.file("a/src/lib.rs", "");
1783+
1784+
assert_that(p.cargo_process("build"), execs().with_status(0));
1785+
1786+
File::create(p.root().join("a/Cargo.toml")).unwrap().write_all(format!(r#"
1787+
[package]
1788+
name = "a"
1789+
version = "0.0.1"
1790+
authors = []
1791+
1792+
[dependencies]
1793+
git = {{ git = '{}' }}
1794+
"#, git.url()).as_bytes()).unwrap();
1795+
1796+
assert_that(p.cargo("build"), execs().with_status(0));
1797+
});

0 commit comments

Comments
 (0)