3
0
mirror of https://github.com/Qortal/qortal.git synced 2025-02-12 02:05:50 +00:00

Auto delete any metadata files that are unreadable (e.g. due to being empty, or invalid JSON).

This commit is contained in:
CalDescent 2023-04-23 11:30:42 +01:00
parent e48529704c
commit f27c9193c7
2 changed files with 13 additions and 2 deletions

View File

@ -50,7 +50,7 @@ public class ArbitraryDataMetadata {
this.readJson();
} catch (JSONException e) {
throw new DataException(String.format("Unable to read JSON: %s", e.getMessage()));
throw new DataException(String.format("Unable to read JSON at path %s: %s", this.filePath, e.getMessage()));
}
}
@ -64,6 +64,10 @@ public class ArbitraryDataMetadata {
writer.close();
}
public void delete() throws IOException {
Files.delete(this.filePath);
}
protected void loadJson() throws IOException {
File metadataFile = new File(this.filePath.toString());

View File

@ -102,7 +102,14 @@ public class ArbitraryMetadataManager {
if (metadataFile.exists()) {
// Use local copy
ArbitraryDataTransactionMetadata transactionMetadata = new ArbitraryDataTransactionMetadata(metadataFile.getFilePath());
transactionMetadata.read();
try {
transactionMetadata.read();
} catch (DataException e) {
// Invalid file, so delete it
LOGGER.info("Deleting invalid metadata file due to exception: {}", e.getMessage());
transactionMetadata.delete();
return null;
}
return transactionMetadata;
}
}