Skip to content

Commit 1e43c7c

Browse files
authored
Fix writeChecksums to clean up any dangling sha1 files. (#15524)
1 parent afcca4b commit 1e43c7c

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/licenses/CheckJarChecksumsAndLicensesPlugin.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,17 @@ private static void inspectLicenseAndNoticeFile(
274274
/** Update checksums for each jar. */
275275
private static void writeChecksums(CollectJarInfos task, Directory licensesDir) {
276276
try {
277+
var licensesPath = licensesDir.getAsFile().toPath();
278+
var sha1Matcher = licensesPath.getFileSystem().getPathMatcher("glob:**.sha1");
279+
Set<Path> danglingShaFiles;
280+
try (var stream = Files.list(licensesPath)) {
281+
danglingShaFiles = stream.filter(sha1Matcher::matches).collect(Collectors.toSet());
282+
}
283+
277284
for (var jarInfo : task.getUniqueJarInfos()) {
278-
var expectedChecksumFile =
279-
licensesDir.file(jarInfo.fileName() + ".sha1").getAsFile().toPath();
285+
var expectedChecksumFile = licensesPath.resolve(jarInfo.fileName() + ".sha1");
286+
danglingShaFiles.remove(expectedChecksumFile);
287+
280288
var newChecksum = jarInfo.checksum();
281289
if (Files.exists(expectedChecksumFile)) {
282290
var previousChecksum = Files.readString(expectedChecksumFile).trim();
@@ -286,6 +294,10 @@ private static void writeChecksums(CollectJarInfos task, Directory licensesDir)
286294
}
287295
Files.writeString(expectedChecksumFile, newChecksum + "\n");
288296
}
297+
298+
for (var path : danglingShaFiles) {
299+
Files.delete(path);
300+
}
289301
} catch (IOException e) {
290302
throw new UncheckedIOException(e);
291303
}

0 commit comments

Comments
 (0)