Skip to content

Commit 43fc23c

Browse files
committed
Auto merge of #6841 - ehuss:err-walk-access, r=dwijnand
Better error if PathSource::walk can't access something. Reported at #6757 (comment).
2 parents cd17472 + dcad83d commit 43fc23c

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

src/cargo/sources/path.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ use log::{trace, warn};
1111
use crate::core::source::MaybePackage;
1212
use crate::core::{Dependency, Package, PackageId, Source, SourceId, Summary};
1313
use crate::ops;
14-
use crate::util::paths;
15-
use crate::util::Config;
16-
use crate::util::{internal, CargoResult};
14+
use crate::util::{internal, paths, CargoResult, CargoResultExt, Config};
1715

1816
pub struct PathSource<'cfg> {
1917
source_id: SourceId,
@@ -455,7 +453,10 @@ impl<'cfg> PathSource<'cfg> {
455453
//
456454
// TODO: drop `collect` and sort after transition period and dropping warning tests.
457455
// See rust-lang/cargo#4268 and rust-lang/cargo#4270.
458-
let mut entries: Vec<PathBuf> = fs::read_dir(path)?.map(|e| e.unwrap().path()).collect();
456+
let mut entries: Vec<PathBuf> = fs::read_dir(path)
457+
.chain_err(|| format!("cannot read {:?}", path))?
458+
.map(|e| e.unwrap().path())
459+
.collect();
459460
entries.sort_unstable_by(|a, b| a.as_os_str().cmp(b.as_os_str()));
460461
for path in entries {
461462
let name = path.file_name().and_then(|s| s.to_str());

tests/testsuite/build_script.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3720,9 +3720,7 @@ fn using_rerun_if_changed_does_not_rebuild() {
37203720
.build();
37213721

37223722
p.cargo("build").run();
3723-
p.cargo("build")
3724-
.with_stderr("[FINISHED] [..]")
3725-
.run();
3723+
p.cargo("build").with_stderr("[FINISHED] [..]").run();
37263724
}
37273725

37283726
#[test]
@@ -3807,3 +3805,32 @@ fn links_interrupted_can_restart() {
38073805
.with_stderr_contains("[RUNNING] [..]/foo-[..]/build-script-build[..]")
38083806
.run();
38093807
}
3808+
3809+
#[test]
3810+
#[cfg(unix)]
3811+
fn build_script_scan_eacces() {
3812+
// build.rs causes a scan of the whole project, which can be a problem if
3813+
// a directory is not accessible.
3814+
use std::os::unix::fs::PermissionsExt;
3815+
let p = project()
3816+
.file("src/lib.rs", "")
3817+
.file("build.rs", "fn main() {}")
3818+
.file("secrets/stuff", "")
3819+
.build();
3820+
let path = p.root().join("secrets");
3821+
fs::set_permissions(&path, fs::Permissions::from_mode(0)).unwrap();
3822+
// "Caused by" is a string from libc such as the following:
3823+
// Permission denied (os error 13)
3824+
p.cargo("build")
3825+
.with_stderr(
3826+
"\
3827+
[ERROR] cannot read \"[..]/foo/secrets\"
3828+
3829+
Caused by:
3830+
[..]
3831+
",
3832+
)
3833+
.with_status(101)
3834+
.run();
3835+
fs::set_permissions(&path, fs::Permissions::from_mode(0o755)).unwrap();
3836+
}

0 commit comments

Comments
 (0)