Skip to content

Commit 4e866be

Browse files
ThirdPartyAudit append counter to duplicate files on unzip.
Signed-off-by: Finn Carroll <carrofin@amazon.com>
1 parent 2b402ec commit 4e866be

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

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

+19
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,25 @@ private void extractJars(Set<File> jars) {
309309
jars.forEach(jar -> {
310310
FileTree jarFiles = getProject().zipTree(jar);
311311
getProject().copy(spec -> {
312+
spec.eachFile(details -> {
313+
File targetFile = new File(jarExpandDir, details.getPath());
314+
if (targetFile.exists()) {
315+
if ((targetFile.isDirectory() && !details.isDirectory()) || (details.isDirectory() && targetFile.isFile())) {
316+
317+
// Windows duplicate handling. dup.txt-1, dup.txt-2, ...
318+
int counter = 1;
319+
String basePath = details.getPath();
320+
String newPath;
321+
do {
322+
newPath = basePath + "-" + counter++;
323+
targetFile = new File(jarExpandDir, newPath);
324+
} while (targetFile.exists());
325+
326+
details.setPath(newPath);
327+
}
328+
}
329+
});
330+
312331
spec.from(jarFiles);
313332
spec.into(jarExpandDir);
314333
// exclude classes from multi release jars

0 commit comments

Comments
 (0)