From 4509464a424c17bd145b6c82b240d76f00e1fdb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20D=C3=BCrr?= <102963075+cd-work@users.noreply.github.com> Date: Thu, 27 Jun 2024 16:49:16 +0000 Subject: [PATCH] Fix Gradle 5 lockfiles not overriding manifests (#1462) This fixes an issue where Gradle 5 lockfiles would not override manifest files in the same directory since the lockfiles themselves are stored in a subdirectory. --- CHANGELOG.md | 4 ++++ lockfile/src/lib.rs | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 059749014..f5543d80e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## Unreleased +### Fixed + +- Gradle 5 lockfiles not overriding manifest files in the same project + ## 6.6.3 - 2024-06-26 ### Fixed diff --git a/lockfile/src/lib.rs b/lockfile/src/lib.rs index 1a5469dfb..f18491881 100644 --- a/lockfile/src/lib.rs +++ b/lockfile/src/lib.rs @@ -377,7 +377,16 @@ pub fn find_depfiles_at(root: impl AsRef) -> Vec<(PathBuf, LockfileFormat) // the manifest. let mut lockfile_dirs = depfiles.lockfiles.iter().filter_map(|(path, format)| Some((path.parent()?, format))); - remove |= lockfile_dirs.any(|(lockfile_dir, lockfile_format)| { + remove |= lockfile_dirs.any(|(mut lockfile_dir, lockfile_format)| { + // Gradle 5 lockfiles are in a subdirectory, so we truncate these directories to + // get the effective directory these lockfiles were created for. + let dir_str = lockfile_dir.to_string_lossy(); + if lockfile_format == &LockfileFormat::Gradle + && dir_str.ends_with("/gradle/dependency-locks") + { + lockfile_dir = lockfile_dir.parent().unwrap().parent().unwrap(); + } + lockfile_format.parser().is_path_manifest(manifest_path) && manifest_path.starts_with(lockfile_dir) });