diff --git a/catalogue/RdbmsCatalogue.cpp b/catalogue/RdbmsCatalogue.cpp index 3a42339590bfcb987518b0b0241d61212f84be65..8334552f1805b3060d04f39f1f6c27e6e78b30c9 100644 --- a/catalogue/RdbmsCatalogue.cpp +++ b/catalogue/RdbmsCatalogue.cpp @@ -4329,7 +4329,14 @@ void RdbmsCatalogue::insertArchiveFile(rdbms::Conn &conn, const ArchiveFileRow & stmt.bindUint64(":DISK_FILE_GID", row.diskFileGid); stmt.bindUint64(":SIZE_IN_BYTES", row.size); stmt.bindBlob (":CHECKSUM_BLOB", row.checksumBlob.serialize()); - stmt.bindBlob (":CHECKSUM_ADLER32", "0x" + checksum::ChecksumBlob::ByteArrayToHex(row.checksumBlob.at(checksum::ADLER32))); + // Keep transition ADLER32 checksum up-to-date if it exists + std::string adler32str; + try { + adler32str = checksum::ChecksumBlob::ByteArrayToHex(row.checksumBlob.at(checksum::ADLER32)); + } catch(exception::ChecksumTypeMismatch &ex) { + adler32str = "0"; + } + stmt.bindBlob (":CHECKSUM_ADLER32", "0x" + adler32str); stmt.bindString(":STORAGE_CLASS_NAME", row.storageClassName); stmt.bindUint64(":CREATION_TIME", now); stmt.bindUint64(":RECONCILIATION_TIME", now); diff --git a/common/checksum/ChecksumBlob.hpp b/common/checksum/ChecksumBlob.hpp index 2dd33ba8344242cadef4971fc5bf4aa6538266d9..25b12517244eb8d7da4ced6a5ac32db74cc856dd 100644 --- a/common/checksum/ChecksumBlob.hpp +++ b/common/checksum/ChecksumBlob.hpp @@ -135,7 +135,14 @@ public: * Return the checksum for the specified key */ std::string at(ChecksumType type) const { - return m_cs.at(type); + try { + return m_cs.at(type); + } catch(std::out_of_range) { + std::stringstream ss; + ss << ChecksumTypeName.at(type) << " checksum not found. Checksum blob contents: " + << *this; + throw exception::ChecksumTypeMismatch(ss.str()); + } } /*! diff --git a/common/checksum/ChecksumBlobTest.cpp b/common/checksum/ChecksumBlobTest.cpp index a46018d244199e814dbaf630b471c720db4ffc56..1a9bd3768b2fbd9e8f7a25e6f0d567229d127193 100644 --- a/common/checksum/ChecksumBlobTest.cpp +++ b/common/checksum/ChecksumBlobTest.cpp @@ -38,6 +38,14 @@ TEST_F(cta_ChecksumBlobTest, checksum_types) { ASSERT_EQ(checksumBlob.empty(), true); ASSERT_EQ(checksumBlob.size(), 0); + // Checksum type not in blob + ASSERT_THROW(checksumBlob.at(NONE), ChecksumTypeMismatch); + ASSERT_THROW(checksumBlob.at(ADLER32), ChecksumTypeMismatch); + ASSERT_THROW(checksumBlob.at(CRC32), ChecksumTypeMismatch); + ASSERT_THROW(checksumBlob.at(CRC32C), ChecksumTypeMismatch); + ASSERT_THROW(checksumBlob.at(MD5), ChecksumTypeMismatch); + ASSERT_THROW(checksumBlob.at(SHA1), ChecksumTypeMismatch); + // valid insertions checksumBlob.insert(NONE, ""); // 0 bits ASSERT_EQ(checksumBlob.size(), 1);