|
1 | 1 | //! Helpers to gather the VCS information for `cargo package`.
|
2 | 2 |
|
3 | 3 | use std::collections::HashSet;
|
4 |
| -use std::path::Path; |
5 | 4 | use std::path::PathBuf;
|
6 | 5 |
|
7 | 6 | use anyhow::Context as _;
|
@@ -187,8 +186,7 @@ fn git(
|
187 | 186 | .iter()
|
188 | 187 | .filter(|src_file| dirty_files.iter().any(|path| src_file.starts_with(path)))
|
189 | 188 | .map(|p| p.as_ref())
|
190 |
| - .chain(dirty_metadata_paths(pkg, repo)?.iter()) |
191 |
| - .chain(dirty_symlinks(pkg, repo, src_files)?.iter()) |
| 189 | + .chain(dirty_files_outside_pkg_root(pkg, repo, src_files)?.iter()) |
192 | 190 | .map(|path| {
|
193 | 191 | pathdiff::diff_paths(path, cwd)
|
194 | 192 | .as_ref()
|
@@ -221,54 +219,39 @@ fn git(
|
221 | 219 | }
|
222 | 220 | }
|
223 | 221 |
|
224 |
| -/// Checks whether files at paths specified in `package.readme` and |
225 |
| -/// `package.license-file` have been modified. |
| 222 | +/// Checks whether "included" source files outside package root have been modified. |
226 | 223 | ///
|
227 |
| -/// This is required because those paths may link to a file outside the |
228 |
| -/// current package root, but still under the git workdir, affecting the |
229 |
| -/// final packaged `.crate` file. |
230 |
| -fn dirty_metadata_paths(pkg: &Package, repo: &git2::Repository) -> CargoResult<Vec<PathBuf>> { |
231 |
| - let mut dirty_files = Vec::new(); |
232 |
| - let workdir = repo.workdir().unwrap(); |
233 |
| - let root = pkg.root(); |
234 |
| - let meta = pkg.manifest().metadata(); |
235 |
| - for path in [&meta.license_file, &meta.readme] { |
236 |
| - let Some(path) = path.as_deref().map(Path::new) else { |
237 |
| - continue; |
238 |
| - }; |
239 |
| - let abs_path = paths::normalize_path(&root.join(path)); |
240 |
| - if paths::strip_prefix_canonical(&abs_path, root).is_ok() { |
241 |
| - // Inside package root. Don't bother checking git status. |
242 |
| - continue; |
243 |
| - } |
244 |
| - if let Ok(rel_path) = paths::strip_prefix_canonical(&abs_path, workdir) { |
245 |
| - // Outside package root but under git workdir, |
246 |
| - if repo.status_file(&rel_path)? != git2::Status::CURRENT { |
247 |
| - dirty_files.push(workdir.join(rel_path)) |
248 |
| - } |
249 |
| - } |
250 |
| - } |
251 |
| - Ok(dirty_files) |
252 |
| -} |
253 |
| - |
254 |
| -/// Checks whether source files are symlinks and have been modified. |
| 224 | +/// This currently looks at |
| 225 | +/// |
| 226 | +/// * `package.readme` and `package.license-file` pointing to paths outside package root |
| 227 | +/// * symlinks targets reside outside package root |
255 | 228 | ///
|
256 | 229 | /// This is required because those paths may link to a file outside the
|
257 | 230 | /// current package root, but still under the git workdir, affecting the
|
258 | 231 | /// final packaged `.crate` file.
|
259 |
| -fn dirty_symlinks( |
| 232 | +fn dirty_files_outside_pkg_root( |
260 | 233 | pkg: &Package,
|
261 | 234 | repo: &git2::Repository,
|
262 | 235 | src_files: &[PathEntry],
|
263 | 236 | ) -> CargoResult<HashSet<PathBuf>> {
|
| 237 | + let pkg_root = pkg.root(); |
264 | 238 | let workdir = repo.workdir().unwrap();
|
| 239 | + |
| 240 | + let meta = pkg.manifest().metadata(); |
| 241 | + let metadata_paths: Vec<_> = [&meta.license_file, &meta.readme] |
| 242 | + .into_iter() |
| 243 | + .filter_map(|p| p.as_deref()) |
| 244 | + .map(|path| paths::normalize_path(&pkg_root.join(path))) |
| 245 | + .collect(); |
| 246 | + |
265 | 247 | let mut dirty_symlinks = HashSet::new();
|
266 | 248 | for rel_path in src_files
|
267 | 249 | .iter()
|
268 | 250 | .filter(|p| p.is_symlink_or_under_symlink())
|
269 |
| - .map(|p| p.as_ref().as_path()) |
| 251 | + .map(|p| p.as_ref()) |
| 252 | + .chain(metadata_paths.iter()) |
270 | 253 | // If inside package root. Don't bother checking git status.
|
271 |
| - .filter(|p| paths::strip_prefix_canonical(p, pkg.root()).is_err()) |
| 254 | + .filter(|p| paths::strip_prefix_canonical(p, pkg_root).is_err()) |
272 | 255 | // Handle files outside package root but under git workdir,
|
273 | 256 | .filter_map(|p| paths::strip_prefix_canonical(p, workdir).ok())
|
274 | 257 | {
|
|
0 commit comments