Skip to content

Commit d92dcea

Browse files
committed
Test IO error resilience while walking directories
Remove `build_script::build_script_scan_eacces` test case because cargo ignores it and returns its path during a `cargo build`. The caller still has a chance to hit the IO error if they does access it.
1 parent 0113ec4 commit d92dcea

File tree

3 files changed

+8
-74
lines changed

3 files changed

+8
-74
lines changed

tests/testsuite/build.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,11 @@ fn ignore_broken_symlinks() {
16871687
.symlink_dir("a/b", "a/b/c/d/foo")
16881688
.build();
16891689

1690-
p.cargo("build").run();
1690+
p.cargo("build")
1691+
.with_stderr_contains(
1692+
"[WARNING] File system loop found: [..]/a/b/c/d/foo points to an ancestor [..]/a/b",
1693+
)
1694+
.run();
16911695
assert!(p.bin("foo").is_file());
16921696

16931697
p.process(&p.bin("foo")).with_stdout("i am foo\n").run();

tests/testsuite/build_script.rs

-69
Original file line numberDiff line numberDiff line change
@@ -4618,75 +4618,6 @@ fn links_interrupted_can_restart() {
46184618
.run();
46194619
}
46204620

4621-
#[cargo_test]
4622-
#[cfg(unix)]
4623-
fn build_script_scan_eacces() {
4624-
// build.rs causes a scan of the whole project, which can be a problem if
4625-
// a directory is not accessible.
4626-
use cargo_test_support::git;
4627-
use std::os::unix::fs::PermissionsExt;
4628-
4629-
let p = project()
4630-
.file("src/lib.rs", "")
4631-
.file("build.rs", "fn main() {}")
4632-
.file("secrets/stuff", "")
4633-
.build();
4634-
let path = p.root().join("secrets");
4635-
fs::set_permissions(&path, fs::Permissions::from_mode(0o0)).unwrap();
4636-
// The last "Caused by" is a string from libc such as the following:
4637-
// Permission denied (os error 13)
4638-
p.cargo("build")
4639-
.with_stderr(
4640-
"\
4641-
[ERROR] failed to determine package fingerprint for build script for foo v0.0.1 ([..]/foo)
4642-
An I/O error happened[..]
4643-
4644-
By default[..]
4645-
it to[..]
4646-
file[..]
4647-
See[..]
4648-
4649-
Caused by:
4650-
failed to determine the most recently modified file in [..]/foo
4651-
4652-
Caused by:
4653-
failed to determine list of files in [..]/foo
4654-
4655-
Caused by:
4656-
IO error for operation on [..]/foo/secrets: [..]
4657-
4658-
Caused by:
4659-
[..]
4660-
",
4661-
)
4662-
.with_status(101)
4663-
.run();
4664-
4665-
// Try `package.exclude` to skip a directory.
4666-
p.change_file(
4667-
"Cargo.toml",
4668-
r#"
4669-
[package]
4670-
name = "foo"
4671-
version = "0.0.1"
4672-
exclude = ["secrets"]
4673-
"#,
4674-
);
4675-
p.cargo("build").run();
4676-
4677-
// Try with git. This succeeds because the git status walker ignores
4678-
// directories it can't access.
4679-
p.change_file("Cargo.toml", &basic_manifest("foo", "0.0.1"));
4680-
p.build_dir().rm_rf();
4681-
let repo = git::init(&p.root());
4682-
git::add(&repo);
4683-
git::commit(&repo);
4684-
p.cargo("build").run();
4685-
4686-
// Restore permissions so that the directory can be deleted.
4687-
fs::set_permissions(&path, fs::Permissions::from_mode(0o755)).unwrap();
4688-
}
4689-
46904621
#[cargo_test]
46914622
fn dev_dep_with_links() {
46924623
let p = project()

tests/testsuite/package.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -794,10 +794,10 @@ fn broken_symlink() {
794794
.with_status(101)
795795
.with_stderr_contains(
796796
"\
797-
error: failed to determine list of files [..]/foo
797+
[ERROR] failed to prepare local package for uploading
798798
799799
Caused by:
800-
IO error for operation on [..]/foo/src/foo.rs: [..]
800+
failed to open for archiving: `[..]foo.rs`
801801
802802
Caused by:
803803
[..]
@@ -841,9 +841,8 @@ fn filesystem_loop() {
841841
.symlink_dir("a/b", "a/b/c/d/foo")
842842
.build()
843843
.cargo("package -v")
844-
.with_status(101)
845844
.with_stderr_contains(
846-
" File system loop found: [..]/a/b/c/d/foo points to an ancestor [..]/a/b",
845+
"[WARNING] File system loop found: [..]/a/b/c/d/foo points to an ancestor [..]/a/b",
847846
)
848847
.run();
849848
}

0 commit comments

Comments
 (0)