Don't delete metadata when deleting a resource from the Data Management screen.

This commit is contained in:
CalDescent 2023-03-31 15:36:51 +01:00
parent e598d7476b
commit 7deb9328fa
6 changed files with 14 additions and 11 deletions

View File

@ -592,7 +592,7 @@ public class ArbitraryResource {
Security.checkApiCallAllowed(request); Security.checkApiCallAllowed(request);
ArbitraryDataResource resource = new ArbitraryDataResource(name, ResourceIdType.NAME, service, identifier); ArbitraryDataResource resource = new ArbitraryDataResource(name, ResourceIdType.NAME, service, identifier);
return resource.delete(); return resource.delete(false);
} }
@POST @POST

View File

@ -388,12 +388,15 @@ public class ArbitraryDataFile {
return false; return false;
} }
public boolean deleteAll() { public boolean deleteAll(boolean deleteMetadata) {
// Delete the complete file // Delete the complete file
boolean fileDeleted = this.delete(); boolean fileDeleted = this.delete();
// Delete the metadata file // Delete the metadata file if requested
boolean metadataDeleted = this.deleteMetadata(); boolean metadataDeleted = false;
if (deleteMetadata) {
metadataDeleted = this.deleteMetadata();
}
// Delete the individual chunks // Delete the individual chunks
boolean chunksDeleted = this.deleteAllChunks(); boolean chunksDeleted = this.deleteAllChunks();

View File

@ -140,7 +140,7 @@ public class ArbitraryDataResource {
return null; return null;
} }
public boolean delete() { public boolean delete(boolean deleteMetadata) {
try { try {
this.fetchTransactions(); this.fetchTransactions();
if (this.transactions == null) { if (this.transactions == null) {
@ -157,7 +157,7 @@ public class ArbitraryDataResource {
arbitraryDataFile.setMetadataHash(metadataHash); arbitraryDataFile.setMetadataHash(metadataHash);
// Delete any chunks or complete files from each transaction // Delete any chunks or complete files from each transaction
arbitraryDataFile.deleteAll(); arbitraryDataFile.deleteAll(deleteMetadata);
} }
// Also delete cached data for the entire resource // Also delete cached data for the entire resource

View File

@ -281,7 +281,7 @@ public class ArbitraryDataTransactionBuilder {
} catch (DataException e) { } catch (DataException e) {
if (arbitraryDataFile != null) { if (arbitraryDataFile != null) {
arbitraryDataFile.deleteAll(); arbitraryDataFile.deleteAll(true);
} }
throw(e); throw(e);
} }
@ -315,7 +315,7 @@ public class ArbitraryDataTransactionBuilder {
Transaction.ValidationResult result = transaction.isValidUnconfirmed(); Transaction.ValidationResult result = transaction.isValidUnconfirmed();
if (result != Transaction.ValidationResult.OK) { if (result != Transaction.ValidationResult.OK) {
arbitraryDataFile.deleteAll(); arbitraryDataFile.deleteAll(true);
throw new DataException(String.format("Arbitrary transaction invalid: %s", result)); throw new DataException(String.format("Arbitrary transaction invalid: %s", result));
} }
LOGGER.info("Transaction is valid"); LOGGER.info("Transaction is valid");

View File

@ -155,8 +155,8 @@ public class HSQLDBArbitraryRepository implements ArbitraryRepository {
ArbitraryDataFile arbitraryDataFile = ArbitraryDataFile.fromHash(hash, signature); ArbitraryDataFile arbitraryDataFile = ArbitraryDataFile.fromHash(hash, signature);
arbitraryDataFile.setMetadataHash(metadataHash); arbitraryDataFile.setMetadataHash(metadataHash);
// Delete file and chunks // Delete file, chunks, and metadata
arbitraryDataFile.deleteAll(); arbitraryDataFile.deleteAll(true);
} }
@Override @Override

View File

@ -249,7 +249,7 @@ public class ArbitraryTransactionUtils {
ArbitraryDataFile arbitraryDataFile = ArbitraryDataFile.fromHash(completeHash, signature); ArbitraryDataFile arbitraryDataFile = ArbitraryDataFile.fromHash(completeHash, signature);
arbitraryDataFile.setMetadataHash(metadataHash); arbitraryDataFile.setMetadataHash(metadataHash);
arbitraryDataFile.deleteAll(); arbitraryDataFile.deleteAll(true);
} }
public static void convertFileToChunks(ArbitraryTransactionData arbitraryTransactionData, long now, long cleanupAfter) throws DataException { public static void convertFileToChunks(ArbitraryTransactionData arbitraryTransactionData, long now, long cleanupAfter) throws DataException {