Skip to content

Commit 3a0464d

Browse files
committed
checked file deletion
1 parent cd179b7 commit 3a0464d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/main/java/com/falsepattern/lib/dependencies/DependencyLoader.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,7 @@ public static void loadLibrary(@NonNull String loadingModId,
121121
return;
122122
} catch (RuntimeException e) {
123123
log.warn("Failed to load library {} from file! Re-downloading...", artifactLogName);
124-
if (!file.delete()) {
125-
log.fatal("Failed to delete file {}", file);
126-
throw new RuntimeException("Failed to delete file " + file);
127-
}
124+
checkedDelete(file);
128125
}
129126
}
130127
if (!LibraryConfig.ENABLE_LIBRARY_DOWNLOADS) {
@@ -185,7 +182,8 @@ public static void loadLibrary(@NonNull String loadingModId,
185182
if (!fileHash.equals(referenceHash)) {
186183
log.error("Failed {} checksum validation for {}. Retrying download...",
187184
checksumType, artifactLogName);
188-
file.delete();
185+
checkedDelete(file);
186+
checkedDelete(checksumFile);
189187
retry = true;
190188
continue redownload;
191189
}
@@ -252,6 +250,13 @@ private static String hash(String algo, File file) {
252250
return digest(algo, data);
253251
}
254252

253+
private static void checkedDelete(File file) {
254+
if (!file.delete()) {
255+
log.fatal("Failed to delete file {}", file);
256+
throw new RuntimeException("Failed to delete file " + file);
257+
}
258+
}
259+
255260
private static void addToClasspath(File file) {
256261
try {
257262
val cl = (LaunchClassLoader) DependencyLoader.class.getClassLoader();

0 commit comments

Comments
 (0)