From 6cee10b0754958e7917e16c1152a9f71a9d279cc Mon Sep 17 00:00:00 2001 From: Stefan Hoelzl Date: Sun, 8 Dec 2019 16:06:57 +0100 Subject: [PATCH] variant with old behaviour but dotfiles can be included --- src/cargo/sources/path.rs | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/cargo/sources/path.rs b/src/cargo/sources/path.rs index d15f876c3..afc896c14 100644 --- a/src/cargo/sources/path.rs +++ b/src/cargo/sources/path.rs @@ -147,6 +147,8 @@ impl<'cfg> PathSource<'cfg> { if let Some(result) = self.discover_git_and_list_files(pkg, root, &mut filter) { return result; } + // no include option and not git repo discovered (see rust-lang/cargo#7183). + return self.list_files_walk_except_dot_files_and_dirs(pkg, &mut filter); } self.list_files_walk(pkg, &mut filter) } @@ -329,6 +331,29 @@ impl<'cfg> PathSource<'cfg> { } } + fn list_files_walk_except_dot_files_and_dirs( + &self, + pkg: &Package, + filter: &mut dyn FnMut(&Path) -> CargoResult, + ) -> CargoResult> { + let root = pkg.root(); + let mut exclude_dot_files_dir_builder = GitignoreBuilder::new(root); + exclude_dot_files_dir_builder.add_line(None, ".*")?; + exclude_dot_files_dir_builder.add_line(None, "*/.*/*")?; + let ignore_dot_files_and_dirs = exclude_dot_files_dir_builder.build()?; + + let mut filter_ignore_dot_files_and_dirs = |path: &Path| -> CargoResult { + let relative_path = path.strip_prefix(root)?; + match ignore_dot_files_and_dirs + .matched_path_or_any_parents(relative_path, /* is_dir */ false) + { + Match::Ignore(_) => Ok(false), + _ => filter(path), + } + }; + self.list_files_walk(pkg, &mut filter_ignore_dot_files_and_dirs) + } + fn list_files_walk( &self, pkg: &Package, @@ -355,15 +380,6 @@ impl<'cfg> PathSource<'cfg> { if !is_root && fs::metadata(&path.join("Cargo.toml")).is_ok() { return Ok(()); } - // Skip dotfile directories. - if path - .file_name() - .and_then(|s| s.to_str()) - .map(|s| s.starts_with('.')) - == Some(true) - { - return Ok(()); - } // For package integration tests, we need to sort the paths in a deterministic order to // be able to match stdout warnings in the same order. -- 2.39.5