Skip to content

Ignore malformed manifests on git dependencies #3998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 8, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/cargo/ops/cargo_read_manifest.rs
Original file line number Diff line number Diff line change
@@ -121,7 +121,22 @@ fn read_nested_packages(path: &Path,

let manifest_path = find_project_manifest_exact(path, "Cargo.toml")?;

let (manifest, nested) = read_manifest(&manifest_path, source_id, config)?;
let (manifest, nested) = match read_manifest(&manifest_path, source_id, config) {
Err(_) => {
// Ignore malformed manifests found on git repositories
//
// git source try to find and read all manifests from the repository
// but since it's not possible to exclude folders from this search
// it's safer to ignore malformed manifests to avoid
//
// TODO: Add a way to exclude folders?
info!("skipping malformed package found at `{}`",
path.to_string_lossy());
return Ok(());
}
Ok(tuple) => tuple
};

let manifest = match manifest {
EitherManifest::Real(manifest) => manifest,
EitherManifest::Virtual(..) => return Ok(()),
55 changes: 55 additions & 0 deletions tests/git.rs
Original file line number Diff line number Diff line change
@@ -290,6 +290,61 @@ fn cargo_compile_with_nested_paths() {
execs().with_stdout("hello world\n"));
}

#[test]
fn cargo_compile_with_malformed_nested_paths() {
let git_project = git::new("dep1", |project| {
project
.file("Cargo.toml", r#"
[project]
name = "dep1"
version = "0.5.0"
authors = ["[email protected]"]
[lib]
name = "dep1"
"#)
.file("src/dep1.rs", r#"
pub fn hello() -> &'static str {
"hello world"
}
"#)
.file("vendor/dep2/Cargo.toml", r#"
!INVALID!
"#)
}).unwrap();

let p = project("parent")
.file("Cargo.toml", &format!(r#"
[project]
name = "parent"
version = "0.5.0"
authors = ["[email protected]"]
[dependencies.dep1]
version = "0.5.0"
git = '{}'
[[bin]]
name = "parent"
"#, git_project.url()))
.file("src/parent.rs",
&main_file(r#""{}", dep1::hello()"#, &["dep1"]));

p.cargo_process("build")
.exec_with_output()
.unwrap();

assert_that(&p.bin("parent"), existing_file());

assert_that(process(&p.bin("parent")),
execs().with_stdout("hello world\n"));
}

#[test]
fn cargo_compile_with_meta_package() {
let git_project = git::new("meta-dep", |project| {