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 <[email protected]>
  • 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());
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();
String newPath;
do {
newPath = basePath + "-" + counter++;
targetFile = new File(jarExpandDir, newPath);
} while (targetFile.exists());

details.setPath(newPath);
}
}
});

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

0 comments on commit 4b1b382

Please sign in to comment.