mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Auto merge of #11008 - weihanglo:issue-10917, r=epage
Ignore broken but excluded file during traversing
This commit is contained in:
commit
1ac83ba696
@ -150,7 +150,7 @@ impl<'cfg> PathSource<'cfg> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut filter = |path: &Path, is_dir: bool| {
|
let filter = |path: &Path, is_dir: bool| {
|
||||||
let relative_path = match path.strip_prefix(root) {
|
let relative_path = match path.strip_prefix(root) {
|
||||||
Ok(p) => p,
|
Ok(p) => p,
|
||||||
Err(_) => return false,
|
Err(_) => return false,
|
||||||
@ -169,10 +169,10 @@ impl<'cfg> PathSource<'cfg> {
|
|||||||
// Attempt Git-prepopulate only if no `include` (see rust-lang/cargo#4135).
|
// Attempt Git-prepopulate only if no `include` (see rust-lang/cargo#4135).
|
||||||
if no_include_option {
|
if no_include_option {
|
||||||
if let Some(repo) = git_repo {
|
if let Some(repo) = git_repo {
|
||||||
return self.list_files_git(pkg, &repo, &mut filter);
|
return self.list_files_git(pkg, &repo, &filter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.list_files_walk(pkg, &mut filter)
|
self.list_files_walk(pkg, &filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `Some(git2::Repository)` if found sibling `Cargo.toml` and `.git`
|
/// Returns `Some(git2::Repository)` if found sibling `Cargo.toml` and `.git`
|
||||||
@ -222,7 +222,7 @@ impl<'cfg> PathSource<'cfg> {
|
|||||||
&self,
|
&self,
|
||||||
pkg: &Package,
|
pkg: &Package,
|
||||||
repo: &git2::Repository,
|
repo: &git2::Repository,
|
||||||
filter: &mut dyn FnMut(&Path, bool) -> bool,
|
filter: &dyn Fn(&Path, bool) -> bool,
|
||||||
) -> CargoResult<Vec<PathBuf>> {
|
) -> CargoResult<Vec<PathBuf>> {
|
||||||
warn!("list_files_git {}", pkg.package_id());
|
warn!("list_files_git {}", pkg.package_id());
|
||||||
let index = repo.index()?;
|
let index = repo.index()?;
|
||||||
@ -376,7 +376,7 @@ impl<'cfg> PathSource<'cfg> {
|
|||||||
fn list_files_walk(
|
fn list_files_walk(
|
||||||
&self,
|
&self,
|
||||||
pkg: &Package,
|
pkg: &Package,
|
||||||
filter: &mut dyn FnMut(&Path, bool) -> bool,
|
filter: &dyn Fn(&Path, bool) -> bool,
|
||||||
) -> CargoResult<Vec<PathBuf>> {
|
) -> CargoResult<Vec<PathBuf>> {
|
||||||
let mut ret = Vec::new();
|
let mut ret = Vec::new();
|
||||||
self.walk(pkg.root(), &mut ret, true, filter)?;
|
self.walk(pkg.root(), &mut ret, true, filter)?;
|
||||||
@ -388,7 +388,7 @@ impl<'cfg> PathSource<'cfg> {
|
|||||||
path: &Path,
|
path: &Path,
|
||||||
ret: &mut Vec<PathBuf>,
|
ret: &mut Vec<PathBuf>,
|
||||||
is_root: bool,
|
is_root: bool,
|
||||||
filter: &mut dyn FnMut(&Path, bool) -> bool,
|
filter: &dyn Fn(&Path, bool) -> bool,
|
||||||
) -> CargoResult<()> {
|
) -> CargoResult<()> {
|
||||||
let walkdir = WalkDir::new(path)
|
let walkdir = WalkDir::new(path)
|
||||||
.follow_links(true)
|
.follow_links(true)
|
||||||
@ -432,7 +432,11 @@ impl<'cfg> PathSource<'cfg> {
|
|||||||
self.config.shell().warn(err)?;
|
self.config.shell().warn(err)?;
|
||||||
}
|
}
|
||||||
Err(err) => match err.path() {
|
Err(err) => match err.path() {
|
||||||
// If the error occurs with a path, simply recover from it.
|
// If an error occurs with a path, filter it again.
|
||||||
|
// If it is excluded, Just ignore it in this case.
|
||||||
|
// See issue rust-lang/cargo#10917
|
||||||
|
Some(path) if !filter(path, path.is_dir()) => {}
|
||||||
|
// Otherwise, simply recover from it.
|
||||||
// Don't worry about error skipping here, the callers would
|
// Don't worry about error skipping here, the callers would
|
||||||
// still hit the IO error if they do access it thereafter.
|
// still hit the IO error if they do access it thereafter.
|
||||||
Some(path) => ret.push(path.to_path_buf()),
|
Some(path) => ret.push(path.to_path_buf()),
|
||||||
|
@ -845,6 +845,55 @@ Caused by:
|
|||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cargo_test]
|
||||||
|
/// Tests if a broken but excluded symlink is ignored.
|
||||||
|
/// See issue rust-lang/cargo#10917
|
||||||
|
///
|
||||||
|
/// This test requires you to be able to make symlinks.
|
||||||
|
/// For windows, this may require you to enable developer mode.
|
||||||
|
fn broken_but_excluded_symlink() {
|
||||||
|
#[cfg(unix)]
|
||||||
|
use std::os::unix::fs::symlink;
|
||||||
|
#[cfg(windows)]
|
||||||
|
use std::os::windows::fs::symlink_dir as symlink;
|
||||||
|
|
||||||
|
if !symlink_supported() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let p = project()
|
||||||
|
.file(
|
||||||
|
"Cargo.toml",
|
||||||
|
r#"
|
||||||
|
[project]
|
||||||
|
name = "foo"
|
||||||
|
version = "0.0.1"
|
||||||
|
authors = []
|
||||||
|
license = "MIT"
|
||||||
|
description = 'foo'
|
||||||
|
documentation = 'foo'
|
||||||
|
homepage = 'foo'
|
||||||
|
repository = 'foo'
|
||||||
|
exclude = ["src/foo.rs"]
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.file("src/main.rs", r#"fn main() { println!("hello"); }"#)
|
||||||
|
.build();
|
||||||
|
t!(symlink("nowhere", &p.root().join("src/foo.rs")));
|
||||||
|
|
||||||
|
p.cargo("package -v --list")
|
||||||
|
// `src/foo.rs` is excluded.
|
||||||
|
.with_stdout(
|
||||||
|
"\
|
||||||
|
Cargo.lock
|
||||||
|
Cargo.toml
|
||||||
|
Cargo.toml.orig
|
||||||
|
src/main.rs
|
||||||
|
",
|
||||||
|
)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
#[cargo_test]
|
#[cargo_test]
|
||||||
#[cfg(not(windows))] // https://github.com/libgit2/libgit2/issues/6250
|
#[cfg(not(windows))] // https://github.com/libgit2/libgit2/issues/6250
|
||||||
/// Test that /dir and /dir/ matches symlinks to directories.
|
/// Test that /dir and /dir/ matches symlinks to directories.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user