Skip to content

Commit c5e13da

Browse files
committed
Check workspace member existence as dir.
1 parent f84f3f8 commit c5e13da

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

src/cargo/core/workspace.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,16 @@ impl WorkspaceRootConfig {
11941194
if expanded_paths.is_empty() {
11951195
expanded_list.push(pathbuf);
11961196
} else {
1197-
expanded_list.extend(expanded_paths);
1197+
// Some OS can create system support files anywhere.
1198+
// (e.g. macOS creates `.DS_Store` file if you visit a directory using Finder.)
1199+
// Such files can be reported as a member path unexpectedly.
1200+
// Check and filter out non-directory paths to prevent pushing such accidental unwanted path
1201+
// as a member.
1202+
for expanded_path in expanded_paths {
1203+
if expanded_path.is_dir() {
1204+
expanded_list.push(expanded_path);
1205+
}
1206+
}
11981207
}
11991208
}
12001209

tests/testsuite/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ mod locate_project;
6262
mod lockfile_compat;
6363
mod login;
6464
mod lto;
65+
mod member_discovery;
6566
mod member_errors;
6667
mod message_format;
6768
mod metabuild;

tests/testsuite/member_discovery.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//! Tests for workspace member discovery.
2+
3+
use cargo::core::{Shell, Workspace};
4+
use cargo::util::config::Config;
5+
6+
use cargo_test_support::install::cargo_home;
7+
use cargo_test_support::project;
8+
use cargo_test_support::registry;
9+
10+
/// Tests exclusion of non-directory files from workspace member discovery using glob `*`.
11+
#[cargo_test]
12+
fn bad_file_member_exclusion() {
13+
let p = project()
14+
.file(
15+
"Cargo.toml",
16+
r#"
17+
[workspace]
18+
members = [ "crates/*" ]
19+
"#,
20+
)
21+
.file("crates/.DS_Store", "PLACEHOLDER")
22+
.file(
23+
"crates/bar/Cargo.toml",
24+
r#"
25+
[project]
26+
name = "bar"
27+
version = "0.1.0"
28+
authors = []
29+
"#,
30+
)
31+
.file("crates/bar/src/main.rs", "fn main() {}")
32+
.build();
33+
34+
// Prevent this test from accessing the network by setting up .cargo/config.
35+
registry::init();
36+
let config = Config::new(
37+
Shell::from_write(Box::new(Vec::new())),
38+
cargo_home(),
39+
cargo_home(),
40+
);
41+
let ws = Workspace::new(&p.root().join("Cargo.toml"), &config).unwrap();
42+
assert_eq!(ws.members().count(), 1);
43+
assert_eq!(ws.members().next().unwrap().name(), "bar");
44+
}

0 commit comments

Comments
 (0)