mirror of
https://github.com/Qortal/qortal.git
synced 2025-03-26 23:44:34 +00:00
Auto delete any metadata files that are unreadable (e.g. due to being empty, or invalid JSON).
This commit is contained in:
parent
e48529704c
commit
f27c9193c7
@ -50,7 +50,7 @@ public class ArbitraryDataMetadata {
|
|||||||
this.readJson();
|
this.readJson();
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} 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();
|
writer.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void delete() throws IOException {
|
||||||
|
Files.delete(this.filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void loadJson() throws IOException {
|
protected void loadJson() throws IOException {
|
||||||
File metadataFile = new File(this.filePath.toString());
|
File metadataFile = new File(this.filePath.toString());
|
||||||
|
@ -102,7 +102,14 @@ public class ArbitraryMetadataManager {
|
|||||||
if (metadataFile.exists()) {
|
if (metadataFile.exists()) {
|
||||||
// Use local copy
|
// Use local copy
|
||||||
ArbitraryDataTransactionMetadata transactionMetadata = new ArbitraryDataTransactionMetadata(metadataFile.getFilePath());
|
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;
|
return transactionMetadata;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user