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.
This commit is contained in:
Weihang Lo 2021-12-21 02:59:41 +08:00
parent 0113ec4645
commit d92dceaeba
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7
3 changed files with 8 additions and 74 deletions

View File

@ -1687,7 +1687,11 @@ fn ignore_broken_symlinks() {
.symlink_dir("a/b", "a/b/c/d/foo")
.build();
p.cargo("build").run();
p.cargo("build")
.with_stderr_contains(
"[WARNING] File system loop found: [..]/a/b/c/d/foo points to an ancestor [..]/a/b",
)
.run();
assert!(p.bin("foo").is_file());
p.process(&p.bin("foo")).with_stdout("i am foo\n").run();

View File

@ -4618,75 +4618,6 @@ fn links_interrupted_can_restart() {
.run();
}
#[cargo_test]
#[cfg(unix)]
fn build_script_scan_eacces() {
// build.rs causes a scan of the whole project, which can be a problem if
// a directory is not accessible.
use cargo_test_support::git;
use std::os::unix::fs::PermissionsExt;
let p = project()
.file("src/lib.rs", "")
.file("build.rs", "fn main() {}")
.file("secrets/stuff", "")
.build();
let path = p.root().join("secrets");
fs::set_permissions(&path, fs::Permissions::from_mode(0o0)).unwrap();
// The last "Caused by" is a string from libc such as the following:
// Permission denied (os error 13)
p.cargo("build")
.with_stderr(
"\
[ERROR] failed to determine package fingerprint for build script for foo v0.0.1 ([..]/foo)
An I/O error happened[..]
By default[..]
it to[..]
file[..]
See[..]
Caused by:
failed to determine the most recently modified file in [..]/foo
Caused by:
failed to determine list of files in [..]/foo
Caused by:
IO error for operation on [..]/foo/secrets: [..]
Caused by:
[..]
",
)
.with_status(101)
.run();
// Try `package.exclude` to skip a directory.
p.change_file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
exclude = ["secrets"]
"#,
);
p.cargo("build").run();
// Try with git. This succeeds because the git status walker ignores
// directories it can't access.
p.change_file("Cargo.toml", &basic_manifest("foo", "0.0.1"));
p.build_dir().rm_rf();
let repo = git::init(&p.root());
git::add(&repo);
git::commit(&repo);
p.cargo("build").run();
// Restore permissions so that the directory can be deleted.
fs::set_permissions(&path, fs::Permissions::from_mode(0o755)).unwrap();
}
#[cargo_test]
fn dev_dep_with_links() {
let p = project()

View File

@ -794,10 +794,10 @@ fn broken_symlink() {
.with_status(101)
.with_stderr_contains(
"\
error: failed to determine list of files [..]/foo
[ERROR] failed to prepare local package for uploading
Caused by:
IO error for operation on [..]/foo/src/foo.rs: [..]
failed to open for archiving: `[..]foo.rs`
Caused by:
[..]
@ -841,9 +841,8 @@ fn filesystem_loop() {
.symlink_dir("a/b", "a/b/c/d/foo")
.build()
.cargo("package -v")
.with_status(101)
.with_stderr_contains(
" File system loop found: [..]/a/b/c/d/foo points to an ancestor [..]/a/b",
"[WARNING] File system loop found: [..]/a/b/c/d/foo points to an ancestor [..]/a/b",
)
.run();
}