Skip to content
Closed
Show file tree
Hide file tree
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
22 changes: 19 additions & 3 deletions src/cargo/sources/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,27 @@ impl<'cfg> PathSource<'cfg> {
.map(|p| parse(p))
.collect::<Result<Vec<_>, _>>()?;

fn matches_path_or_parents(pattern: &Pattern, target: &Path) -> bool {
if pattern.matches_path(target) {
return true;
}
let mut current = target;
while let Some(parent) = current.parent() {
if pattern.matches_path(parent) {
return true;
}
current = parent;
}
false
}

let mut filter = |p: &Path| {
let relative_path = util::without_prefix(p, root).unwrap();
include.iter().any(|p| p.matches_path(relative_path)) || {
include.is_empty() &&
!exclude.iter().any(|p| p.matches_path(relative_path))
// mutually exclusive: setting include will override exclude
if include.is_empty() {
!exclude.iter().any(|exc| matches_path_or_parents(exc, relative_path))
} else {
include.iter().any(|inc| matches_path_or_parents(inc, relative_path))
}
};

Expand Down
24 changes: 22 additions & 2 deletions tests/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,23 @@ fn exclude() {
name = "foo"
version = "0.0.1"
authors = []
exclude = ["*.txt"]
exclude = [
"*.txt",
"data1",
"data2/", # Does NOT match
"data3/*",
"data4/**",
]
"#)
.file("src/main.rs", r#"
fn main() { println!("hello"); }
"#)
.file("bar.txt", "")
.file("src/bar.txt", "");
.file("src/bar.txt", "")
.file("data1/hello1.bin", "")
.file("data2/hello2.bin", "")
.file("data3/hello3.bin", "")
.file("data4/hello4.bin", "");

assert_that(p.cargo_process("package").arg("--no-verify").arg("-v"),
execs().with_status(0).with_stderr("\
Expand All @@ -266,6 +276,16 @@ See http://doc.crates.io/manifest.html#package-metadata for more info.
[PACKAGING] foo v0.0.1 ([..])
[ARCHIVING] [..]
[ARCHIVING] [..]
[ARCHIVING] [..]
"));

assert_that(&p.root().join("target/package/foo-0.0.1.crate"), existing_file());

assert_that(p.cargo("package").arg("-l"),
execs().with_status(0).with_stdout("\
Cargo.toml
data2[/]hello2.bin
src[/]main.rs
"));
}

Expand Down