diff --git a/ion/include/ion/storage.h b/ion/include/ion/storage.h index 9500e0836..b159f366c 100644 --- a/ion/include/ion/storage.h +++ b/ion/include/ion/storage.h @@ -82,6 +82,8 @@ public: Record recordBaseNamedWithExtension(const char * baseName, const char * extension); Record recordBaseNamedWithExtensions(const char * baseName, const char * extension[], size_t numberOfExtensions); + // Record destruction + void destroyRecordsWithExtension(const char * extension); private: constexpr static uint32_t Magic = 0xEE0BDDBA; constexpr static size_t k_maxRecordSize = (1 << sizeof(record_size_t)*8); diff --git a/ion/src/shared/storage.cpp b/ion/src/shared/storage.cpp index 03c735d72..401dc9fd3 100644 --- a/ion/src/shared/storage.cpp +++ b/ion/src/shared/storage.cpp @@ -183,6 +183,20 @@ Storage::Record Storage::recordBaseNamedWithExtensions(const char * baseName, co return Record(); } +void Storage::destroyRecordsWithExtension(const char * extension) { + size_t extensionLength = strlen(extension); + char * currentRecordStart = (char *)m_buffer; + while (currentRecordStart != nullptr && sizeOfRecordStarting(currentRecordStart) != 0) { + const char * currentFullName = fullNameOfRecordStarting(currentRecordStart); + if (FullNameHasExtension(currentFullName, extension, extensionLength)) { + Record currentRecord(currentFullName); + currentRecord.destroy(); + continue; + } + currentRecordStart = *(RecordIterator(currentRecordStart).operator++()); + } +} + const char * Storage::fullNameOfRecord(const Record record) { for (char * p : *this) { Record currentRecord(fullNameOfRecordStarting(p));