Skip to content
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

Check workspace member existence as dir. #8511

Merged
merged 1 commit into from
Jul 23, 2020
Merged
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
11 changes: 10 additions & 1 deletion src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,16 @@ impl WorkspaceRootConfig {
if expanded_paths.is_empty() {
expanded_list.push(pathbuf);
} else {
expanded_list.extend(expanded_paths);
// Some OS can create system support files anywhere.
// (e.g. macOS creates `.DS_Store` file if you visit a directory using Finder.)
// Such files can be reported as a member path unexpectedly.
// Check and filter out non-directory paths to prevent pushing such accidental unwanted path
// as a member.
for expanded_path in expanded_paths {
if expanded_path.is_dir() {
expanded_list.push(expanded_path);
}
}
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ mod locate_project;
mod lockfile_compat;
mod login;
mod lto;
mod member_discovery;
mod member_errors;
mod message_format;
mod metabuild;
Expand Down
44 changes: 44 additions & 0 deletions tests/testsuite/member_discovery.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//! Tests for workspace member discovery.

use cargo::core::{Shell, Workspace};
use cargo::util::config::Config;

use cargo_test_support::install::cargo_home;
use cargo_test_support::project;
use cargo_test_support::registry;

/// Tests exclusion of non-directory files from workspace member discovery using glob `*`.
#[cargo_test]
fn bad_file_member_exclusion() {
let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = [ "crates/*" ]
"#,
)
.file("crates/.DS_Store", "PLACEHOLDER")
.file(
"crates/bar/Cargo.toml",
r#"
[project]
name = "bar"
version = "0.1.0"
authors = []
"#,
)
.file("crates/bar/src/main.rs", "fn main() {}")
.build();

// Prevent this test from accessing the network by setting up .cargo/config.
registry::init();
let config = Config::new(
Shell::from_write(Box::new(Vec::new())),
cargo_home(),
cargo_home(),
);
let ws = Workspace::new(&p.root().join("Cargo.toml"), &config).unwrap();
assert_eq!(ws.members().count(), 1);
assert_eq!(ws.members().next().unwrap().name(), "bar");
}