From f0e13fa492bbbe896329711e9561a393ea3cb727 Mon Sep 17 00:00:00 2001 From: CalDescent Date: Fri, 15 Oct 2021 13:58:27 +0100 Subject: [PATCH] Arbitrary transaction names are now case insensitive --- .../arbitrary/ArbitraryDataBuildQueueItem.java | 2 +- .../arbitrary/ArbitraryDataBuildManager.java | 5 ++++- .../controller/arbitrary/ArbitraryDataManager.java | 13 ++++++++++++- .../hsqldb/HSQLDBArbitraryRepository.java | 4 ++-- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/qortal/arbitrary/ArbitraryDataBuildQueueItem.java b/src/main/java/org/qortal/arbitrary/ArbitraryDataBuildQueueItem.java index 040ac197..f89fafda 100644 --- a/src/main/java/org/qortal/arbitrary/ArbitraryDataBuildQueueItem.java +++ b/src/main/java/org/qortal/arbitrary/ArbitraryDataBuildQueueItem.java @@ -24,7 +24,7 @@ public class ArbitraryDataBuildQueueItem { public static long FAILURE_TIMEOUT = 5*60*1000L; // 5 minutes public ArbitraryDataBuildQueueItem(String resourceId, ResourceIdType resourceIdType, Service service) { - this.resourceId = resourceId; + this.resourceId = resourceId.toLowerCase(); this.resourceIdType = resourceIdType; this.service = service; this.creationTimestamp = NTP.getTime(); diff --git a/src/main/java/org/qortal/controller/arbitrary/ArbitraryDataBuildManager.java b/src/main/java/org/qortal/controller/arbitrary/ArbitraryDataBuildManager.java index 63c33a7b..96f24f08 100644 --- a/src/main/java/org/qortal/controller/arbitrary/ArbitraryDataBuildManager.java +++ b/src/main/java/org/qortal/controller/arbitrary/ArbitraryDataBuildManager.java @@ -84,6 +84,9 @@ public class ArbitraryDataBuildManager implements Runnable { } private void removeFromQueue(String resourceId) { - ArbitraryDataManager.getInstance().arbitraryDataBuildQueue.remove(resourceId); + if (resourceId == null) { + return; + } + ArbitraryDataManager.getInstance().arbitraryDataBuildQueue.remove(resourceId.toLowerCase()); } } diff --git a/src/main/java/org/qortal/controller/arbitrary/ArbitraryDataManager.java b/src/main/java/org/qortal/controller/arbitrary/ArbitraryDataManager.java index c54ac43a..d1f625d3 100644 --- a/src/main/java/org/qortal/controller/arbitrary/ArbitraryDataManager.java +++ b/src/main/java/org/qortal/controller/arbitrary/ArbitraryDataManager.java @@ -272,6 +272,10 @@ public class ArbitraryDataManager extends Thread { // Arbitrary data resource cache public boolean isResourceCached(String resourceId) { + if (resourceId == null) { + return false; + } + resourceId = resourceId.toLowerCase(); // We don't have an entry for this resource ID, it is not cached if (this.arbitraryDataCachedResources == null) { @@ -297,6 +301,11 @@ public class ArbitraryDataManager extends Thread { } public void addResourceToCache(String resourceId) { + if (resourceId == null) { + return; + } + resourceId = resourceId.toLowerCase(); + // Just in case if (this.arbitraryDataCachedResources == null) { this.arbitraryDataCachedResources = new HashMap<>(); @@ -319,6 +328,7 @@ public class ArbitraryDataManager extends Thread { if (resourceId == null) { return false; } + resourceId = resourceId.toLowerCase(); if (this.arbitraryDataBuildQueue == null) { return false; @@ -398,6 +408,7 @@ public class ArbitraryDataManager extends Thread { if (resourceId == null) { return false; } + resourceId = resourceId.toLowerCase(); if (this.arbitraryDataFailedBuilds == null) { return false; @@ -537,7 +548,7 @@ public class ArbitraryDataManager extends Thread { // so that it is rebuilt the next time we serve it if (arbitraryDataFile.exists() || arbitraryDataFile.allChunksExist(arbitraryTransactionData.getChunkHashes())) { if (arbitraryTransactionData.getName() != null) { - String resourceId = arbitraryTransactionData.getName(); + String resourceId = arbitraryTransactionData.getName().toLowerCase(); if (this.arbitraryDataCachedResources.containsKey(resourceId)) { this.arbitraryDataCachedResources.remove(resourceId); } diff --git a/src/main/java/org/qortal/repository/hsqldb/HSQLDBArbitraryRepository.java b/src/main/java/org/qortal/repository/hsqldb/HSQLDBArbitraryRepository.java index e7ee0d50..0e94314c 100644 --- a/src/main/java/org/qortal/repository/hsqldb/HSQLDBArbitraryRepository.java +++ b/src/main/java/org/qortal/repository/hsqldb/HSQLDBArbitraryRepository.java @@ -229,7 +229,7 @@ public class HSQLDBArbitraryRepository implements ArbitraryRepository { "version, nonce, service, size, is_data_raw, data, chunk_hashes, " + "name, update_method, secret, compression FROM ArbitraryTransactions " + "JOIN Transactions USING (signature) " + - "WHERE name = ? AND service = ?"); + "WHERE lower(name) = ? AND service = ?"); if (method != null) { sql.append(" AND update_method = "); @@ -238,7 +238,7 @@ public class HSQLDBArbitraryRepository implements ArbitraryRepository { sql.append("ORDER BY created_when DESC LIMIT 1"); - try (ResultSet resultSet = this.repository.checkedExecute(sql.toString(), name, service.value)) { + try (ResultSet resultSet = this.repository.checkedExecute(sql.toString(), name.toLowerCase(), service.value)) { if (resultSet == null) return null;