Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sources/path: if PathSource::list_files fails while using a git repo, retry without it #10313

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions src/cargo/sources/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,13 @@ impl<'cfg> PathSource<'cfg> {
})
}

fn _list_files(&self, pkg: &Package) -> CargoResult<Vec<PathBuf>> {
let root = pkg.root();
let no_include_option = pkg.manifest().include().is_empty();
let git_repo = if no_include_option {
self.discover_git_repo(root)?
} else {
None
};

fn _list_files_with_repo(
&self,
root: &Path,
no_include_option: bool,
git_repo: Option<&git2::Repository>,
pkg: &Package,
) -> CargoResult<Vec<PathBuf>> {
let mut exclude_builder = GitignoreBuilder::new(root);
if no_include_option && git_repo.is_none() {
// no include option and not git repo discovered (see rust-lang/cargo#7183).
Expand Down Expand Up @@ -174,6 +172,28 @@ impl<'cfg> PathSource<'cfg> {
self.list_files_walk(pkg, &mut filter)
}

fn _list_files(&self, pkg: &Package) -> CargoResult<Vec<PathBuf>> {
let root = pkg.root();
let no_include_option = pkg.manifest().include().is_empty();
let git_repo = if no_include_option {
self.discover_git_repo(root)?
} else {
None
};

match self._list_files_with_repo(root, no_include_option, git_repo.as_ref(), pkg) {
// If we tried using the git repo and it failed, retry without the git repo because
// the git repo might be invalid in some way.
//
// NOTE: this may cause occasional retries that are related to failures that aren't
// due to invalid git repos.
Err(_e) if git_repo.is_some() => {
self._list_files_with_repo(root, no_include_option, None, pkg)
}
res => res,
}
}

/// Returns `Some(git2::Repository)` if found sibling `Cargo.toml` and `.git`
/// directory; otherwise, caller should fall back on full file list.
fn discover_git_repo(&self, root: &Path) -> CargoResult<Option<git2::Repository>> {
Expand Down