Skip to content

Commit 0c123d7

Browse files
author
Federico Fissore
committed
Deleting json files if they are some how corrupted. Fixes #3015
1 parent 875a775 commit 0c123d7

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

arduino-core/src/processing/app/BaseNoGui.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import cc.arduino.files.DeleteFilesOnShutdown;
88
import cc.arduino.packages.DiscoveryManager;
99
import cc.arduino.packages.Uploader;
10+
import com.fasterxml.jackson.core.JsonProcessingException;
1011
import org.apache.commons.logging.impl.LogFactoryImpl;
1112
import org.apache.commons.logging.impl.NoOpLog;
1213
import processing.app.debug.Compiler;
@@ -597,9 +598,13 @@ static public void initPackages() throws Exception {
597598

598599
try {
599600
indexer.parseIndex();
601+
} catch (JsonProcessingException e) {
602+
FileUtils.deleteIfExists(indexFile);
603+
FileUtils.deleteIfExists(indexSignatureFile);
604+
throw e;
600605
} catch (SignatureVerificationFailedException e) {
601-
indexFile.delete();
602-
indexSignatureFile.delete();
606+
FileUtils.deleteIfExists(indexFile);
607+
FileUtils.deleteIfExists(indexSignatureFile);
603608
throw e;
604609
}
605610
indexer.syncWithFilesystem(getHardwareFolder());
@@ -631,7 +636,12 @@ static public void initPackages() throws Exception {
631636
}
632637
}
633638
}
634-
librariesIndexer.parseIndex();
639+
try {
640+
librariesIndexer.parseIndex();
641+
} catch (JsonProcessingException e) {
642+
FileUtils.deleteIfExists(librariesIndexFile);
643+
throw e;
644+
}
635645
}
636646

637647
static protected void initPlatform() {

arduino-core/src/processing/app/helpers/FileUtils.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public static void recursiveDelete(File file) {
8585
recursiveDelete(current);
8686
}
8787
}
88-
file.delete();
88+
deleteIfExists(file);
8989
}
9090

9191
public static File createTempFolder() throws IOException {
@@ -269,5 +269,16 @@ public static File newFile(File parent, String... parts) {
269269
return result;
270270
}
271271

272+
public static boolean deleteIfExists(File file) {
273+
if (file == null) {
274+
return true;
275+
}
276+
277+
if (!file.exists()) {
278+
return false;
279+
}
280+
281+
return file.delete();
282+
}
272283

273284
}

0 commit comments

Comments
 (0)