Skip to content

Commit

Permalink
ThirdPartyAudit append counter to duplicate files on unzip.
Browse files Browse the repository at this point in the history
Signed-off-by: Finn Carroll <carrofin@amazon.com>
  • Loading branch information
finnegancarroll committed Dec 20, 2024
1 parent 7050ecf commit 4b1b382
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,25 @@ private void extractJars(Set<File> jars) {
jars.forEach(jar -> {
FileTree jarFiles = getProject().zipTree(jar);
getProject().copy(spec -> {
spec.eachFile(details -> {
File targetFile = new File(jarExpandDir, details.getPath());

Check warning on line 313 in buildSrc/src/main/java/org/opensearch/gradle/precommit/ThirdPartyAuditTask.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/precommit/ThirdPartyAuditTask.java#L312-L313

Added lines #L312 - L313 were not covered by tests
if (targetFile.exists()) {
if ((targetFile.isDirectory() && !details.isDirectory()) || (details.isDirectory() && targetFile.isFile())) {

// Windows duplicate handling. dup.txt-1, dup.txt-2, ...
int counter = 1;
String basePath = details.getPath();

Check warning on line 319 in buildSrc/src/main/java/org/opensearch/gradle/precommit/ThirdPartyAuditTask.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/precommit/ThirdPartyAuditTask.java#L318-L319

Added lines #L318 - L319 were not covered by tests
String newPath;
do {
newPath = basePath + "-" + counter++;
targetFile = new File(jarExpandDir, newPath);

Check warning on line 323 in buildSrc/src/main/java/org/opensearch/gradle/precommit/ThirdPartyAuditTask.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/precommit/ThirdPartyAuditTask.java#L322-L323

Added lines #L322 - L323 were not covered by tests
} while (targetFile.exists());

details.setPath(newPath);

Check warning on line 326 in buildSrc/src/main/java/org/opensearch/gradle/precommit/ThirdPartyAuditTask.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/precommit/ThirdPartyAuditTask.java#L326

Added line #L326 was not covered by tests
}
}
});

Check warning on line 329 in buildSrc/src/main/java/org/opensearch/gradle/precommit/ThirdPartyAuditTask.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/precommit/ThirdPartyAuditTask.java#L329

Added line #L329 was not covered by tests

spec.from(jarFiles);
spec.into(jarExpandDir);
// exclude classes from multi release jars
Expand Down

0 comments on commit 4b1b382

Please sign in to comment.