From b05a4836f69338fca77389e5d26e61ee6c264b6b Mon Sep 17 00:00:00 2001 From: Sharaf Mohamed Date: Tue, 1 Mar 2022 20:05:27 -0500 Subject: [PATCH] Change ErrorCode enum to an enum class --- components/core/src/ArrayBackedPosIntSet.hpp | 2 +- components/core/src/DictionaryReader.hpp | 18 +++--- components/core/src/DictionaryWriter.hpp | 14 ++--- .../core/src/EncodedVariableInterpreter.cpp | 2 +- components/core/src/ErrorCode.hpp | 28 +++++++++ components/core/src/FileReader.cpp | 42 +++++++------- components/core/src/FileReader.hpp | 38 ++++++------ components/core/src/FileWriter.cpp | 44 +++++++------- components/core/src/FileWriter.hpp | 18 +++--- components/core/src/GlobalMySQLMetadataDB.cpp | 22 +++---- .../core/src/GlobalSQLiteMetadataDB.cpp | 10 ++-- components/core/src/LibarchiveFileReader.cpp | 52 ++++++++--------- components/core/src/LibarchiveFileReader.hpp | 20 +++---- components/core/src/LibarchiveReader.cpp | 58 +++++++++---------- components/core/src/LibarchiveReader.hpp | 16 ++--- .../core/src/LogTypeDictionaryEntry.cpp | 12 ++-- .../core/src/LogTypeDictionaryWriter.cpp | 2 +- components/core/src/MessageParser.cpp | 4 +- components/core/src/MySQLDB.cpp | 18 +++--- components/core/src/MySQLParamBindings.cpp | 6 +- .../core/src/MySQLPreparedStatement.cpp | 6 +- components/core/src/PageAllocatedVector.hpp | 8 +-- components/core/src/ReaderInterface.cpp | 34 +++++------ components/core/src/ReaderInterface.hpp | 12 ++-- components/core/src/SQLiteDB.cpp | 4 +- .../core/src/SQLitePreparedStatement.cpp | 36 ++++++------ components/core/src/TimestampPattern.cpp | 4 +- components/core/src/Utils.cpp | 42 +++++++------- components/core/src/Utils.hpp | 20 +++---- .../core/src/VariableDictionaryEntry.cpp | 8 +-- .../core/src/VariableDictionaryWriter.cpp | 2 +- components/core/src/Writer.cpp | 8 +-- components/core/src/Writer.hpp | 6 +- components/core/src/WriterInterface.cpp | 6 +- components/core/src/clg/clg.cpp | 12 ++-- components/core/src/clo/clo.cpp | 6 +- components/core/src/clp/FileCompressor.cpp | 14 ++--- components/core/src/clp/FileDecompressor.cpp | 6 +- components/core/src/clp/clp.cpp | 2 +- components/core/src/clp/compression.cpp | 24 ++++---- components/core/src/clp/decompression.cpp | 4 +- components/core/src/clp/utils.cpp | 6 +- .../core/src/streaming_archive/MetadataDB.cpp | 4 +- .../src/streaming_archive/reader/Archive.cpp | 10 ++-- .../src/streaming_archive/reader/File.cpp | 30 +++++----- .../src/streaming_archive/reader/File.hpp | 10 ++-- .../src/streaming_archive/reader/Segment.cpp | 10 ++-- .../src/streaming_archive/reader/Segment.hpp | 10 ++-- .../reader/SegmentManager.cpp | 2 +- .../src/streaming_archive/writer/Archive.cpp | 34 +++++------ .../src/streaming_archive/writer/File.cpp | 4 +- .../src/streaming_archive/writer/Segment.cpp | 2 +- .../src/streaming_compression/Compressor.hpp | 8 +-- .../passthrough/Compressor.cpp | 8 +-- .../passthrough/Compressor.hpp | 2 +- .../passthrough/Decompressor.cpp | 20 +++---- .../passthrough/Decompressor.hpp | 18 +++--- .../streaming_compression/zstd/Compressor.cpp | 22 +++---- .../streaming_compression/zstd/Compressor.hpp | 4 +- .../zstd/Decompressor.cpp | 46 +++++++-------- .../zstd/Decompressor.hpp | 22 +++---- components/core/tests/test-Segment.cpp | 6 +- .../core/tests/test-StreamingCompression.cpp | 32 +++++----- components/core/tests/test-Utils.cpp | 6 +- 64 files changed, 517 insertions(+), 489 deletions(-) diff --git a/components/core/src/ArrayBackedPosIntSet.hpp b/components/core/src/ArrayBackedPosIntSet.hpp index 14a174482d..785202c222 100644 --- a/components/core/src/ArrayBackedPosIntSet.hpp +++ b/components/core/src/ArrayBackedPosIntSet.hpp @@ -186,7 +186,7 @@ template void ArrayBackedPosIntSet::increase_capacity (size_t value) { if (value < m_data.size()) { SPDLOG_ERROR("Calling increase_capacity on value smaller than capacity."); - throw OperationFailed(ErrorCode_BadParam, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::BadParam, __FILENAME__, __LINE__); } auto capacity = m_data.size(); do { diff --git a/components/core/src/DictionaryReader.hpp b/components/core/src/DictionaryReader.hpp index d2210ef626..e6523add88 100644 --- a/components/core/src/DictionaryReader.hpp +++ b/components/core/src/DictionaryReader.hpp @@ -113,7 +113,7 @@ class DictionaryReader { template void DictionaryReader::open (const std::string& dictionary_path, const std::string& segment_index_path) { if (m_is_open) { - throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotReady, __FILENAME__, __LINE__); } constexpr size_t cDecompressorFileReadBufferCapacity = 64 * 1024; // 64 KB @@ -127,7 +127,7 @@ void DictionaryReader::open (const std::string& dic template void DictionaryReader::close () { if (false == m_is_open) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } m_segment_index_decompressor.close(); @@ -144,7 +144,7 @@ void DictionaryReader::close () { template void DictionaryReader::read_new_entries () { if (false == m_is_open) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } // Read dictionary header @@ -152,7 +152,7 @@ void DictionaryReader::read_new_entries () { // Validate dictionary header if (num_dictionary_entries < m_entries.size()) { - throw OperationFailed(ErrorCode_Corrupt, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Corrupt, __FILENAME__, __LINE__); } // Read new dictionary entries @@ -173,7 +173,7 @@ void DictionaryReader::read_new_entries () { // Validate segment index header if (num_segments < m_num_segments_read_from_index) { - throw OperationFailed(ErrorCode_Corrupt, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Corrupt, __FILENAME__, __LINE__); } // Read new segments from index @@ -188,10 +188,10 @@ void DictionaryReader::read_new_entries () { template const EntryType& DictionaryReader::get_entry (DictionaryIdType id) const { if (false == m_is_open) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } if (id >= m_entries.size()) { - throw OperationFailed(ErrorCode_BadParam, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::BadParam, __FILENAME__, __LINE__); } return m_entries[id]; @@ -200,7 +200,7 @@ const EntryType& DictionaryReader::get_entry (Dicti template const std::string& DictionaryReader::get_value (DictionaryIdType id) const { if (id >= m_entries.size()) { - throw OperationFailed(ErrorCode_Corrupt, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Corrupt, __FILENAME__, __LINE__); } return m_entries[id].get_value(); } @@ -247,7 +247,7 @@ void DictionaryReader::read_segment_ids () { DictionaryIdType id; m_segment_index_decompressor.read_numeric_value(id, false); if (id >= m_entries.size()) { - throw OperationFailed(ErrorCode_Corrupt, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Corrupt, __FILENAME__, __LINE__); } m_entries[id].add_segment_containing_entry(segment_id); diff --git a/components/core/src/DictionaryWriter.hpp b/components/core/src/DictionaryWriter.hpp index 97c0244965..7b9435c655 100644 --- a/components/core/src/DictionaryWriter.hpp +++ b/components/core/src/DictionaryWriter.hpp @@ -112,7 +112,7 @@ class DictionaryWriter { template void DictionaryWriter::open (const std::string& dictionary_path, const std::string& segment_index_path, DictionaryIdType max_id) { if (m_is_open) { - throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotReady, __FILENAME__, __LINE__); } m_dictionary_file_writer.open(dictionary_path, FileWriter::OpenMode::CREATE_FOR_WRITING); @@ -139,7 +139,7 @@ void DictionaryWriter::open (const std::string& dic template void DictionaryWriter::close () { if (false == m_is_open) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } write_header_and_flush_to_disk(); @@ -156,7 +156,7 @@ void DictionaryWriter::close () { template void DictionaryWriter::write_header_and_flush_to_disk () { if (false == m_is_open) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } // Update header @@ -176,7 +176,7 @@ void DictionaryWriter::open_and_preload (const std: const variable_dictionary_id_t max_id) { if (m_is_open) { - throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotReady, __FILENAME__, __LINE__); } m_max_id = max_id; @@ -192,7 +192,7 @@ void DictionaryWriter::open_and_preload (const std: auto num_dictionary_entries = read_dictionary_header(dictionary_file_reader); if (num_dictionary_entries > m_max_id) { SPDLOG_ERROR("DictionaryWriter ran out of IDs."); - throw OperationFailed(ErrorCode_OutOfBounds, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::OutOfBounds, __FILENAME__, __LINE__); } // Loads entries from the given dictionary file EntryType entry; @@ -202,7 +202,7 @@ void DictionaryWriter::open_and_preload (const std: const auto& str_value = entry.get_value(); if (m_value_to_id.count(str_value)) { SPDLOG_ERROR("Entry's value already exists in dictionary"); - throw OperationFailed(ErrorCode_Corrupt, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Corrupt, __FILENAME__, __LINE__); } m_value_to_id[str_value] = entry.get_id();; @@ -230,7 +230,7 @@ void DictionaryWriter::open_and_preload (const std: template void DictionaryWriter::index_segment (segment_id_t segment_id, const ArrayBackedPosIntSet& ids) { if (false == m_is_open) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } m_segment_index_compressor.write_numeric_value(segment_id); diff --git a/components/core/src/EncodedVariableInterpreter.cpp b/components/core/src/EncodedVariableInterpreter.cpp index 02311d6a3c..558ff24238 100644 --- a/components/core/src/EncodedVariableInterpreter.cpp +++ b/components/core/src/EncodedVariableInterpreter.cpp @@ -284,7 +284,7 @@ bool EncodedVariableInterpreter::encode_and_search_dictionary (const string& var { size_t length = var_str.length(); if (0 == length) { - throw OperationFailed(ErrorCode_BadParam, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::BadParam, __FILENAME__, __LINE__); } encoded_variable_t encoded_var; diff --git a/components/core/src/ErrorCode.hpp b/components/core/src/ErrorCode.hpp index 6220e3993f..5e577331b2 100644 --- a/components/core/src/ErrorCode.hpp +++ b/components/core/src/ErrorCode.hpp @@ -1,6 +1,33 @@ #ifndef ERRORCODE_HPP #define ERRORCODE_HPP +// C libraries +#include + +enum class ErrorCode : uint8_t { + Success = 0, + BadParam, + BadParam_DB_URI, + Corrupt, + Errno, + EndOfFile, + FileExists, + FileNotFound, + NoMem, + NotInit, + NotReady, + OutOfBounds, + TooLong, + Truncated, + Unsupported, + NoAccess, + Failure, + Failure_Metadata_Corrupted, + MetadataCorrupted, + Failure_DB_Bulk_Write, +}; + +/* typedef enum { ErrorCode_Success = 0, ErrorCode_BadParam, @@ -23,5 +50,6 @@ typedef enum { ErrorCode_MetadataCorrupted, ErrorCode_Failure_DB_Bulk_Write } ErrorCode; +*/ #endif \ No newline at end of file diff --git a/components/core/src/FileReader.cpp b/components/core/src/FileReader.cpp index 5a2b427e69..cc43338e32 100644 --- a/components/core/src/FileReader.cpp +++ b/components/core/src/FileReader.cpp @@ -18,50 +18,50 @@ FileReader::~FileReader () { ErrorCode FileReader::try_read (char* buf, size_t num_bytes_to_read, size_t& num_bytes_read) { if (nullptr == m_file) { - return ErrorCode_NotInit; + return ErrorCode::NotInit; } if (nullptr == buf) { - return ErrorCode_BadParam; + return ErrorCode::BadParam; } num_bytes_read = fread(buf, sizeof(*buf), num_bytes_to_read, m_file); if (num_bytes_read < num_bytes_to_read) { if (ferror(m_file)) { - return ErrorCode_errno; + return ErrorCode::Errno; } else if (feof(m_file)) { if (0 == num_bytes_read) { - return ErrorCode_EndOfFile; + return ErrorCode::EndOfFile; } } } - return ErrorCode_Success; + return ErrorCode::Success; } ErrorCode FileReader::try_seek_from_begin (size_t pos) { if (nullptr == m_file) { - return ErrorCode_NotInit; + return ErrorCode::NotInit; } int retval = fseeko(m_file, pos, SEEK_SET); if (0 != retval) { - return ErrorCode_errno; + return ErrorCode::Errno; } - return ErrorCode_Success; + return ErrorCode::Success; } ErrorCode FileReader::try_get_pos (size_t& pos) { if (nullptr == m_file) { - return ErrorCode_NotInit; + return ErrorCode::NotInit; } pos = ftello(m_file); if ((off_t)-1 == pos) { - return ErrorCode_errno; + return ErrorCode::Errno; } - return ErrorCode_Success; + return ErrorCode::Success; } ErrorCode FileReader::try_open (const string& path) { @@ -71,17 +71,17 @@ ErrorCode FileReader::try_open (const string& path) { m_file = fopen(path.c_str(), "rb"); if (nullptr == m_file) { if (ENOENT == errno) { - return ErrorCode_FileNotFound; + return ErrorCode::FileNotFound; } - return ErrorCode_errno; + return ErrorCode::Errno; } - return ErrorCode_Success; + return ErrorCode::Success; } void FileReader::open (const string& path) { ErrorCode error_code = try_open(path); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { throw OperationFailed(error_code, __FILENAME__, __LINE__); } } @@ -104,9 +104,9 @@ ErrorCode FileReader::try_read_to_delimiter (char delim, bool keep_delimiter, bo ssize_t num_bytes_read = getdelim(&m_getdelim_buf, &m_getdelim_buf_len, delim, m_file); if (num_bytes_read < 1) { if (ferror(m_file)) { - return ErrorCode_errno; + return ErrorCode::Errno; } else if (feof(m_file)) { - return ErrorCode_EndOfFile; + return ErrorCode::EndOfFile; } } if (false == keep_delimiter && delim == m_getdelim_buf[num_bytes_read - 1]) { @@ -114,17 +114,17 @@ ErrorCode FileReader::try_read_to_delimiter (char delim, bool keep_delimiter, bo } str.append(m_getdelim_buf, num_bytes_read); - return ErrorCode_Success; + return ErrorCode::Success; } ErrorCode FileReader::try_fstat (struct stat& stat_buffer) { if (nullptr == m_file) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } auto return_value = fstat(fileno(m_file), &stat_buffer); if (0 != return_value) { - return ErrorCode_errno; + return ErrorCode::Errno; } - return ErrorCode_Success; + return ErrorCode::Success; } diff --git a/components/core/src/FileReader.hpp b/components/core/src/FileReader.hpp index 8455030986..937fc5f063 100644 --- a/components/core/src/FileReader.hpp +++ b/components/core/src/FileReader.hpp @@ -32,17 +32,17 @@ class FileReader : public ReaderInterface { /** * Tries to get the current position of the read head in the file * @param pos Position of the read head in the file - * @return ErrorCode_NotInit if the file is not open - * @return ErrorCode_errno on error - * @return ErrorCode_Success on success + * @return ErrorCode::NotInit if the file is not open + * @return ErrorCode::Errno on error + * @return ErrorCode::Success on success */ ErrorCode try_get_pos (size_t& pos) override; /** * Tries to seek from the beginning of the file to the given position * @param pos - * @return ErrorCode_NotInit if the file is not open - * @return ErrorCode_errno on error - * @return ErrorCode_Success on success + * @return ErrorCode::NotInit if the file is not open + * @return ErrorCode::Errno on error + * @return ErrorCode::Success on success */ ErrorCode try_seek_from_begin (size_t pos) override; @@ -51,11 +51,11 @@ class FileReader : public ReaderInterface { * @param buf * @param num_bytes_to_read The number of bytes to try and read * @param num_bytes_read The actual number of bytes read - * @return ErrorCode_NotInit if the file is not open - * @return ErrorCode_BadParam if buf is invalid - * @return ErrorCode_errno on error - * @return ErrorCode_EndOfFile on EOF - * @return ErrorCode_Success on success + * @return ErrorCode::NotInit if the file is not open + * @return ErrorCode::BadParam if buf is invalid + * @return ErrorCode::Errno on error + * @return ErrorCode::EndOfFile on EOF + * @return ErrorCode::Success on success */ ErrorCode try_read (char* buf, size_t num_bytes_to_read, size_t& num_bytes_read) override; @@ -65,9 +65,9 @@ class FileReader : public ReaderInterface { * @param keep_delimiter Whether to include the delimiter in the output string or not * @param append Whether to append to the given string or replace its contents * @param str The string read - * @return ErrorCode_Success on success - * @return ErrorCode_EndOfFile on EOF - * @return ErrorCode_errno otherwise + * @return ErrorCode::Success on success + * @return ErrorCode::EndOfFile on EOF + * @return ErrorCode::Errno otherwise */ ErrorCode try_read_to_delimiter (char delim, bool keep_delimiter, bool append, std::string& str) override; @@ -77,9 +77,9 @@ class FileReader : public ReaderInterface { /** * Tries to open a file * @param path - * @return ErrorCode_Success on success - * @return ErrorCode_FileNotFound if the file was not found - * @return ErrorCode_errno otherwise + * @return ErrorCode::Success on success + * @return ErrorCode::FileNotFound if the file was not found + * @return ErrorCode::Errno otherwise */ ErrorCode try_open (const std::string& path); /** @@ -96,8 +96,8 @@ class FileReader : public ReaderInterface { /** * Tries to stat the current file * @param stat_buffer - * @return ErrorCode_errno on error - * @return ErrorCode_Success on success + * @return ErrorCode::Errno on error + * @return ErrorCode::Success on success */ ErrorCode try_fstat (struct stat& stat_buffer); diff --git a/components/core/src/FileWriter.cpp b/components/core/src/FileWriter.cpp index ca2b76e091..d3c0bc843d 100644 --- a/components/core/src/FileWriter.cpp +++ b/components/core/src/FileWriter.cpp @@ -23,18 +23,18 @@ FileWriter::~FileWriter () { } void FileWriter::write (const char* data, size_t data_length) { - ErrorCode error_code = ErrorCode_Success; + ErrorCode error_code = ErrorCode::Success; if (nullptr == m_file) { - error_code = ErrorCode_NotInit; + error_code = ErrorCode::NotInit; } else if (nullptr == data) { - error_code = ErrorCode_BadParam; + error_code = ErrorCode::BadParam; } else { size_t num_bytes_written = fwrite(data, sizeof(*data), data_length, m_file); if (num_bytes_written < data_length) { - error_code = ErrorCode_errno; + error_code = ErrorCode::Errno; } } - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { throw OperationFailed(error_code, __FILENAME__, __LINE__); } } @@ -47,58 +47,58 @@ void FileWriter::flush () { // Flush userspace buffers to page cache if (0 != fflush(m_file)) { SPDLOG_ERROR("fflush failed, errno={}", errno); - throw OperationFailed(ErrorCode_errno, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Errno, __FILENAME__, __LINE__); } // Flush page cache pages to disk if (0 != fdatasync(m_fd)) { SPDLOG_ERROR("fdatasync failed, errno={}", errno); - throw OperationFailed(ErrorCode_errno, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Errno, __FILENAME__, __LINE__); } } ErrorCode FileWriter::try_get_pos (size_t& pos) const { if (nullptr == m_file) { - return ErrorCode_NotInit; + return ErrorCode::NotInit; } pos = ftello(m_file); if ((off_t)-1 == pos) { - return ErrorCode_errno; + return ErrorCode::Errno; } - return ErrorCode_Success; + return ErrorCode::Success; } ErrorCode FileWriter::try_seek_from_begin (size_t pos) { if (nullptr == m_file) { - return ErrorCode_NotInit; + return ErrorCode::NotInit; } int retval = fseeko(m_file, pos, SEEK_SET); if (0 != retval) { - return ErrorCode_errno; + return ErrorCode::Errno; } - return ErrorCode_Success; + return ErrorCode::Success; } ErrorCode FileWriter::try_seek_from_current (off_t offset) { if (nullptr == m_file) { - return ErrorCode_NotInit; + return ErrorCode::NotInit; } int retval = fseeko(m_file, offset, SEEK_CUR); if (0 != retval) { - return ErrorCode_errno; + return ErrorCode::Errno; } - return ErrorCode_Success; + return ErrorCode::Success; } void FileWriter::open (const string& path, OpenMode open_mode) { if (nullptr != m_file) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } switch (open_mode) { @@ -115,7 +115,7 @@ void FileWriter::open (const string& path, OpenMode open_mode) { m_file = fopen(path.c_str(), "r+b"); } else { if (ENOENT != errno) { - throw OperationFailed(ErrorCode_errno, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Errno, __FILENAME__, __LINE__); } // File doesn't exist, so create and open it for seekable writing // NOTE: We can't use the "w+" mode if the file exists since that will truncate the file @@ -124,26 +124,26 @@ void FileWriter::open (const string& path, OpenMode open_mode) { auto retval = fseek(m_file, 0, SEEK_END); if (0 != retval) { - throw OperationFailed(ErrorCode_errno, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Errno, __FILENAME__, __LINE__); } break; } } if (nullptr == m_file) { - throw OperationFailed(ErrorCode_errno, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Errno, __FILENAME__, __LINE__); } m_fd = fileno(m_file); if (-1 == m_fd) { fclose(m_file); - throw OperationFailed(ErrorCode_errno, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Errno, __FILENAME__, __LINE__); } } void FileWriter::close () { if (nullptr != m_file) { if (0 != fclose(m_file)) { - throw OperationFailed(ErrorCode_errno, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Errno, __FILENAME__, __LINE__); } m_file = nullptr; m_fd = -1; diff --git a/components/core/src/FileWriter.hpp b/components/core/src/FileWriter.hpp index 3c822a5081..e9ec6dcc50 100644 --- a/components/core/src/FileWriter.hpp +++ b/components/core/src/FileWriter.hpp @@ -50,26 +50,26 @@ class FileWriter : public WriterInterface { /** * Tries to get the current position of the write head in the file * @param pos Position of the write head in the file - * @return ErrorCode_NotInit if the file is not open - * @return ErrorCode_errno on error - * @return ErrorCode_Success on success + * @return ErrorCode::NotInit if the file is not open + * @return ErrorCode::Errno on error + * @return ErrorCode::Success on success */ ErrorCode try_get_pos (size_t& pos) const override; /** * Tries to seek from the beginning of the file to the given position * @param pos - * @return ErrorCode_NotInit if the file is not open - * @return ErrorCode_errno on error - * @return ErrorCode_Success on success + * @return ErrorCode::NotInit if the file is not open + * @return ErrorCode::Errno on error + * @return ErrorCode::Success on success */ ErrorCode try_seek_from_begin (size_t pos) override; /** * Tries to offset from the current position by the given amount * @param pos - * @return ErrorCode_NotInit if the file is not open - * @return ErrorCode_errno on error - * @return ErrorCode_Success on success + * @return ErrorCode::NotInit if the file is not open + * @return ErrorCode::Errno on error + * @return ErrorCode::Success on success */ ErrorCode try_seek_from_current (off_t offset) override; diff --git a/components/core/src/GlobalMySQLMetadataDB.cpp b/components/core/src/GlobalMySQLMetadataDB.cpp index b5f98c3d55..b5ccc3efd8 100644 --- a/components/core/src/GlobalMySQLMetadataDB.cpp +++ b/components/core/src/GlobalMySQLMetadataDB.cpp @@ -44,7 +44,7 @@ void GlobalMySQLMetadataDB::ArchiveIterator::get_id (string& id) const { void GlobalMySQLMetadataDB::open () { if (m_is_open) { - throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotReady, __FILENAME__, __LINE__); } m_db.open(m_host, m_port, m_username, m_password, m_database_name); @@ -109,7 +109,7 @@ void GlobalMySQLMetadataDB::close () { void GlobalMySQLMetadataDB::add_archive (const string& id, size_t uncompressed_size, size_t size, const string& creator_id, size_t creation_num) { if (false == m_is_open) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } auto& statement_bindings = m_insert_archive_statement->get_statement_bindings(); @@ -119,13 +119,13 @@ void GlobalMySQLMetadataDB::add_archive (const string& id, size_t uncompressed_s statement_bindings.bind_varchar(enum_to_underlying_type(ArchivesTableFieldIndexes::CreatorId), creator_id.c_str(), creator_id.length()); statement_bindings.bind_uint64(enum_to_underlying_type(ArchivesTableFieldIndexes::CreationIx), creation_num); if (false == m_insert_archive_statement->execute()) { - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } } void GlobalMySQLMetadataDB::update_archive_size (const std::string& archive_id, size_t uncompressed_size, size_t size) { if (false == m_is_open) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } auto& statement_bindings = m_update_archive_size_statement->get_statement_bindings(); @@ -133,18 +133,18 @@ void GlobalMySQLMetadataDB::update_archive_size (const std::string& archive_id, statement_bindings.bind_uint64(enum_to_underlying_type(UpdateArchiveSizeStmtFieldIndexes::Size), size); statement_bindings.bind_varchar(enum_to_underlying_type(UpdateArchiveSizeStmtFieldIndexes::Length), archive_id.c_str(), archive_id.length()); if (false == m_update_archive_size_statement->execute()) { - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } } void GlobalMySQLMetadataDB::update_metadata_for_files (const std::string& archive_id, const std::vector& files) { if (false == m_is_open) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } // TODO Split into multiple transactions if necessary if (false == m_db.execute_query("BEGIN")) { - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } auto& statement_bindings = m_upsert_file_statement->get_statement_bindings(); for (auto file : files) { @@ -184,11 +184,11 @@ void GlobalMySQLMetadataDB::update_metadata_for_files (const std::string& archiv statement_bindings.bind_varchar(enum_to_underlying_type(FilesTableFieldIndexes::ArchiveId) + offset, archive_id.c_str(), archive_id.length()); if (false == m_upsert_file_statement->execute()) { - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } } if (false == m_db.execute_query("COMMIT")) { - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } } @@ -199,7 +199,7 @@ GlobalMetadataDB::ArchiveIterator* GlobalMySQLMetadataDB::get_archive_iterator ( SPDLOG_DEBUG("{}", statement_string); if (false == m_db.execute_query(statement_string)) { - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } return new ArchiveIterator(m_db.get_iterator()); @@ -217,7 +217,7 @@ GlobalMetadataDB::ArchiveIterator* GlobalMySQLMetadataDB::get_archive_iterator_f SPDLOG_DEBUG("{}", statement_string); if (false == m_db.execute_query(statement_string)) { - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } return new ArchiveIterator(m_db.get_iterator()); diff --git a/components/core/src/GlobalSQLiteMetadataDB.cpp b/components/core/src/GlobalSQLiteMetadataDB.cpp index 9d699556ab..d63447fa8f 100644 --- a/components/core/src/GlobalSQLiteMetadataDB.cpp +++ b/components/core/src/GlobalSQLiteMetadataDB.cpp @@ -136,7 +136,7 @@ void GlobalSQLiteMetadataDB::ArchiveIterator::get_id (string& id) const { void GlobalSQLiteMetadataDB::open () { if (m_is_open) { - throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotReady, __FILENAME__, __LINE__); } m_db.open(m_path); @@ -231,14 +231,14 @@ void GlobalSQLiteMetadataDB::close () { m_upsert_files_transaction_begin_statement.reset(nullptr); m_upsert_files_transaction_end_statement.reset(nullptr); if (false == m_db.close()) { - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } m_is_open = false; } void GlobalSQLiteMetadataDB::add_archive (const string& id, size_t uncompressed_size, size_t size, const string& creator_id, size_t creation_num) { if (false == m_is_open) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } m_insert_archive_statement->bind_text(enum_to_underlying_type(ArchivesTableFieldIndexes::Id) + 1, id, false); @@ -252,7 +252,7 @@ void GlobalSQLiteMetadataDB::add_archive (const string& id, size_t uncompressed_ void GlobalSQLiteMetadataDB::update_archive_size (const string& archive_id, size_t uncompressed_size, size_t size) { if (false == m_is_open) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } m_update_archive_size_statement->bind_int64(enum_to_underlying_type(UpdateArchiveSizeStmtFieldIndexes::UncompressedSize) + 1, (int64_t)uncompressed_size); @@ -264,7 +264,7 @@ void GlobalSQLiteMetadataDB::update_archive_size (const string& archive_id, size void GlobalSQLiteMetadataDB::update_metadata_for_files (const string& archive_id, const vector& files) { if (false == m_is_open) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } m_upsert_files_transaction_begin_statement->step(); diff --git a/components/core/src/LibarchiveFileReader.cpp b/components/core/src/LibarchiveFileReader.cpp index 60c41178f4..b3ef74b824 100644 --- a/components/core/src/LibarchiveFileReader.cpp +++ b/components/core/src/LibarchiveFileReader.cpp @@ -8,30 +8,30 @@ ErrorCode LibarchiveFileReader::try_get_pos (size_t& pos) { if (nullptr == m_archive) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } pos = m_pos_in_file; - return ErrorCode_Success; + return ErrorCode::Success; } ErrorCode LibarchiveFileReader::try_seek_from_begin (size_t pos) { if (nullptr == m_archive) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } - throw OperationFailed(ErrorCode_Unsupported, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Unsupported, __FILENAME__, __LINE__); } ErrorCode LibarchiveFileReader::try_read (char* buf, size_t num_bytes_to_read, size_t& num_bytes_read) { if (nullptr == m_archive) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } if (nullptr == m_archive_entry) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } if (m_reached_eof) { - return ErrorCode_EndOfFile; + return ErrorCode::EndOfFile; } num_bytes_read = 0; @@ -39,9 +39,9 @@ ErrorCode LibarchiveFileReader::try_read (char* buf, size_t num_bytes_to_read, s // Read a data block if necessary if (nullptr == m_data_block) { auto error_code = read_next_data_block(); - if (ErrorCode_Success != error_code) { - if (ErrorCode_EndOfFile == error_code && num_bytes_read > 0) { - return ErrorCode_Success; + if (ErrorCode::Success != error_code) { + if (ErrorCode::EndOfFile == error_code && num_bytes_read > 0) { + return ErrorCode::Success; } return error_code; } @@ -55,7 +55,7 @@ ErrorCode LibarchiveFileReader::try_read (char* buf, size_t num_bytes_to_read, s m_pos_in_file += num_zeros_to_append; if (num_bytes_read == num_bytes_to_read) { - return ErrorCode_Success; + return ErrorCode::Success; } } @@ -76,7 +76,7 @@ ErrorCode LibarchiveFileReader::try_read (char* buf, size_t num_bytes_to_read, s } if (num_bytes_read == num_bytes_to_read) { - return ErrorCode_Success; + return ErrorCode::Success; } } } @@ -84,14 +84,14 @@ ErrorCode LibarchiveFileReader::try_read (char* buf, size_t num_bytes_to_read, s ErrorCode LibarchiveFileReader::try_read_to_delimiter (char delim, bool keep_delimiter, bool append, std::string& str) { if (nullptr == m_archive) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } if (nullptr == m_archive_entry) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } if (m_reached_eof) { - return ErrorCode_EndOfFile; + return ErrorCode::EndOfFile; } if (false == append) { @@ -104,10 +104,10 @@ ErrorCode LibarchiveFileReader::try_read_to_delimiter (char delim, bool keep_del // Read a data block if necessary if (nullptr == m_data_block) { auto error_code = read_next_data_block(); - if (ErrorCode_Success != error_code) { - if (ErrorCode_EndOfFile == error_code && str.length() > original_str_length) { + if (ErrorCode::Success != error_code) { + if (ErrorCode::EndOfFile == error_code && str.length() > original_str_length) { // NOTE: At this point, we haven't found delim, so return directly without breaking to add delim - return ErrorCode_Success; + return ErrorCode::Success; } return error_code; } @@ -164,18 +164,18 @@ ErrorCode LibarchiveFileReader::try_read_to_delimiter (char delim, bool keep_del if (keep_delimiter) { str += delim; } - return ErrorCode_Success; + return ErrorCode::Success; } void LibarchiveFileReader::open (struct archive* archive, struct archive_entry* archive_entry) { if (nullptr == archive) { - throw OperationFailed(ErrorCode_BadParam, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::BadParam, __FILENAME__, __LINE__); } if (nullptr == archive_entry) { - throw OperationFailed(ErrorCode_BadParam, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::BadParam, __FILENAME__, __LINE__); } if (nullptr != m_archive) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } m_archive = archive; @@ -184,7 +184,7 @@ void LibarchiveFileReader::open (struct archive* archive, struct archive_entry* void LibarchiveFileReader::close () { if (nullptr == m_archive) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } m_archive = nullptr; @@ -202,14 +202,14 @@ ErrorCode LibarchiveFileReader::read_next_data_block () { if (ARCHIVE_EOF == return_value) { m_reached_eof = true; m_data_block = nullptr; - return ErrorCode_EndOfFile; + return ErrorCode::EndOfFile; } else { SPDLOG_DEBUG("Failed to read data block from libarchive - {}", archive_error_string(m_archive)); - return ErrorCode_Failure; + return ErrorCode::Failure; } } m_pos_in_data_block = 0; - return ErrorCode_Success; + return ErrorCode::Success; } diff --git a/components/core/src/LibarchiveFileReader.hpp b/components/core/src/LibarchiveFileReader.hpp index 97b4f24737..83b2794c54 100644 --- a/components/core/src/LibarchiveFileReader.hpp +++ b/components/core/src/LibarchiveFileReader.hpp @@ -36,7 +36,7 @@ class LibarchiveFileReader : public ReaderInterface { /** * Tries to get the current position of the read head in the file * @param pos Position of the read head in the file - * @return ErrorCode_Success + * @return ErrorCode::Success */ ErrorCode try_get_pos (size_t &pos) override; /** @@ -50,9 +50,9 @@ class LibarchiveFileReader : public ReaderInterface { * @param buf * @param num_bytes_to_read The number of bytes to try and read * @param num_bytes_read The actual number of bytes read - * @return ErrorCode_EndOfFile on EOF - * @return ErrorCode_Failure on failure - * @return ErrorCode_Success on success + * @return ErrorCode::EndOfFile on EOF + * @return ErrorCode::Failure on failure + * @return ErrorCode::Success on success */ ErrorCode try_read (char *buf, size_t num_bytes_to_read, size_t &num_bytes_read) override; @@ -63,9 +63,9 @@ class LibarchiveFileReader : public ReaderInterface { * @param keep_delimiter Whether to include the delimiter in the output string or not * @param append Whether to append to the given string or replace its contents * @param str The string read - * @return ErrorCode_EndOfFile on EOF - * @return ErrorCode_Failure on failure - * @return ErrorCode_Success on success + * @return ErrorCode::EndOfFile on EOF + * @return ErrorCode::Failure on failure + * @return ErrorCode::Success on success */ ErrorCode try_read_to_delimiter (char delim, bool keep_delimiter, bool append, std::string& str) override; @@ -85,9 +85,9 @@ class LibarchiveFileReader : public ReaderInterface { // Methods /** * Reads next data block from the archive - * @return ErrorCode_EndOfFile on EOF - * @return ErrorCode_Failure on failure - * @return ErrorCode_Success on success + * @return ErrorCode::EndOfFile on EOF + * @return ErrorCode::Failure on failure + * @return ErrorCode::Success on success */ ErrorCode read_next_data_block (); diff --git a/components/core/src/LibarchiveReader.cpp b/components/core/src/LibarchiveReader.cpp index 1808210308..af44e5b611 100644 --- a/components/core/src/LibarchiveReader.cpp +++ b/components/core/src/LibarchiveReader.cpp @@ -13,25 +13,25 @@ ErrorCode LibarchiveReader::try_open (size_t buffer_length, const char* buffer, // Create and initialize internal libarchive m_archive = archive_read_new(); if (nullptr == m_archive) { - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } auto return_value = archive_read_support_filter_all(m_archive); if (ARCHIVE_OK != return_value) { SPDLOG_DEBUG("Failed to enable all filters for libarchive - {}", archive_error_string(m_archive)); - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } // NOTE: We rely on libarchive trying to interpret the archive as raw last (since that's our intent as well) return_value = archive_read_support_format_all(m_archive); if (ARCHIVE_OK != return_value) { SPDLOG_DEBUG("Failed to enable all formats for libarchive - {}", archive_error_string(m_archive)); - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } return_value = archive_read_support_format_raw(m_archive); if (ARCHIVE_OK != return_value) { SPDLOG_DEBUG("Failed to enable raw format for libarchive - {}", archive_error_string(m_archive)); - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } // Copy initial buffer content @@ -49,15 +49,15 @@ ErrorCode LibarchiveReader::try_open (size_t buffer_length, const char* buffer, if (ARCHIVE_OK != return_value) { SPDLOG_DEBUG("Failed to open libarchive - {}", archive_error_string(m_archive)); release_resources(); - return ErrorCode_Failure; + return ErrorCode::Failure; } - return ErrorCode_Success; + return ErrorCode::Success; } void LibarchiveReader::close () { if (nullptr == m_archive) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } auto return_value = archive_read_close(m_archive); @@ -70,27 +70,27 @@ void LibarchiveReader::close () { ErrorCode LibarchiveReader::try_read_next_header () { if (nullptr == m_archive) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } auto return_value = archive_read_next_header(m_archive, &m_archive_entry); if (ARCHIVE_OK != return_value) { if (ARCHIVE_EOF == return_value) { - return ErrorCode_EndOfFile; + return ErrorCode::EndOfFile; } SPDLOG_DEBUG("Failed to read libarchive header - {}", archive_error_string(m_archive)); - return ErrorCode_Failure; + return ErrorCode::Failure; } - return ErrorCode_Success; + return ErrorCode::Success; } void LibarchiveReader::open_file_reader (LibarchiveFileReader& libarchive_file_reader) { if (nullptr == m_archive) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } if (get_entry_file_type() != AE_IFREG) { - throw OperationFailed(ErrorCode_BadParam, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::BadParam, __FILENAME__, __LINE__); } libarchive_file_reader.open(m_archive, m_archive_entry); @@ -98,7 +98,7 @@ void LibarchiveReader::open_file_reader (LibarchiveFileReader& libarchive_file_r mode_t LibarchiveReader::get_entry_file_type () const { if (nullptr == m_archive_entry) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } return archive_entry_filetype(m_archive_entry); @@ -106,7 +106,7 @@ mode_t LibarchiveReader::get_entry_file_type () const { const char* LibarchiveReader::get_path () const { if (nullptr == m_archive_entry) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } if (ARCHIVE_FORMAT_RAW == archive_format(m_archive)) { @@ -137,18 +137,18 @@ la_ssize_t LibarchiveReader::libarchive_read_callback (struct archive* archive, size_t num_bytes_read = 0; auto error_code = libarchive_reader.libarchive_read_callback(buffer, num_bytes_read); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { switch (error_code) { - case ErrorCode_NotInit: + case ErrorCode::NotInit: archive_set_error(archive, EINVAL, "Underlying file is not open."); return -1; - case ErrorCode_BadParam: + case ErrorCode::BadParam: archive_set_error(archive, ENOMEM, "Unknown error."); return -1; - case ErrorCode_errno: + case ErrorCode::Errno: archive_set_error(archive, errno, "%s", strerror(errno)); return -1; - case ErrorCode_EndOfFile: + case ErrorCode::EndOfFile: return 0; default: archive_set_error(archive, ENOENT, "Unhandled error code."); @@ -164,8 +164,8 @@ la_int64_t LibarchiveReader::libarchive_skip_callback (struct archive* archive, size_t num_bytes_skipped; auto error_code = libarchive_reader.libarchive_skip_callback(request, num_bytes_skipped); - if (ErrorCode_Success != error_code) { - if (ErrorCode_errno == error_code) { + if (ErrorCode::Success != error_code) { + if (ErrorCode::Errno == error_code) { archive_set_error(archive, errno, "Failed to skip."); } return ARCHIVE_FATAL; @@ -184,7 +184,7 @@ void LibarchiveReader::libarchive_close_callback () { ErrorCode LibarchiveReader::libarchive_read_callback (const void** buffer, size_t& num_bytes_read) { if (false == m_is_opened_by_libarchive) { - return ErrorCode_NotInit; + return ErrorCode::NotInit; } if (false == m_initial_buffer_content_exhausted) { @@ -195,7 +195,7 @@ ErrorCode LibarchiveReader::libarchive_read_callback (const void** buffer, size_ constexpr size_t cTargetBufferLength = 4096; m_buffer.resize(cTargetBufferLength); auto error_code = m_file_reader->try_read(m_buffer.data(), cTargetBufferLength, num_bytes_read); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { return error_code; } if (num_bytes_read < cTargetBufferLength) { @@ -203,14 +203,14 @@ ErrorCode LibarchiveReader::libarchive_read_callback (const void** buffer, size_ } } - return ErrorCode_Success; + return ErrorCode::Success; } ErrorCode LibarchiveReader::libarchive_skip_callback (off_t num_bytes_to_skip, size_t& num_bytes_skipped) { // Get current position size_t pos; auto error_code = m_file_reader->try_get_pos(pos); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { return error_code; } @@ -218,7 +218,7 @@ ErrorCode LibarchiveReader::libarchive_skip_callback (off_t num_bytes_to_skip, s size_t desired_pos = pos + num_bytes_to_skip; struct stat stat_buffer = {}; error_code = m_file_reader->try_fstat(stat_buffer); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { return error_code; } if (desired_pos > stat_buffer.st_size) { @@ -227,13 +227,13 @@ ErrorCode LibarchiveReader::libarchive_skip_callback (off_t num_bytes_to_skip, s // Seek to desired position error_code = m_file_reader->try_seek_from_begin(desired_pos); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { return error_code; } num_bytes_skipped = desired_pos - pos; - return ErrorCode_Success; + return ErrorCode::Success; } void LibarchiveReader::release_resources () { diff --git a/components/core/src/LibarchiveReader.hpp b/components/core/src/LibarchiveReader.hpp index f17f740d69..0a9d6dc093 100644 --- a/components/core/src/LibarchiveReader.hpp +++ b/components/core/src/LibarchiveReader.hpp @@ -48,8 +48,8 @@ class LibarchiveReader { * @param buffer * @param file_reader * @param path_if_compressed_file Path to use if the data is a single compressed file - * @return ErrorCode_Success on success - * @return ErrorCode_Failure on failure + * @return ErrorCode::Success on success + * @return ErrorCode::Failure on failure */ ErrorCode try_open (size_t buffer_length, const char* buffer, FileReader& file_reader, const std::string& path_if_compressed_file); /** @@ -59,9 +59,9 @@ class LibarchiveReader { /** * Tries to read the next entry's header from the archive - * @return ErrorCode_EndOfFile on EOF - * @return ErrorCode_Failure on failure - * @return ErrorCode_Success on success + * @return ErrorCode::EndOfFile on EOF + * @return ErrorCode::Failure on failure + * @return ErrorCode::Success on success */ ErrorCode try_read_next_header (); @@ -134,9 +134,9 @@ class LibarchiveReader { * Reads a chunk of data from the underlying file * @param buffer * @param num_bytes_read - * @return ErrorCode_NotInit if not opened by libarchive + * @return ErrorCode::NotInit if not opened by libarchive * @return Same as FileReader::try_read - * @return ErrorCode_Success on success + * @return ErrorCode::Success on success */ ErrorCode libarchive_read_callback (const void** buffer, size_t& num_bytes_read); /** @@ -146,7 +146,7 @@ class LibarchiveReader { * @return Same as FileReader::try_get_pos * @return Same as FileReader::try_fstat * @return Same as FileReader::try_seek_from_begin - * @return ErrorCode_Success on success + * @return ErrorCode::Success on success */ ErrorCode libarchive_skip_callback (off_t num_bytes_to_skip, size_t& num_bytes_skipped); diff --git a/components/core/src/LogTypeDictionaryEntry.cpp b/components/core/src/LogTypeDictionaryEntry.cpp index e580fe472c..cfaf8794f0 100644 --- a/components/core/src/LogTypeDictionaryEntry.cpp +++ b/components/core/src/LogTypeDictionaryEntry.cpp @@ -61,7 +61,7 @@ size_t LogTypeDictionaryEntry::get_var_length_in_logtype (size_t var_ix) const { return 2; case VarDelim::Length: default: - throw OperationFailed(ErrorCode_BadParam, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::BadParam, __FILENAME__, __LINE__); } } @@ -124,25 +124,25 @@ ErrorCode LogTypeDictionaryEntry::try_read_from_file (streaming_compression::zst ErrorCode error_code; error_code = decompressor.try_read_numeric_value(m_id); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { return error_code; } uint8_t verbosity; error_code = decompressor.try_read_numeric_value(verbosity); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { return error_code; } m_verbosity = (LogVerbosity)verbosity; uint64_t escaped_value_length; error_code = decompressor.try_read_numeric_value(escaped_value_length); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { return error_code; } string escaped_value; error_code = decompressor.try_read_string(escaped_value_length, escaped_value); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { return error_code; } @@ -182,7 +182,7 @@ ErrorCode LogTypeDictionaryEntry::try_read_from_file (streaming_compression::zst void LogTypeDictionaryEntry::read_from_file (streaming_compression::zstd::Decompressor& decompressor) { auto error_code = try_read_from_file(decompressor); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { throw OperationFailed(error_code, __FILENAME__, __LINE__); } } diff --git a/components/core/src/LogTypeDictionaryWriter.cpp b/components/core/src/LogTypeDictionaryWriter.cpp index 1960a1e464..a39c940361 100644 --- a/components/core/src/LogTypeDictionaryWriter.cpp +++ b/components/core/src/LogTypeDictionaryWriter.cpp @@ -10,7 +10,7 @@ bool LogTypeDictionaryWriter::add_entry (LogTypeDictionaryEntry& logtype_entry, const string& value = logtype_entry.get_value(); if (value.empty()) { - throw OperationFailed(ErrorCode_Corrupt, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Corrupt, __FILENAME__, __LINE__); } const auto ix = m_value_to_id.find(value); if (m_value_to_id.end() != ix) { diff --git a/components/core/src/MessageParser.cpp b/components/core/src/MessageParser.cpp index 529e0241d6..1b9559dafe 100644 --- a/components/core/src/MessageParser.cpp +++ b/components/core/src/MessageParser.cpp @@ -46,8 +46,8 @@ bool MessageParser::parse_next_message (bool drain_source, ReaderInterface& read while (true) { // Read message auto error_code = reader.try_read_to_delimiter(cLineDelimiter, true, true, m_line); - if (ErrorCode_Success != error_code) { - if (ErrorCode_EndOfFile != error_code) { + if (ErrorCode::Success != error_code) { + if (ErrorCode::EndOfFile != error_code) { throw OperationFailed(error_code, __FILENAME__, __LINE__); } diff --git a/components/core/src/MySQLDB.cpp b/components/core/src/MySQLDB.cpp index 81adcf4de5..e9850bb609 100644 --- a/components/core/src/MySQLDB.cpp +++ b/components/core/src/MySQLDB.cpp @@ -8,7 +8,7 @@ using std::string; MySQLDB::Iterator::Iterator (MYSQL* m_db_handle) : m_row(nullptr), m_field_lengths(nullptr), m_num_fields(0) { m_query_result = mysql_use_result(m_db_handle); if (nullptr == m_query_result) { - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } fetch_next_row(); @@ -61,10 +61,10 @@ void MySQLDB::Iterator::get_next () { void MySQLDB::Iterator::get_field_as_string (size_t field_ix, string& field_value) { if (nullptr == m_row) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } if (field_ix >= m_num_fields) { - throw OperationFailed(ErrorCode_OutOfBounds, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::OutOfBounds, __FILENAME__, __LINE__); } field_value.assign(m_row[field_ix], m_field_lengths[field_ix]); @@ -87,24 +87,24 @@ MySQLDB::~MySQLDB () { void MySQLDB::open (const string& host, int port, const string& username, const string& password, const string& database) { if (nullptr != m_db_handle) { - throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotReady, __FILENAME__, __LINE__); } m_db_handle = mysql_init(nullptr); if (nullptr == m_db_handle) { - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } auto db_handle = mysql_real_connect(m_db_handle, host.c_str(), username.c_str(), password.c_str(), database.c_str(), port, nullptr, CLIENT_COMPRESS); if (nullptr == db_handle) { SPDLOG_ERROR("MySQLDB: Failed to connect - {}.", mysql_error(m_db_handle)); - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } } void MySQLDB::close () { if (nullptr == m_db_handle) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } mysql_close(m_db_handle); @@ -113,7 +113,7 @@ void MySQLDB::close () { bool MySQLDB::execute_query (const string& sql_query) { if (nullptr == m_db_handle) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } if (0 != mysql_real_query(m_db_handle, sql_query.c_str(), sql_query.length())) { @@ -126,7 +126,7 @@ bool MySQLDB::execute_query (const string& sql_query) { MySQLPreparedStatement MySQLDB::prepare_statement (const char* statement, size_t statement_length) { if (nullptr == m_db_handle) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } auto prepared_statement = MySQLPreparedStatement(m_db_handle); diff --git a/components/core/src/MySQLParamBindings.cpp b/components/core/src/MySQLParamBindings.cpp index d62b778124..6984284df7 100644 --- a/components/core/src/MySQLParamBindings.cpp +++ b/components/core/src/MySQLParamBindings.cpp @@ -23,7 +23,7 @@ void MySQLParamBindings::resize (size_t num_fields) { void MySQLParamBindings::bind_int64 (size_t field_index, int64_t& value) { if (field_index >= m_statement_bindings.size()) { - throw OperationFailed(ErrorCode_OutOfBounds, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::OutOfBounds, __FILENAME__, __LINE__); } auto& binding = m_statement_bindings[field_index]; @@ -34,7 +34,7 @@ void MySQLParamBindings::bind_int64 (size_t field_index, int64_t& value) { void MySQLParamBindings::bind_uint64 (size_t field_index, uint64_t& value) { if (field_index >= m_statement_bindings.size()) { - throw OperationFailed(ErrorCode_OutOfBounds, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::OutOfBounds, __FILENAME__, __LINE__); } auto& binding = m_statement_bindings[field_index]; @@ -46,7 +46,7 @@ void MySQLParamBindings::bind_uint64 (size_t field_index, uint64_t& value) { void MySQLParamBindings::bind_varchar (size_t field_index, const char* value, size_t value_length) { if (field_index >= m_statement_bindings.size()) { - throw OperationFailed(ErrorCode_OutOfBounds, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::OutOfBounds, __FILENAME__, __LINE__); } auto& binding = m_statement_bindings[field_index]; diff --git a/components/core/src/MySQLPreparedStatement.cpp b/components/core/src/MySQLPreparedStatement.cpp index dc43a12c4e..755c9bff34 100644 --- a/components/core/src/MySQLPreparedStatement.cpp +++ b/components/core/src/MySQLPreparedStatement.cpp @@ -12,7 +12,7 @@ MySQLPreparedStatement::MySQLPreparedStatement (MYSQL* db_handle) : m_db_handle( m_statement_handle = mysql_stmt_init(m_db_handle); if (nullptr == m_statement_handle) { SPDLOG_ERROR("MySQLPreparedStatement: Failed to create statement - {}.", mysql_error(m_db_handle)); - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } } @@ -45,12 +45,12 @@ MySQLPreparedStatement::~MySQLPreparedStatement () { void MySQLPreparedStatement::set (const char* statement, size_t statement_length) { if (m_is_set) { - throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotReady, __FILENAME__, __LINE__); } if (0 != mysql_stmt_prepare(m_statement_handle, statement, statement_length)) { SPDLOG_ERROR("MySQLPreparedStatement: Failed to prepare statement - {}. '{:.{}}'", mysql_stmt_error(m_statement_handle), statement, statement_length); - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } m_statement_bindings.resize(mysql_stmt_param_count(m_statement_handle)); m_is_set = true; diff --git a/components/core/src/PageAllocatedVector.hpp b/components/core/src/PageAllocatedVector.hpp index d9e880cc13..f6f391dee4 100644 --- a/components/core/src/PageAllocatedVector.hpp +++ b/components/core/src/PageAllocatedVector.hpp @@ -124,11 +124,11 @@ template PageAllocatedVector::PageAllocatedVector () : m_values(nullptr), m_capacity_in_bytes(0), m_capacity(0), m_size(0) { m_page_size = sysconf(_SC_PAGESIZE); if (-1 == m_page_size) { - throw OperationFailed(ErrorCode_errno, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Errno, __FILENAME__, __LINE__); } if (sizeof(ValueType) > m_page_size) { - throw OperationFailed(ErrorCode_Unsupported, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Unsupported, __FILENAME__, __LINE__); } } @@ -222,12 +222,12 @@ void PageAllocatedVector::increase_capacity (size_t required_capacity // NOTE: Regions with the MAP_SHARED flag cannot be remapped for some reason new_region = mmap(nullptr, new_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (MAP_FAILED == new_region) { - throw OperationFailed(ErrorCode_errno, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Errno, __FILENAME__, __LINE__); } } else { new_region = mremap(m_values, m_capacity_in_bytes, new_size, MREMAP_MAYMOVE); if (MAP_FAILED == new_region) { - throw OperationFailed(ErrorCode_errno, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Errno, __FILENAME__, __LINE__); } } m_values = (ValueType*)new_region; diff --git a/components/core/src/ReaderInterface.cpp b/components/core/src/ReaderInterface.cpp index b4cc9d6f6e..4276585e0b 100644 --- a/components/core/src/ReaderInterface.cpp +++ b/components/core/src/ReaderInterface.cpp @@ -14,9 +14,9 @@ ErrorCode ReaderInterface::try_read_to_delimiter (char delim, bool keep_delimite size_t num_bytes_read; while (true) { auto error_code = try_read(&c, 1, num_bytes_read); - if (ErrorCode_Success != error_code) { - if (ErrorCode_EndOfFile == error_code && str.length() > original_str_length) { - return ErrorCode_Success; + if (ErrorCode::Success != error_code) { + if (ErrorCode::EndOfFile == error_code && str.length() > original_str_length) { + return ErrorCode::Success; } return error_code; } @@ -33,15 +33,15 @@ ErrorCode ReaderInterface::try_read_to_delimiter (char delim, bool keep_delimite str += delim; } - return ErrorCode_Success; + return ErrorCode::Success; } bool ReaderInterface::read (char* buf, size_t num_bytes_to_read, size_t& num_bytes_read) { ErrorCode error_code = try_read(buf, num_bytes_to_read, num_bytes_read); - if (ErrorCode_EndOfFile == error_code) { + if (ErrorCode::EndOfFile == error_code) { return false; } - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { throw OperationFailed(error_code, __FILENAME__, __LINE__); } return true; @@ -49,10 +49,10 @@ bool ReaderInterface::read (char* buf, size_t num_bytes_to_read, size_t& num_byt bool ReaderInterface::read_to_delimiter (char delim, bool keep_delimiter, bool append, string& str) { ErrorCode error_code = try_read_to_delimiter(delim, keep_delimiter, append, str); - if (ErrorCode_EndOfFile == error_code) { + if (ErrorCode::EndOfFile == error_code) { return false; } - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { throw OperationFailed(error_code, __FILENAME__, __LINE__); } @@ -62,22 +62,22 @@ bool ReaderInterface::read_to_delimiter (char delim, bool keep_delimiter, bool a ErrorCode ReaderInterface::try_read_exact_length (char* buf, size_t num_bytes) { size_t num_bytes_read; auto error_code = try_read(buf, num_bytes, num_bytes_read); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { return error_code; } if (num_bytes_read < num_bytes) { - return ErrorCode_Truncated; + return ErrorCode::Truncated; } - return ErrorCode_Success; + return ErrorCode::Success; } bool ReaderInterface::read_exact_length (char* buf, size_t num_bytes, bool eof_possible) { ErrorCode error_code = try_read_exact_length(buf, num_bytes); - if (eof_possible && ErrorCode_EndOfFile == error_code) { + if (eof_possible && ErrorCode::EndOfFile == error_code) { return false; } - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { throw OperationFailed(error_code, __FILENAME__, __LINE__); } return true; @@ -92,10 +92,10 @@ ErrorCode ReaderInterface::try_read_string (const size_t str_length, string& str bool ReaderInterface::read_string (const size_t str_length, string& str, bool eof_possible) { ErrorCode error_code = try_read_string(str_length, str); - if (eof_possible && ErrorCode_EndOfFile == error_code) { + if (eof_possible && ErrorCode::EndOfFile == error_code) { return false; } - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { throw OperationFailed(error_code, __FILENAME__, __LINE__); } return true; @@ -103,7 +103,7 @@ bool ReaderInterface::read_string (const size_t str_length, string& str, bool eo void ReaderInterface::seek_from_begin (size_t pos) { ErrorCode error_code = try_seek_from_begin(pos); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { throw OperationFailed(error_code, __FILENAME__, __LINE__); } } @@ -111,7 +111,7 @@ void ReaderInterface::seek_from_begin (size_t pos) { size_t ReaderInterface::get_pos () { size_t pos; ErrorCode error_code = try_get_pos(pos); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { throw OperationFailed(error_code, __FILENAME__, __LINE__); } diff --git a/components/core/src/ReaderInterface.hpp b/components/core/src/ReaderInterface.hpp index 01eda081ed..a09c3ec7d6 100644 --- a/components/core/src/ReaderInterface.hpp +++ b/components/core/src/ReaderInterface.hpp @@ -36,7 +36,7 @@ class ReaderInterface { * @param keep_delimiter Whether to include the delimiter in the output string or not * @param append Whether to append to the given string or replace its contents * @param str The string read - * @return ErrorCode_Success on success + * @return ErrorCode::Success on success * @return Same as ReaderInterface::try_read otherwise */ virtual ErrorCode try_read_to_delimiter (char delim, bool keep_delimiter, bool append, std::string& str); @@ -67,7 +67,7 @@ class ReaderInterface { * @param buf * @param num_bytes Number of bytes to read * @return Same as the underlying medium's try_read method - * @return ErrorCode_Truncated if 0 < # bytes read < num_bytes + * @return ErrorCode::Truncated if 0 < # bytes read < num_bytes */ ErrorCode try_read_exact_length (char* buf, size_t num_bytes); /** @@ -130,19 +130,19 @@ class ReaderInterface { template ErrorCode ReaderInterface::try_read_numeric_value (ValueType& value) { ErrorCode error_code = try_read_exact_length(reinterpret_cast(&value), sizeof(value)); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { return error_code; } - return ErrorCode_Success; + return ErrorCode::Success; } template bool ReaderInterface::read_numeric_value (ValueType& value, bool eof_possible) { ErrorCode error_code = try_read_numeric_value(value); - if (ErrorCode_EndOfFile == error_code && eof_possible) { + if (ErrorCode::EndOfFile == error_code && eof_possible) { return false; } - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { throw OperationFailed(error_code, __FILENAME__, __LINE__); } return true; diff --git a/components/core/src/SQLiteDB.cpp b/components/core/src/SQLiteDB.cpp index 52ca1e947f..43cea58bf7 100644 --- a/components/core/src/SQLiteDB.cpp +++ b/components/core/src/SQLiteDB.cpp @@ -13,7 +13,7 @@ void SQLiteDB::open (const string& path) { if (SQLITE_OK != return_value) { SPDLOG_ERROR("Failed to open sqlite database {} - {}", path.c_str(), sqlite3_errmsg(m_db_handle)); close(); - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } } @@ -29,7 +29,7 @@ bool SQLiteDB::close () { SQLitePreparedStatement SQLiteDB::prepare_statement (const char* statement, size_t statement_length) { if (nullptr == m_db_handle) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } return {statement, statement_length, m_db_handle}; diff --git a/components/core/src/SQLitePreparedStatement.cpp b/components/core/src/SQLitePreparedStatement.cpp index b77f13c695..f34f0e58fc 100644 --- a/components/core/src/SQLitePreparedStatement.cpp +++ b/components/core/src/SQLitePreparedStatement.cpp @@ -12,7 +12,7 @@ SQLitePreparedStatement::SQLitePreparedStatement (const char* statement, size_t auto return_value = sqlite3_prepare_v2(db_handle, statement, statement_length, &m_statement_handle, nullptr); if (SQLITE_OK != return_value) { SPDLOG_ERROR("SQLitePreparedStatement: Failed to prepare statement '{:.{}}' - {}", statement, statement_length, sqlite3_errmsg(db_handle)); - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } m_db_handle = db_handle; m_row_ready = false; @@ -54,14 +54,14 @@ void SQLitePreparedStatement::bind_int (int parameter_index, int value) { auto return_value = sqlite3_bind_int(m_statement_handle, parameter_index, value); if (SQLITE_OK != return_value) { SPDLOG_ERROR("SQLitePreparedStatement: Failed to bind int to statement - {}", sqlite3_errmsg(m_db_handle)); - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } } void SQLitePreparedStatement::bind_int (const string& parameter_name, int value) { int parameter_index = sqlite3_bind_parameter_index(m_statement_handle, parameter_name.c_str()); if (0 == parameter_index) { - throw OperationFailed(ErrorCode_BadParam, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::BadParam, __FILENAME__, __LINE__); } bind_int(parameter_index, value); @@ -71,14 +71,14 @@ void SQLitePreparedStatement::bind_int64 (int parameter_index, int64_t value) { auto return_value = sqlite3_bind_int64(m_statement_handle, parameter_index, value); if (SQLITE_OK != return_value) { SPDLOG_ERROR("SQLitePreparedStatement: Failed to bind int64 to statement - {}", sqlite3_errmsg(m_db_handle)); - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } } void SQLitePreparedStatement::bind_int64 (const string& parameter_name, int64_t value) { int parameter_index = sqlite3_bind_parameter_index(m_statement_handle, parameter_name.c_str()); if (0 == parameter_index) { - throw OperationFailed(ErrorCode_BadParam, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::BadParam, __FILENAME__, __LINE__); } bind_int64(parameter_index, value); @@ -89,14 +89,14 @@ void SQLitePreparedStatement::bind_text (int parameter_index, const std::string& copy_parameter ? SQLITE_TRANSIENT : SQLITE_STATIC); if (SQLITE_OK != return_value) { SPDLOG_ERROR("SQLitePreparedStatement: Failed to bind text to statement - {}", sqlite3_errmsg(m_db_handle)); - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } } void SQLitePreparedStatement::bind_text (const string& parameter_name, const string& value, bool copy_parameter) { int parameter_index = sqlite3_bind_parameter_index(m_statement_handle, parameter_name.c_str()); if (0 == parameter_index) { - throw OperationFailed(ErrorCode_BadParam, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::BadParam, __FILENAME__, __LINE__); } bind_text(parameter_index, value, copy_parameter); @@ -113,19 +113,19 @@ bool SQLitePreparedStatement::step () { m_row_ready = (SQLITE_ROW == return_value); switch (return_value) { case SQLITE_BUSY: - throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotReady, __FILENAME__, __LINE__); case SQLITE_DONE: return false; case SQLITE_ROW: return true; default: - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } } int SQLitePreparedStatement::column_int (int parameter_index) const { if (false == m_row_ready) { - throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotReady, __FILENAME__, __LINE__); } return sqlite3_column_int(m_statement_handle, parameter_index); @@ -133,11 +133,11 @@ int SQLitePreparedStatement::column_int (int parameter_index) const { int SQLitePreparedStatement::column_int (const string& parameter_name) const { if (false == m_row_ready) { - throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotReady, __FILENAME__, __LINE__); } int parameter_index = sqlite3_bind_parameter_index(m_statement_handle, parameter_name.c_str()); if (0 == parameter_index) { - throw OperationFailed(ErrorCode_BadParam, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::BadParam, __FILENAME__, __LINE__); } return column_int(parameter_index); @@ -145,7 +145,7 @@ int SQLitePreparedStatement::column_int (const string& parameter_name) const { int64_t SQLitePreparedStatement::column_int64 (int parameter_index) const { if (false == m_row_ready) { - throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotReady, __FILENAME__, __LINE__); } return sqlite3_column_int64(m_statement_handle, parameter_index); @@ -153,11 +153,11 @@ int64_t SQLitePreparedStatement::column_int64 (int parameter_index) const { int64_t SQLitePreparedStatement::column_int64 (const string& parameter_name) const { if (false == m_row_ready) { - throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotReady, __FILENAME__, __LINE__); } int parameter_index = sqlite3_bind_parameter_index(m_statement_handle, parameter_name.c_str()); if (0 == parameter_index) { - throw OperationFailed(ErrorCode_BadParam, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::BadParam, __FILENAME__, __LINE__); } return column_int64(parameter_index); @@ -165,7 +165,7 @@ int64_t SQLitePreparedStatement::column_int64 (const string& parameter_name) con void SQLitePreparedStatement::column_string (int parameter_index, std::string& value) const { if (false == m_row_ready) { - throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotReady, __FILENAME__, __LINE__); } value.assign(reinterpret_cast(sqlite3_column_text(m_statement_handle, parameter_index)), @@ -174,11 +174,11 @@ void SQLitePreparedStatement::column_string (int parameter_index, std::string& v void SQLitePreparedStatement::column_string (const std::string& parameter_name, std::string& value) const { if (false == m_row_ready) { - throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotReady, __FILENAME__, __LINE__); } int parameter_index = sqlite3_bind_parameter_index(m_statement_handle, parameter_name.c_str()); if (0 == parameter_index) { - throw OperationFailed(ErrorCode_BadParam, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::BadParam, __FILENAME__, __LINE__); } column_string(parameter_index, value); diff --git a/components/core/src/TimestampPattern.cpp b/components/core/src/TimestampPattern.cpp index c07811660b..b9751f6d94 100644 --- a/components/core/src/TimestampPattern.cpp +++ b/components/core/src/TimestampPattern.cpp @@ -568,7 +568,7 @@ void TimestampPattern::insert_formatted_timestamp (const epochtime_t timestamp, } if (num_spaces_found < m_num_spaces_before_ts) { SPDLOG_ERROR("{} has {} spaces, but pattern has {}", msg.c_str(), num_spaces_found, m_num_spaces_before_ts); - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } // Copy text before timestamp @@ -699,7 +699,7 @@ void TimestampPattern::insert_formatted_timestamp (const epochtime_t timestamp, break; default: { - throw OperationFailed(ErrorCode_Unsupported, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Unsupported, __FILENAME__, __LINE__); } } is_specifier = false; diff --git a/components/core/src/Utils.cpp b/components/core/src/Utils.cpp index 2c44ab0da1..f1daef73c3 100644 --- a/components/core/src/Utils.cpp +++ b/components/core/src/Utils.cpp @@ -169,13 +169,13 @@ ErrorCode create_directory (const string& path, __mode_t mode, bool exist_ok) { int retval = mkdir(path.c_str(), mode); if (0 != retval ) { if (EEXIST != errno) { - return ErrorCode_errno; + return ErrorCode::Errno; } else if (false == exist_ok) { - return ErrorCode_FileExists; + return ErrorCode::FileExists; } } - return ErrorCode_Success; + return ErrorCode::Success; } ErrorCode create_directory_structure (const string& path, __mode_t mode) { @@ -185,10 +185,10 @@ ErrorCode create_directory_structure (const string& path, __mode_t mode) { struct stat s = {}; if (0 == stat(path.c_str(), &s)) { // Deepest directory exists, so can return here - return ErrorCode_Success; + return ErrorCode::Success; } else if (ENOENT != errno) { // Unexpected error - return ErrorCode_errno; + return ErrorCode::Errno; } // Find deepest directory which exists, starting from the (2nd) deepest directory @@ -202,7 +202,7 @@ ErrorCode create_directory_structure (const string& path, __mode_t mode) { break; } else if (ENOENT != errno) { // Unexpected error - return ErrorCode_errno; + return ErrorCode::Errno; } } @@ -220,12 +220,12 @@ ErrorCode create_directory_structure (const string& path, __mode_t mode) { dir_path.assign(path, 0, path_end_pos); // Technically the directory shouldn't exist at this point in the code, but it may have been created concurrently. auto error_code = create_directory(dir_path, mode, true); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { return error_code; } } - return ErrorCode_Success; + return ErrorCode::Success; } size_t find_first_of (const string& haystack, const char* needles, size_t search_start_pos, size_t& needle_ix) { @@ -747,24 +747,24 @@ ErrorCode memory_map_file (const string& path, bool read_ahead, int& fd, size_t& fd = open(path.c_str(), O_RDONLY); if (fd < 0) { SPDLOG_ERROR("Failed to open {}, errno={}", path.c_str(), errno); - return ErrorCode_errno; + return ErrorCode::Errno; } // Check file exists and get size struct stat s = {}; if (0 != fstat(fd, &s)) { if (ENOENT == errno) { - return ErrorCode_FileNotFound; + return ErrorCode::FileNotFound; } SPDLOG_ERROR("Failed to stat {}, errno={}", path.c_str(), errno); - return ErrorCode_errno; + return ErrorCode::Errno; } file_size = s.st_size; if (0 == file_size) { if (0 != close(fd)) { SPDLOG_ERROR("Failed to close empty file - {}, errno={}", path.c_str(), errno); - return ErrorCode_errno; + return ErrorCode::Errno; } } else { int flags = MAP_SHARED; @@ -776,27 +776,27 @@ ErrorCode memory_map_file (const string& path, bool read_ahead, int& fd, size_t& void* mapped_region = mmap(nullptr, file_size, PROT_READ, flags, fd, 0); if (MAP_FAILED == mapped_region) { SPDLOG_ERROR("Failed to mmap {}, errno={}", path.c_str(), errno); - return ErrorCode_errno; + return ErrorCode::Errno; } ptr = mapped_region; } - return ErrorCode_Success; + return ErrorCode::Success; } ErrorCode memory_unmap_file (int fd, size_t file_size, void* ptr) { if (0 != file_size) { if (0 != munmap(ptr, file_size)) { SPDLOG_ERROR("Failed to unmap file, errno={}", errno); - return ErrorCode_errno; + return ErrorCode::Errno; } if (0 != close(fd)) { SPDLOG_ERROR("Failed to close file, errno={}", errno); - return ErrorCode_errno; + return ErrorCode::Errno; } } - return ErrorCode_Success; + return ErrorCode::Success; } @@ -804,7 +804,7 @@ ErrorCode memory_unmap_file (int fd, size_t file_size, void* ptr) { ErrorCode read_list_of_paths (const string& list_path, vector& paths) { FileReader file_reader; ErrorCode error_code = file_reader.try_open(list_path); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { return error_code; } @@ -812,7 +812,7 @@ ErrorCode read_list_of_paths (const string& list_path, vector& paths) { string line; while (true) { error_code = file_reader.try_read_to_delimiter('\n', false, false, line); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { break; } // Only add non-empty paths @@ -821,11 +821,11 @@ ErrorCode read_list_of_paths (const string& list_path, vector& paths) { } } // Check for any unexpected errors - if (ErrorCode_EndOfFile != error_code) { + if (ErrorCode::EndOfFile != error_code) { return error_code; } file_reader.close(); - return ErrorCode_Success; + return ErrorCode::Success; } diff --git a/components/core/src/Utils.hpp b/components/core/src/Utils.hpp index 7f71bfb8fb..19a9586fcf 100644 --- a/components/core/src/Utils.hpp +++ b/components/core/src/Utils.hpp @@ -45,9 +45,9 @@ bool convert_string_to_double (const std::string& raw, double& converted); * @param path * @param mode * @param exist_ok - * @return ErrorCode_Success on success - * @return ErrorCode_errno on error - * @return ErrorCode_FileExists if exist_ok was false and the path already existed + * @return ErrorCode::Success on success + * @return ErrorCode::Errno on error + * @return ErrorCode::FileExists if exist_ok was false and the path already existed */ ErrorCode create_directory (const std::string& path, __mode_t mode, bool exist_ok); @@ -56,7 +56,7 @@ ErrorCode create_directory (const std::string& path, __mode_t mode, bool exist_o * NOTE: We assume the path "/" exists * @param path The path (must be non-empty) * @param mode Permission bits for structure - * @return ErrorCode_Success on success, ErrorCode_errno otherwise + * @return ErrorCode::Success on success, ErrorCode::Errno otherwise */ ErrorCode create_directory_structure (const std::string& path, __mode_t mode); @@ -153,9 +153,9 @@ bool wildCardMatch ( * @param fd Reference to file descriptor opened for file * @param file_size Reference to file size determined for file * @param ptr Reference to pointer to mapped region - * @return ErrorCode_errno on error - * @return ErrorCode_FileNotFound if file not found - * @return ErrorCode_Success on success + * @return ErrorCode::Errno on error + * @return ErrorCode::FileNotFound if file not found + * @return ErrorCode::Success on success */ ErrorCode memory_map_file (const std::string& path, bool read_ahead, int& fd, size_t& file_size, void*& ptr); @@ -164,8 +164,8 @@ ErrorCode memory_map_file (const std::string& path, bool read_ahead, int& fd, si * @param fd File's file descriptor * @param file_size File's size * @param ptr Pointer to mapped region - * @return ErrorCode_errno on error - * @return ErrorCode_Success on success + * @return ErrorCode::Errno on error + * @return ErrorCode::Success on success */ ErrorCode memory_unmap_file (int fd, size_t file_size, void* ptr); @@ -173,7 +173,7 @@ ErrorCode memory_unmap_file (int fd, size_t file_size, void* ptr); * Read a list of paths from a file * @param list_path * @param paths - * @return ErrorCode_Success on success + * @return ErrorCode::Success on success * @return Otherwise, same as FileReader::try_open and FileReader::try_read_to_delimiter */ ErrorCode read_list_of_paths (const std::string& list_path, std::vector& paths); diff --git a/components/core/src/VariableDictionaryEntry.cpp b/components/core/src/VariableDictionaryEntry.cpp index 1758931b51..ab7975b578 100644 --- a/components/core/src/VariableDictionaryEntry.cpp +++ b/components/core/src/VariableDictionaryEntry.cpp @@ -14,17 +14,17 @@ ErrorCode VariableDictionaryEntry::try_read_from_file (streaming_compression::zs ErrorCode error_code; error_code = decompressor.try_read_numeric_value(m_id); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { return error_code; } uint64_t value_length; error_code = decompressor.try_read_numeric_value(value_length); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { return error_code; } error_code = decompressor.try_read_string(value_length, m_value); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { return error_code; } @@ -33,7 +33,7 @@ ErrorCode VariableDictionaryEntry::try_read_from_file (streaming_compression::zs void VariableDictionaryEntry::read_from_file (streaming_compression::zstd::Decompressor& decompressor) { auto error_code = try_read_from_file(decompressor); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { throw OperationFailed(error_code, __FILENAME__, __LINE__); } } diff --git a/components/core/src/VariableDictionaryWriter.cpp b/components/core/src/VariableDictionaryWriter.cpp index 227260f03d..a3a2097719 100644 --- a/components/core/src/VariableDictionaryWriter.cpp +++ b/components/core/src/VariableDictionaryWriter.cpp @@ -17,7 +17,7 @@ bool VariableDictionaryWriter::add_entry (const std::string& value, variable_dic if (m_next_id > m_max_id) { SPDLOG_ERROR("VariableDictionaryWriter ran out of IDs."); - throw OperationFailed(ErrorCode_OutOfBounds, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::OutOfBounds, __FILENAME__, __LINE__); } // Assign ID diff --git a/components/core/src/Writer.cpp b/components/core/src/Writer.cpp index d9d81bcad7..859471a909 100644 --- a/components/core/src/Writer.cpp +++ b/components/core/src/Writer.cpp @@ -8,18 +8,18 @@ ErrorCode Writer::try_write (int fd, const unsigned char* buf, size_t buf_len) { if (fd < 0 || nullptr == buf) { - return ErrorCode_BadParam; + return ErrorCode::BadParam; } while (buf_len > 0) { ssize_t num_bytes_sent = ::write(fd, buf, buf_len); if (-1 == num_bytes_sent) { - return ErrorCode_errno; + return ErrorCode::Errno; } buf_len -= num_bytes_sent; } - return ErrorCode_Success; + return ErrorCode::Success; } ErrorCode Writer::try_write_packet (int fd, PacketEncoder& packet_encoder) { @@ -28,7 +28,7 @@ ErrorCode Writer::try_write_packet (int fd, PacketEncoder& packet_encoder) { void Writer::write_packet(int fd, PacketEncoder &packet_encoder) { ErrorCode error_code = try_write_packet(fd, packet_encoder); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { throw OperationFailed(error_code, __FILENAME__, __LINE__); } } diff --git a/components/core/src/Writer.hpp b/components/core/src/Writer.hpp index 082fa54329..f57b303992 100644 --- a/components/core/src/Writer.hpp +++ b/components/core/src/Writer.hpp @@ -29,9 +29,9 @@ class Writer { * @param fd * @param buf * @param buf_len Length of the buffer - * @return ErrorCode_BadParam if file descriptor or buffer pointer are invalid - * @return ErrorCode_errno if write failed - * @return ErrorCode_Success otherwise + * @return ErrorCode::BadParam if file descriptor or buffer pointer are invalid + * @return ErrorCode::Errno if write failed + * @return ErrorCode::Success otherwise */ static ErrorCode try_write (int fd, const unsigned char* buf, size_t buf_len); diff --git a/components/core/src/WriterInterface.cpp b/components/core/src/WriterInterface.cpp index 6eebe57e17..327e6b8b44 100644 --- a/components/core/src/WriterInterface.cpp +++ b/components/core/src/WriterInterface.cpp @@ -13,14 +13,14 @@ void WriterInterface::write_string (const std::string& str) { void WriterInterface::seek_from_begin (size_t pos) { auto error_code = try_seek_from_begin(pos); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { throw OperationFailed(error_code, __FILENAME__, __LINE__); } } void WriterInterface::seek_from_current (off_t offset) { auto error_code = try_seek_from_current(offset); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { throw OperationFailed(error_code, __FILENAME__, __LINE__); } } @@ -28,7 +28,7 @@ void WriterInterface::seek_from_current (off_t offset) { size_t WriterInterface::get_pos () const { size_t pos; ErrorCode error_code = try_get_pos(pos); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { throw OperationFailed(error_code, __FILENAME__, __LINE__); } diff --git a/components/core/src/clg/clg.cpp b/components/core/src/clg/clg.cpp index 89b3cac7e2..407451d316 100644 --- a/components/core/src/clg/clg.cpp +++ b/components/core/src/clg/clg.cpp @@ -107,7 +107,7 @@ static bool open_archive (const string& archive_path, Archive& archive_reader) { archive_reader.open(archive_path); } catch (TraceableException& e) { error_code = e.get_error_code(); - if (ErrorCode_errno == error_code) { + if (ErrorCode::Errno == error_code) { SPDLOG_ERROR("Opening archive failed: {}:{} {}, errno={}", e.get_filename(), e.get_line_number(), e.what(), errno); return false; } else { @@ -120,7 +120,7 @@ static bool open_archive (const string& archive_path, Archive& archive_reader) { archive_reader.refresh_dictionaries(); } catch (TraceableException& e) { error_code = e.get_error_code(); - if (ErrorCode_errno == error_code) { + if (ErrorCode::Errno == error_code) { SPDLOG_ERROR("Reading dictionaries failed: {}:{} {}, errno={}", e.get_filename(), e.get_line_number(), e.what(), errno); return false; } else { @@ -186,7 +186,7 @@ static bool search (const vector& search_strings, CommandLineArguments& } } catch (TraceableException& e) { error_code = e.get_error_code(); - if (ErrorCode_errno == error_code) { + if (ErrorCode::Errno == error_code) { SPDLOG_ERROR("Search failed: {}:{} {}, errno={}", e.get_filename(), e.get_line_number(), e.what(), errno); return false; } else { @@ -200,14 +200,14 @@ static bool search (const vector& search_strings, CommandLineArguments& static bool open_compressed_file (MetadataDB::FileIterator& file_metadata_ix, Archive& archive, File& compressed_file) { ErrorCode error_code = archive.open_file(compressed_file, file_metadata_ix, false); - if (ErrorCode_Success == error_code) { + if (ErrorCode::Success == error_code) { return true; } string orig_path; file_metadata_ix.get_path(orig_path); - if (ErrorCode_FileNotFound == error_code) { + if (ErrorCode::FileNotFound == error_code) { SPDLOG_WARN("{} not found in archive", orig_path.c_str()); - } else if (ErrorCode_errno == error_code) { + } else if (ErrorCode::Errno == error_code) { SPDLOG_ERROR("Failed to open {}, errno={}", orig_path.c_str(), errno); } else { SPDLOG_ERROR("Failed to open {}, error={}", orig_path.c_str(), error_code); diff --git a/components/core/src/clo/clo.cpp b/components/core/src/clo/clo.cpp index 7cd0ba68f9..4d24888de3 100644 --- a/components/core/src/clo/clo.cpp +++ b/components/core/src/clo/clo.cpp @@ -114,10 +114,10 @@ static bool search_files (Query& query, Archive& archive, MetadataDB::FileIterat // Run query on each file for (; file_metadata_ix.has_next(); file_metadata_ix.next()) { ErrorCode error_code = archive.open_file(compressed_file, file_metadata_ix, false); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { string orig_path; file_metadata_ix.get_path(orig_path); - if (ErrorCode_errno == error_code) { + if (ErrorCode::Errno == error_code) { SPDLOG_ERROR("Failed to open {}, errno={}", orig_path.c_str(), errno); } else { SPDLOG_ERROR("Failed to open {}, error={}", orig_path.c_str(), error_code); @@ -223,7 +223,7 @@ int main (int argc, const char* argv[]) { } } catch (TraceableException& e) { auto error_code = e.get_error_code(); - if (ErrorCode_errno == error_code) { + if (ErrorCode::Errno == error_code) { SPDLOG_ERROR("Search failed: {}:{} {}, errno={}", e.get_filename(), e.get_line_number(), e.what(), errno); return -1; } else { diff --git a/components/core/src/clp/FileCompressor.cpp b/components/core/src/clp/FileCompressor.cpp index e5c7349bff..5cf7b8fd37 100644 --- a/components/core/src/clp/FileCompressor.cpp +++ b/components/core/src/clp/FileCompressor.cpp @@ -86,8 +86,8 @@ namespace clp { // Check that file is UTF-8 encoded auto error_code = m_file_reader.try_read(m_utf8_validation_buf, cUtf8ValidationBufCapacity, m_utf8_validation_buf_length); - if (ErrorCode_Success != error_code) { - if (ErrorCode_EndOfFile != error_code) { + if (ErrorCode::Success != error_code) { + if (ErrorCode::EndOfFile != error_code) { SPDLOG_ERROR("Failed to read {}, errno={}", file_to_compress.get_path().c_str(), errno); return false; } @@ -162,7 +162,7 @@ namespace clp { // Check if it's an archive auto error_code = m_libarchive_reader.try_open(m_utf8_validation_buf_length, m_utf8_validation_buf, m_file_reader, filename_if_compressed); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { SPDLOG_ERROR("Cannot compress {} - not UTF-8 encoded.", file_to_compress.get_path().c_str()); return false; } @@ -173,8 +173,8 @@ namespace clp { set parent_directories; while (true) { error_code = m_libarchive_reader.try_read_next_header(); - if (ErrorCode_Success != error_code) { - if (ErrorCode_EndOfFile == error_code) { + if (ErrorCode::Success != error_code) { + if (ErrorCode::EndOfFile == error_code) { break; } SPDLOG_ERROR("Failed to read entry in {}.", file_to_compress.get_path().c_str()); @@ -212,8 +212,8 @@ namespace clp { // Check that file is UTF-8 encoded error_code = m_libarchive_file_reader.try_read(m_utf8_validation_buf, cUtf8ValidationBufCapacity, m_utf8_validation_buf_length); - if (ErrorCode_Success != error_code) { - if (ErrorCode_EndOfFile != error_code) { + if (ErrorCode::Success != error_code) { + if (ErrorCode::EndOfFile != error_code) { SPDLOG_ERROR("Failed to read {} from {}.", m_libarchive_reader.get_path(), file_to_compress.get_path().c_str()); m_libarchive_file_reader.close(); succeeded = false; diff --git a/components/core/src/clp/FileDecompressor.cpp b/components/core/src/clp/FileDecompressor.cpp index 82b01db2dc..e345a3b7fb 100644 --- a/components/core/src/clp/FileDecompressor.cpp +++ b/components/core/src/clp/FileDecompressor.cpp @@ -15,8 +15,8 @@ namespace clp { { // Open compressed file auto error_code = archive_reader.open_file(m_encoded_file, file_metadata_ix, true); - if (ErrorCode_Success != error_code) { - if (ErrorCode_errno == error_code) { + if (ErrorCode::Success != error_code) { + if (ErrorCode::Errno == error_code) { SPDLOG_ERROR("Failed to open encoded file, errno={}", errno); } else { SPDLOG_ERROR("Failed to open encoded file, error_code={}", error_code); @@ -44,7 +44,7 @@ namespace clp { // Generate output directory error_code = create_directory_structure(final_output_path.parent_path().string(), 0700); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { SPDLOG_ERROR("Failed to create directory structure {}, errno={}", final_output_path.parent_path().c_str(), errno); return false; } diff --git a/components/core/src/clp/clp.cpp b/components/core/src/clp/clp.cpp index 416b97ed90..2db1777374 100644 --- a/components/core/src/clp/clp.cpp +++ b/components/core/src/clp/clp.cpp @@ -86,7 +86,7 @@ int main (int argc, const char* argv[]) { command_line_args.get_target_encoded_file_size()); } catch (TraceableException& e) { ErrorCode error_code = e.get_error_code(); - if (ErrorCode_errno == error_code) { + if (ErrorCode::Errno == error_code) { SPDLOG_ERROR("Compression failed: {}:{} {}, errno={}", e.get_filename(), e.get_line_number(), e.what(), errno); compression_successful = false; } else { diff --git a/components/core/src/clp/compression.cpp b/components/core/src/clp/compression.cpp index ddd217168a..4400b26aa6 100644 --- a/components/core/src/clp/compression.cpp +++ b/components/core/src/clp/compression.cpp @@ -60,7 +60,7 @@ namespace clp { // Create output directory in case it doesn't exist auto error_code = create_directory(output_dir.parent_path().string(), 0700, true); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { SPDLOG_ERROR("Failed to create {} - {}", output_dir.parent_path().c_str(), strerror(errno)); return false; } @@ -156,10 +156,10 @@ namespace clp { { FileReader grouped_file_path_reader; ErrorCode error_code = grouped_file_path_reader.try_open(list_path); - if (ErrorCode_Success != error_code) { - if (ErrorCode_FileNotFound == error_code) { + if (ErrorCode::Success != error_code) { + if (ErrorCode::FileNotFound == error_code) { SPDLOG_ERROR("'{}' does not exist.", list_path.c_str()); - } else if (ErrorCode_errno == error_code) { + } else if (ErrorCode::Errno == error_code) { SPDLOG_ERROR("Failed to read '{}', errno={}", list_path.c_str(), errno); } else { SPDLOG_ERROR("Failed to read '{}', error_code={}", list_path.c_str(), error_code); @@ -170,10 +170,10 @@ namespace clp { FileReader grouped_file_id_reader; string grouped_file_ids_path = list_path.substr(0, list_path.length() - 4) + ".gid"; error_code = grouped_file_id_reader.try_open(grouped_file_ids_path); - if (ErrorCode_Success != error_code) { - if (ErrorCode_FileNotFound == error_code) { + if (ErrorCode::Success != error_code) { + if (ErrorCode::FileNotFound == error_code) { SPDLOG_ERROR("'{}' does not exist.", grouped_file_ids_path.c_str()); - } else if (ErrorCode_errno == error_code) { + } else if (ErrorCode::Errno == error_code) { SPDLOG_ERROR("Failed to read '{}', errno={}", grouped_file_ids_path.c_str(), errno); } else { SPDLOG_ERROR("Failed to read '{}', error_code={}", grouped_file_ids_path.c_str(), error_code); @@ -189,7 +189,7 @@ namespace clp { while (true) { // Read path error_code = grouped_file_path_reader.try_read_to_delimiter('\n', false, false, path); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { break; } // Validate path is not empty @@ -201,8 +201,8 @@ namespace clp { // Read group ID error_code = grouped_file_id_reader.try_read_numeric_value(group_id); - if (ErrorCode_Success != error_code) { - if (ErrorCode_EndOfFile == error_code) { + if (ErrorCode::Success != error_code) { + if (ErrorCode::EndOfFile == error_code) { SPDLOG_ERROR("There are more grouped file paths than IDs."); return false; } @@ -234,8 +234,8 @@ namespace clp { grouped_files.emplace_back(path, path_without_prefix, group_id); } // Check for any unexpected errors - if (ErrorCode_EndOfFile != error_code) { - if (ErrorCode_errno == error_code) { + if (ErrorCode::EndOfFile != error_code) { + if (ErrorCode::Errno == error_code) { SPDLOG_ERROR("Failed to read grouped file paths or IDs, errno={}", errno); } else { SPDLOG_ERROR("Failed to read grouped file paths or IDs, error_code={}", error_code); diff --git a/components/core/src/clp/decompression.cpp b/components/core/src/clp/decompression.cpp index e73c592da6..3579445bdc 100644 --- a/components/core/src/clp/decompression.cpp +++ b/components/core/src/clp/decompression.cpp @@ -33,7 +33,7 @@ namespace clp { // Create output directory in case it doesn't exist auto output_dir = boost::filesystem::path(command_line_args.get_output_dir()); error_code = create_directory(output_dir.parent_path().string(), 0700, true); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { SPDLOG_ERROR("Failed to create {} - {}", output_dir.parent_path().c_str(), strerror(errno)); return false; } @@ -187,7 +187,7 @@ namespace clp { } } catch (TraceableException& e) { error_code = e.get_error_code(); - if (ErrorCode_errno == error_code) { + if (ErrorCode::Errno == error_code) { SPDLOG_ERROR("Decompression failed: {}:{} {}, errno={}", e.get_filename(), e.get_line_number(), e.what(), errno); return false; } else { diff --git a/components/core/src/clp/utils.cpp b/components/core/src/clp/utils.cpp index b0fb883e9d..1c1a121e40 100644 --- a/components/core/src/clp/utils.cpp +++ b/components/core/src/clp/utils.cpp @@ -100,10 +100,10 @@ namespace clp { bool read_input_paths (const string& list_path, vector& paths) { ErrorCode error_code = read_list_of_paths(list_path, paths); - if (ErrorCode_Success != error_code) { - if (ErrorCode_FileNotFound == error_code) { + if (ErrorCode::Success != error_code) { + if (ErrorCode::FileNotFound == error_code) { SPDLOG_ERROR("'{}' does not exist.", list_path.c_str()); - } else if (ErrorCode_errno == error_code) { + } else if (ErrorCode::Errno == error_code) { SPDLOG_ERROR("Failed to read '{}', errno={}", list_path.c_str(), errno); } else { SPDLOG_ERROR("Failed to read '{}', error_code={}", list_path.c_str(), error_code); diff --git a/components/core/src/streaming_archive/MetadataDB.cpp b/components/core/src/streaming_archive/MetadataDB.cpp index d1fa06e26d..bd6090d26b 100644 --- a/components/core/src/streaming_archive/MetadataDB.cpp +++ b/components/core/src/streaming_archive/MetadataDB.cpp @@ -258,7 +258,7 @@ namespace streaming_archive { void MetadataDB::open (const string& path) { if (m_is_open) { - throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotReady, __FILENAME__, __LINE__); } m_db.open(path); @@ -345,7 +345,7 @@ namespace streaming_archive { m_insert_empty_directories_statement.reset(nullptr); if (false == m_db.close()) { SPDLOG_ERROR("streaming_archive::MetadataDB: Failed to close database - {}", m_db.get_error_message()); - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } m_is_open = false; } diff --git a/components/core/src/streaming_archive/reader/Archive.cpp b/components/core/src/streaming_archive/reader/Archive.cpp index 8f79b6ed82..cf90aa969a 100644 --- a/components/core/src/streaming_archive/reader/Archive.cpp +++ b/components/core/src/streaming_archive/reader/Archive.cpp @@ -41,11 +41,11 @@ namespace streaming_archive { namespace reader { const char* path_c_str = path.c_str(); if (0 != stat(path_c_str, &path_stat)) { SPDLOG_ERROR("Failed to stat {}, errno={}", path_c_str, errno); - throw OperationFailed(ErrorCode_errno, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Errno, __FILENAME__, __LINE__); } if (!S_ISDIR(path_stat.st_mode)) { SPDLOG_ERROR("{} is not a directory", path_c_str); - throw OperationFailed(ErrorCode_Unsupported, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Unsupported, __FILENAME__, __LINE__); } m_path = path; @@ -58,7 +58,7 @@ namespace streaming_archive { namespace reader { read_metadata_file(metadata_file_path, format_version, stable_uncompressed_size, stable_size); } catch (TraceableException& traceable_exception) { auto error_code = traceable_exception.get_error_code(); - if (ErrorCode_errno == error_code) { + if (ErrorCode::Errno == error_code) { SPDLOG_CRITICAL("streaming_archive::reader::Archive: Failed to read archive metadata file {} at {}:{} - errno={}", metadata_file_path.c_str(), traceable_exception.get_filename(), traceable_exception.get_line_number(), errno); } else { @@ -71,7 +71,7 @@ namespace streaming_archive { namespace reader { // Check archive matches format version if (cArchiveFormatVersion != format_version) { SPDLOG_ERROR("streaming_archive::reader::Archive: Archive uses an unsupported format."); - throw OperationFailed(ErrorCode_BadParam, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::BadParam, __FILENAME__, __LINE__); } auto metadata_db_path = boost::filesystem::path(path) / cMetadataDBFileName; @@ -205,7 +205,7 @@ namespace streaming_archive { namespace reader { ix.get_path(path); auto empty_directory_path = output_dir_path / path; auto error_code = create_directory_structure(empty_directory_path.string(), 0700); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { SPDLOG_ERROR("Failed to create directory structure {}, errno={}", empty_directory_path.string().c_str(), errno); throw OperationFailed(error_code, __FILENAME__, __LINE__); } diff --git a/components/core/src/streaming_archive/reader/File.cpp b/components/core/src/streaming_archive/reader/File.cpp index d32f0ceb9d..310c28c0d7 100644 --- a/components/core/src/streaming_archive/reader/File.cpp +++ b/components/core/src/streaming_archive/reader/File.cpp @@ -58,7 +58,7 @@ namespace streaming_archive { namespace reader { end_pos = encoded_timestamp_patterns.find_first_of(':', begin_pos); if (string::npos == end_pos) { // Unexpected truncation - throw OperationFailed(ErrorCode_Corrupt, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Corrupt, __FILENAME__, __LINE__); } uint8_t num_spaces_before_ts = strtol(&encoded_timestamp_patterns[begin_pos], nullptr, 10); begin_pos = end_pos + 1; @@ -66,7 +66,7 @@ namespace streaming_archive { namespace reader { end_pos = encoded_timestamp_patterns.find_first_of('\n', begin_pos); if (string::npos == end_pos) { // Unexpected truncation - throw OperationFailed(ErrorCode_Corrupt, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Corrupt, __FILENAME__, __LINE__); } timestamp_format.assign(encoded_timestamp_patterns, begin_pos, end_pos - begin_pos); begin_pos = end_pos + 1; @@ -113,7 +113,7 @@ namespace streaming_archive { namespace reader { error_code = segment_manager.try_read(m_segment_id, m_segment_timestamps_decompressed_stream_pos, reinterpret_cast(m_segment_timestamps.get()), num_bytes_to_read); PROFILER_STOP_STOPWATCH(segment_read_stopwatch) - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { close_me(); return error_code; } @@ -124,7 +124,7 @@ namespace streaming_archive { namespace reader { error_code = segment_manager.try_read(m_segment_id, m_segment_logtypes_decompressed_stream_pos, reinterpret_cast(m_segment_logtypes.get()), num_bytes_to_read); PROFILER_STOP_STOPWATCH(segment_read_stopwatch) - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { close_me(); return error_code; } @@ -144,7 +144,7 @@ namespace streaming_archive { namespace reader { error_code = segment_manager.try_read(m_segment_id, m_segment_variables_decompressed_stream_pos, reinterpret_cast(m_segment_variables.get()), num_bytes_to_read); PROFILER_STOP_STOPWATCH(segment_read_stopwatch) - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { close_me(); return error_code; } @@ -162,7 +162,7 @@ namespace streaming_archive { namespace reader { column_path = file_path; column_path += cTimestampsFileExtension; error_code = memory_map_file(column_path, read_ahead, m_timestamps_fd, m_timestamps_file_size, ptr); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { close_me(); return error_code; } @@ -171,14 +171,14 @@ namespace streaming_archive { namespace reader { if (num_timestamps_read < m_num_messages) { SPDLOG_ERROR("There are fewer timestamps on disk ({}) than the metadata ({}) indicates.", num_timestamps_read, m_num_messages); close_me(); - return ErrorCode_Truncated; + return ErrorCode::Truncated; } // Open logtype IDs file column_path = file_path; column_path += cLogTypeIdsFileExtension; error_code = memory_map_file(column_path, read_ahead, m_logtypes_fd, m_logtypes_file_size, ptr); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { close_me(); return error_code; } @@ -187,14 +187,14 @@ namespace streaming_archive { namespace reader { if (num_logtypes_read < m_num_messages) { SPDLOG_ERROR("There are fewer logtypes on disk ({}) than the metadata ({}) indicates.", num_logtypes_read, m_num_messages); close_me(); - return ErrorCode_Truncated; + return ErrorCode::Truncated; } // Open variables file column_path = file_path; column_path += cVariablesFileExtension; error_code = memory_map_file(column_path, read_ahead, m_variables_fd, m_variables_file_size, ptr); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { close_me(); return error_code; } @@ -203,7 +203,7 @@ namespace streaming_archive { namespace reader { if (num_variables_read < m_num_variables) { SPDLOG_ERROR("There are fewer variables on disk ({}) than the metadata ({}) indicates.", num_variables_read, m_num_variables); close_me(); - return ErrorCode_Truncated; + return ErrorCode::Truncated; } } @@ -213,7 +213,7 @@ namespace streaming_archive { namespace reader { m_current_ts_pattern_ix = 0; m_current_ts_in_milli = m_begin_ts; - return ErrorCode_Success; + return ErrorCode::Success; } void File::close_me () { @@ -233,7 +233,7 @@ namespace streaming_archive { namespace reader { // Unmap variables file if (0 != m_variables_file_size) { error_code = memory_unmap_file(m_variables_fd, m_variables_file_size, m_variables); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { SPDLOG_ERROR("streaming_archive::reader::File: Failed to unmap variables file, errno={}", errno); } m_variables_fd = -1; @@ -244,7 +244,7 @@ namespace streaming_archive { namespace reader { // Unmap logtypes file if (0 != m_logtypes_file_size) { error_code = memory_unmap_file(m_logtypes_fd, m_logtypes_file_size, m_logtypes); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { SPDLOG_ERROR("streaming_archive::reader::File: Failed to unmap logtypes file, errno={}", errno); } m_logtypes_fd = -1; @@ -255,7 +255,7 @@ namespace streaming_archive { namespace reader { // Unmap timestamps file if (0 != m_timestamps_file_size) { error_code = memory_unmap_file(m_timestamps_fd, m_timestamps_file_size, m_timestamps); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { SPDLOG_ERROR("streaming_archive::reader::File: Failed to unmap timestamps file, errno={}", errno); } m_timestamps_fd = -1; diff --git a/components/core/src/streaming_archive/reader/File.hpp b/components/core/src/streaming_archive/reader/File.hpp index d0a08592e8..b40da825d1 100644 --- a/components/core/src/streaming_archive/reader/File.hpp +++ b/components/core/src/streaming_archive/reader/File.hpp @@ -82,11 +82,11 @@ namespace streaming_archive { namespace reader { * @param archive_logs_dir_path Path to directory where logs are stored on disk in this archive * @param segment_manager Segment manager for when file is stored in a segment * @return FileReader::try_open's error codes on failure to open metadata - * @return ErrorCode_Failure_Metadata_Corrupted on metadata loading error - * @return ErrorCode_errno on error - * @return ErrorCode_FileNotFound if a column's file was not found - * @return ErrorCode_Truncated if metadata did not contain all required data or if column in segment was truncated - * @return ErrorCode_Success on success + * @return ErrorCode::Failure_Metadata_Corrupted on metadata loading error + * @return ErrorCode::Errno on error + * @return ErrorCode::FileNotFound if a column's file was not found + * @return ErrorCode::Truncated if metadata did not contain all required data or if column in segment was truncated + * @return ErrorCode::Success on success * @throw FileReader::OperationFailed on any read failure * @throw Same as streaming_archive::reader::SegmentManager::read */ diff --git a/components/core/src/streaming_archive/reader/Segment.cpp b/components/core/src/streaming_archive/reader/Segment.cpp index d73dff548f..f7e4d4e830 100644 --- a/components/core/src/streaming_archive/reader/Segment.cpp +++ b/components/core/src/streaming_archive/reader/Segment.cpp @@ -35,7 +35,7 @@ namespace streaming_archive { namespace reader { if (segment_path == m_segment_path) { // Do nothing if segment file path is the same because it is already memory mapped // If we want to re-open the same file, we need to close it first - return ErrorCode_Success; + return ErrorCode::Success; } // Get the size of the compressed segment file @@ -44,7 +44,7 @@ namespace streaming_archive { namespace reader { if (boost_error_code) { SPDLOG_ERROR("streaming_archive::reader::Segment: Unable to obtain file size for segment: {}", segment_path.c_str()); SPDLOG_ERROR("streaming_archive::reader::Segment: {}", boost_error_code.message().c_str()); - return ErrorCode_Failure; + return ErrorCode::Failure; } // Sanity check: previously used memory mapped file should be closed before opening a new one @@ -61,13 +61,13 @@ namespace streaming_archive { namespace reader { m_memory_mapped_segment_file.open(memory_map_params); if (!m_memory_mapped_segment_file.is_open()) { SPDLOG_ERROR("streaming_archive::reader:Segment: Unable to memory map the compressed segment with path: {}", segment_path.c_str()); - return ErrorCode_Failure; + return ErrorCode::Failure; } m_decompressor.open(m_memory_mapped_segment_file.data(), segment_file_size); m_segment_path = segment_path; - return ErrorCode_Success; + return ErrorCode::Success; } void Segment::close () { @@ -82,7 +82,7 @@ namespace streaming_archive { namespace reader { // We always assume the passed in buffer is already pre-allocated, but we check anyways as a precaution if (nullptr == extraction_buf) { SPDLOG_ERROR("streaming_archive::reader::Segment: Extraction buffer not allocated during decompression"); - return ErrorCode_BadParam; + return ErrorCode::BadParam; } return m_decompressor.get_decompressed_stream_region(decompressed_stream_pos, extraction_buf, extraction_len); } diff --git a/components/core/src/streaming_archive/reader/Segment.hpp b/components/core/src/streaming_archive/reader/Segment.hpp index 287f59f2da..41e778dee6 100644 --- a/components/core/src/streaming_archive/reader/Segment.hpp +++ b/components/core/src/streaming_archive/reader/Segment.hpp @@ -31,8 +31,8 @@ namespace streaming_archive { namespace reader { * Opens a segment with the given ID from the given directory * @param segment_dir_path * @param segment_id - * @return ErrorCode_Failure if unable to memory map the segment file - * @return ErrorCode_Success on success + * @return ErrorCode::Failure if unable to memory map the segment file + * @return ErrorCode::Success on success */ ErrorCode try_open (const std::string& segment_dir_path, segment_id_t segment_id); @@ -46,9 +46,9 @@ namespace streaming_archive { namespace reader { * @param decompressed_stream_pos Offset of the content in the segment * @param extraction_buf Buffer to store the content * @param extraction_len Length of the buffer - * @return ErrorCode_Truncated if decompressed_stream_pos is outside of the segment - * @return ErrorCode_Failure if decompression failed - * @return ErrorCode_Success on success + * @return ErrorCode::Truncated if decompressed_stream_pos is outside of the segment + * @return ErrorCode::Failure if decompression failed + * @return ErrorCode::Success on success */ ErrorCode try_read (uint64_t decompressed_stream_pos, char* extraction_buf, uint64_t extraction_len); diff --git a/components/core/src/streaming_archive/reader/SegmentManager.cpp b/components/core/src/streaming_archive/reader/SegmentManager.cpp index 5a76b29389..7ccb87999b 100644 --- a/components/core/src/streaming_archive/reader/SegmentManager.cpp +++ b/components/core/src/streaming_archive/reader/SegmentManager.cpp @@ -24,7 +24,7 @@ namespace streaming_archive { namespace reader { if (m_id_to_open_segment.count(segment_id) == 0) { // Insert and open segment ErrorCode error_code = m_id_to_open_segment[segment_id].try_open(m_segment_dir_path, segment_id); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { m_id_to_open_segment.erase(segment_id); return error_code; } diff --git a/components/core/src/streaming_archive/writer/Archive.cpp b/components/core/src/streaming_archive/writer/Archive.cpp index e3fec79876..0e9ea25fba 100644 --- a/components/core/src/streaming_archive/writer/Archive.cpp +++ b/components/core/src/streaming_archive/writer/Archive.cpp @@ -64,7 +64,7 @@ namespace streaming_archive { namespace writer { bool path_exists = boost::filesystem::exists(archive_path, boost_error_code); if (path_exists) { SPDLOG_ERROR("Archive path already exists: {}", archive_path.c_str()); - throw OperationFailed(ErrorCode_Unsupported, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Unsupported, __FILENAME__, __LINE__); } const auto& archive_path_string = archive_path.string(); m_stable_uncompressed_size = 0; @@ -74,14 +74,14 @@ namespace streaming_archive { namespace writer { retval = mkdir(archive_path_string.c_str(), 0750); if (0 != retval) { SPDLOG_ERROR("Failed to create {}, errno={}", archive_path_string.c_str(), errno); - throw OperationFailed(ErrorCode_errno, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Errno, __FILENAME__, __LINE__); } // Get archive directory's file descriptor int archive_dir_fd = ::open(archive_path_string.c_str(), O_RDONLY); if (-1 == archive_dir_fd) { SPDLOG_ERROR("Failed to get file descriptor for {}, errno={}", archive_path_string.c_str(), errno); - throw OperationFailed(ErrorCode_errno, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Errno, __FILENAME__, __LINE__); } // Create logs directory @@ -92,14 +92,14 @@ namespace streaming_archive { namespace writer { retval = mkdir(m_logs_dir_path.c_str(), 0750); if (0 != retval) { SPDLOG_ERROR("Failed to create {}, errno={}", m_logs_dir_path.c_str(), errno); - throw OperationFailed(ErrorCode_errno, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Errno, __FILENAME__, __LINE__); } // Get logs directory's file descriptor m_logs_dir_fd = ::open(m_logs_dir_path.c_str(), O_RDONLY); if (-1 == m_logs_dir_fd) { SPDLOG_ERROR("Failed to open file descriptor for {}, errno={}", m_logs_dir_path.c_str(), errno); - throw OperationFailed(ErrorCode_errno, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Errno, __FILENAME__, __LINE__); } // Create segments directory @@ -110,14 +110,14 @@ namespace streaming_archive { namespace writer { retval = mkdir(m_segments_dir_path.c_str(), 0750); if (0 != retval) { SPDLOG_ERROR("Failed to create {}, errno={}", m_segments_dir_path.c_str(), errno); - throw OperationFailed(ErrorCode_errno, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Errno, __FILENAME__, __LINE__); } // Get segments directory's file descriptor m_segments_dir_fd = ::open(m_segments_dir_path.c_str(), O_RDONLY); if (-1 == m_segments_dir_fd) { SPDLOG_ERROR("Failed to open file descriptor for {}, errno={}", m_segments_dir_path.c_str(), errno); - throw OperationFailed(ErrorCode_errno, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Errno, __FILENAME__, __LINE__); } // Create metadata database @@ -170,7 +170,7 @@ namespace streaming_archive { namespace writer { // fsync archive directory now that everything in the archive directory has been created if (fsync(archive_dir_fd) != 0) { SPDLOG_ERROR("Failed to fsync {}, errno={}", archive_path_string.c_str(), errno); - throw OperationFailed(ErrorCode_errno, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Errno, __FILENAME__, __LINE__); } #endif if (::close(archive_dir_fd) != 0) { @@ -184,7 +184,7 @@ namespace streaming_archive { namespace writer { void Archive::close () { // The file should have been closed and persisted before closing the archive. if (m_file != nullptr) { - throw OperationFailed(ErrorCode_Unsupported, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Unsupported, __FILENAME__, __LINE__); } // Close segments if necessary @@ -238,7 +238,7 @@ namespace streaming_archive { namespace writer { void Archive::create_and_open_file (const string& path, const group_id_t group_id, const boost::uuids::uuid& orig_file_id, size_t split_ix) { if (m_file != nullptr) { - throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotReady, __FILENAME__, __LINE__); } m_file = new File(m_uuid_generator(), orig_file_id, path, group_id, split_ix); m_file->open(); @@ -246,28 +246,28 @@ namespace streaming_archive { namespace writer { void Archive::close_file () { if (m_file == nullptr) { - throw OperationFailed(ErrorCode_Unsupported, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Unsupported, __FILENAME__, __LINE__); } m_file->close(); } const File& Archive::get_file () const { if (m_file == nullptr) { - throw OperationFailed(ErrorCode_Unsupported, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Unsupported, __FILENAME__, __LINE__); } return *m_file; } void Archive::set_file_is_split (bool is_split) { if (m_file == nullptr) { - throw OperationFailed(ErrorCode_Unsupported, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Unsupported, __FILENAME__, __LINE__); } m_file->set_is_split(is_split); } void Archive::change_ts_pattern (const TimestampPattern* pattern) { if (m_file == nullptr) { - throw OperationFailed(ErrorCode_Unsupported, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Unsupported, __FILENAME__, __LINE__); } m_file->change_ts_pattern(pattern); } @@ -297,7 +297,7 @@ namespace streaming_archive { namespace writer { // fsync logs directory to flush new files' directory entries if (0 != fsync(m_logs_dir_fd)) { SPDLOG_ERROR("Failed to fsync {}, errno={}", m_logs_dir_path.c_str(), errno); - throw OperationFailed(ErrorCode_errno, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Errno, __FILENAME__, __LINE__); } #endif @@ -326,7 +326,7 @@ namespace streaming_archive { namespace writer { void Archive::append_file_to_segment () { if (m_file == nullptr) { - throw OperationFailed(ErrorCode_Unsupported, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Unsupported, __FILENAME__, __LINE__); } if (m_file->has_ts_pattern()) { @@ -377,7 +377,7 @@ namespace streaming_archive { namespace writer { // fsync segments directory to flush segment's directory entry if (fsync(m_segments_dir_fd) != 0) { SPDLOG_ERROR("Failed to fsync {}, errno={}", m_segments_dir_path.c_str(), errno); - throw OperationFailed(ErrorCode_errno, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Errno, __FILENAME__, __LINE__); } #endif diff --git a/components/core/src/streaming_archive/writer/File.cpp b/components/core/src/streaming_archive/writer/File.cpp index b3dfa97d21..f8b30de944 100644 --- a/components/core/src/streaming_archive/writer/File.cpp +++ b/components/core/src/streaming_archive/writer/File.cpp @@ -11,7 +11,7 @@ using std::vector; namespace streaming_archive { namespace writer { void File::open () { if (m_is_written_out) { - throw OperationFailed(ErrorCode_Unsupported, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Unsupported, __FILENAME__, __LINE__); } m_timestamps = std::make_unique>(); m_logtypes = std::make_unique>(); @@ -21,7 +21,7 @@ namespace streaming_archive { namespace writer { void File::append_to_segment (const LogTypeDictionaryWriter& logtype_dict, Segment& segment) { if (m_is_open) { - throw OperationFailed(ErrorCode_Unsupported, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Unsupported, __FILENAME__, __LINE__); } // Append files to segment diff --git a/components/core/src/streaming_archive/writer/Segment.cpp b/components/core/src/streaming_archive/writer/Segment.cpp index bd250e5a64..9e4ecee52b 100644 --- a/components/core/src/streaming_archive/writer/Segment.cpp +++ b/components/core/src/streaming_archive/writer/Segment.cpp @@ -29,7 +29,7 @@ namespace streaming_archive { namespace writer { void Segment::open (const string& segments_dir_path, segment_id_t id, int compression_level) { if (!m_segment_path.empty()) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } m_id = id; diff --git a/components/core/src/streaming_compression/Compressor.hpp b/components/core/src/streaming_compression/Compressor.hpp index e07b43874d..fe0d005e88 100644 --- a/components/core/src/streaming_compression/Compressor.hpp +++ b/components/core/src/streaming_compression/Compressor.hpp @@ -39,15 +39,15 @@ namespace streaming_compression { /** * Unsupported operation * @param pos - * @return ErrorCode_Unsupported + * @return ErrorCode::Unsupported */ - ErrorCode try_seek_from_begin (size_t pos) override { return ErrorCode_Unsupported; }; + ErrorCode try_seek_from_begin (size_t pos) override { return ErrorCode::Unsupported; }; /** * Unsupported operation * @param pos - * @return ErrorCode_Unsupported + * @return ErrorCode::Unsupported */ - ErrorCode try_seek_from_current (off_t offset) override { return ErrorCode_Unsupported; }; + ErrorCode try_seek_from_current (off_t offset) override { return ErrorCode::Unsupported; }; // Methods /** diff --git a/components/core/src/streaming_compression/passthrough/Compressor.cpp b/components/core/src/streaming_compression/passthrough/Compressor.cpp index a48e14030b..ae2c5644e0 100644 --- a/components/core/src/streaming_compression/passthrough/Compressor.cpp +++ b/components/core/src/streaming_compression/passthrough/Compressor.cpp @@ -6,7 +6,7 @@ namespace streaming_compression { namespace passthrough { void Compressor::write (const char* data, const size_t data_length) { if (nullptr == m_compressed_stream_file_writer) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } if (0 == data_length) { @@ -14,7 +14,7 @@ namespace streaming_compression { namespace passthrough { return; } if (nullptr == data) { - throw OperationFailed(ErrorCode_BadParam, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::BadParam, __FILENAME__, __LINE__); } m_compressed_stream_file_writer->write(data, data_length); @@ -22,7 +22,7 @@ namespace streaming_compression { namespace passthrough { void Compressor::flush () { if (nullptr == m_compressed_stream_file_writer) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } m_compressed_stream_file_writer->flush(); @@ -30,7 +30,7 @@ namespace streaming_compression { namespace passthrough { ErrorCode Compressor::try_get_pos (size_t& pos) const { if (nullptr == m_compressed_stream_file_writer) { - return ErrorCode_NotInit; + return ErrorCode::NotInit; } return m_compressed_stream_file_writer->try_get_pos(pos); diff --git a/components/core/src/streaming_compression/passthrough/Compressor.hpp b/components/core/src/streaming_compression/passthrough/Compressor.hpp index f01cb29654..1ff48adce8 100644 --- a/components/core/src/streaming_compression/passthrough/Compressor.hpp +++ b/components/core/src/streaming_compression/passthrough/Compressor.hpp @@ -45,7 +45,7 @@ namespace streaming_compression { namespace passthrough { /** * Tries to get the current position of the write head * @param pos Position of the write head - * @return ErrorCode_NotInit if the compressor is not open + * @return ErrorCode::NotInit if the compressor is not open * @return Same as FileWriter::try_get_pos */ ErrorCode try_get_pos (size_t& pos) const override; diff --git a/components/core/src/streaming_compression/passthrough/Decompressor.cpp b/components/core/src/streaming_compression/passthrough/Decompressor.cpp index f526b3b989..648ec7baa6 100644 --- a/components/core/src/streaming_compression/passthrough/Decompressor.cpp +++ b/components/core/src/streaming_compression/passthrough/Decompressor.cpp @@ -6,45 +6,45 @@ namespace streaming_compression { namespace passthrough { ErrorCode Decompressor::try_read (char* buf, size_t num_bytes_to_read, size_t& num_bytes_read) { if (nullptr == m_compressed_data_buf) { - return ErrorCode_NotInit; + return ErrorCode::NotInit; } if (nullptr == buf) { - return ErrorCode_BadParam; + return ErrorCode::BadParam; } if (m_compressed_data_buf_len == m_decompressed_stream_pos) { - return ErrorCode_EndOfFile; + return ErrorCode::EndOfFile; } num_bytes_read = std::min(num_bytes_to_read, m_compressed_data_buf_len - m_decompressed_stream_pos); memcpy(buf, &m_compressed_data_buf[m_decompressed_stream_pos], num_bytes_read); m_decompressed_stream_pos += num_bytes_read; - return ErrorCode_Success; + return ErrorCode::Success; } ErrorCode Decompressor::try_seek_from_begin (size_t pos) { if (nullptr == m_compressed_data_buf) { - return ErrorCode_NotInit; + return ErrorCode::NotInit; } if (pos > m_compressed_data_buf_len) { - return ErrorCode_Truncated; + return ErrorCode::Truncated; } m_decompressed_stream_pos = pos; - return ErrorCode_Success; + return ErrorCode::Success; } ErrorCode Decompressor::try_get_pos (size_t& pos) { if (nullptr == m_compressed_data_buf) { - return ErrorCode_NotInit; + return ErrorCode::NotInit; } pos = m_decompressed_stream_pos; - return ErrorCode_Success; + return ErrorCode::Success; } void Decompressor::close () { @@ -54,7 +54,7 @@ namespace streaming_compression { namespace passthrough { ErrorCode Decompressor::get_decompressed_stream_region (size_t decompressed_stream_pos, char* extraction_buf, size_t extraction_len) { auto error_code = try_seek_from_begin(decompressed_stream_pos); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { return error_code; } diff --git a/components/core/src/streaming_compression/passthrough/Decompressor.hpp b/components/core/src/streaming_compression/passthrough/Decompressor.hpp index 43fbbf1a8f..3b4e938270 100644 --- a/components/core/src/streaming_compression/passthrough/Decompressor.hpp +++ b/components/core/src/streaming_compression/passthrough/Decompressor.hpp @@ -41,25 +41,25 @@ namespace streaming_compression { namespace passthrough { * @param buf * @param num_bytes_to_read The number of bytes to try and read * @param num_bytes_read The actual number of bytes read - * @return ErrorCode_NotInit if the decompressor is not open - * @return ErrorCode_BadParam if buf is invalid - * @return ErrorCode_EndOfFile on EOF - * @return ErrorCode_Success on success + * @return ErrorCode::NotInit if the decompressor is not open + * @return ErrorCode::BadParam if buf is invalid + * @return ErrorCode::EndOfFile on EOF + * @return ErrorCode::Success on success */ ErrorCode try_read (char* buf, size_t num_bytes_to_read, size_t& num_bytes_read) override; /** * Tries to seek from the beginning to the given position * @param pos - * @return ErrorCode_NotInit if the decompressor is not open - * @return ErrorCode_Truncated if the position is past the last byte in the file - * @return ErrorCode_Success on success + * @return ErrorCode::NotInit if the decompressor is not open + * @return ErrorCode::Truncated if the position is past the last byte in the file + * @return ErrorCode::Success on success */ ErrorCode try_seek_from_begin (size_t pos) override; /** * Tries to get the current position of the read head * @param pos Position of the read head in the file - * @return ErrorCode_NotInit if the decompressor is not open - * @return ErrorCode_Success on success + * @return ErrorCode::NotInit if the decompressor is not open + * @return ErrorCode::Success on success */ ErrorCode try_get_pos (size_t& pos) override; diff --git a/components/core/src/streaming_compression/zstd/Compressor.cpp b/components/core/src/streaming_compression/zstd/Compressor.cpp index 4642640e61..3a53b8d37a 100644 --- a/components/core/src/streaming_compression/zstd/Compressor.cpp +++ b/components/core/src/streaming_compression/zstd/Compressor.cpp @@ -13,7 +13,7 @@ namespace streaming_compression { namespace zstd { m_compression_stream = ZSTD_createCStream(); if (nullptr == m_compression_stream) { SPDLOG_ERROR("streaming_compression::zstd::Compressor: ZSTD_createCStream() error"); - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } } @@ -23,7 +23,7 @@ namespace streaming_compression { namespace zstd { void Compressor::open (FileWriter& file_writer, const int compression_level) { if (nullptr != m_compressed_stream_file_writer) { - throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotReady, __FILENAME__, __LINE__); } // Setup compressed stream parameters @@ -36,7 +36,7 @@ namespace streaming_compression { namespace zstd { auto init_result = ZSTD_initCStream(m_compression_stream, compression_level); if (ZSTD_isError(init_result)) { SPDLOG_ERROR("streaming_compression::zstd::Compressor: ZSTD_initCStream() error: {}", ZSTD_getErrorName(init_result)); - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } m_compressed_stream_file_writer = &file_writer; @@ -46,7 +46,7 @@ namespace streaming_compression { namespace zstd { void Compressor::close () { if (nullptr == m_compressed_stream_file_writer) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } flush(); @@ -55,7 +55,7 @@ namespace streaming_compression { namespace zstd { void Compressor::write (const char* data, size_t data_length) { if (nullptr == m_compressed_stream_file_writer) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } if (0 == data_length) { @@ -63,7 +63,7 @@ namespace streaming_compression { namespace zstd { return; } if (nullptr == data) { - throw OperationFailed(ErrorCode_BadParam, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::BadParam, __FILENAME__, __LINE__); } ZSTD_inBuffer uncompressed_stream_block = {data, data_length, 0}; @@ -72,7 +72,7 @@ namespace streaming_compression { namespace zstd { auto error = ZSTD_compressStream(m_compression_stream, &m_compressed_stream_block, &uncompressed_stream_block); if (ZSTD_isError(error)) { SPDLOG_ERROR("streaming_compression::zstd::Compressor: ZSTD_compressStream() error: {}", ZSTD_getErrorName(error)); - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } if (m_compressed_stream_block.pos) { // Write to disk only if there is data in the compressed stream block buffer @@ -94,7 +94,7 @@ namespace streaming_compression { namespace zstd { if (end_stream_result) { // Note: Output buffer is large enough that it is guaranteed to have enough room to be able to flush the entire buffer, so this can only be an error SPDLOG_ERROR("streaming_compression::zstd::Compressor: ZSTD_endStream() error: {}", ZSTD_getErrorName(end_stream_result)); - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } m_compressed_stream_file_writer->write(reinterpret_cast(m_compressed_stream_block.dst), m_compressed_stream_block.pos); @@ -103,11 +103,11 @@ namespace streaming_compression { namespace zstd { ErrorCode Compressor::try_get_pos (size_t& pos) const { if (nullptr == m_compressed_stream_file_writer) { - return ErrorCode_NotInit; + return ErrorCode::NotInit; } pos = m_uncompressed_stream_pos; - return ErrorCode_Success; + return ErrorCode::Success; } void Compressor::flush_without_ending_frame () { @@ -120,7 +120,7 @@ namespace streaming_compression { namespace zstd { auto result = ZSTD_flushStream(m_compression_stream, &m_compressed_stream_block); if (ZSTD_isError(result)) { SPDLOG_ERROR("streaming_compression::zstd::Compressor: ZSTD_compressStream2() error: {}", ZSTD_getErrorName(result)); - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } if (m_compressed_stream_block.pos) { m_compressed_stream_file_writer->write(reinterpret_cast(m_compressed_stream_block.dst), m_compressed_stream_block.pos); diff --git a/components/core/src/streaming_compression/zstd/Compressor.hpp b/components/core/src/streaming_compression/zstd/Compressor.hpp index 9f009e67b8..076c4cac38 100644 --- a/components/core/src/streaming_compression/zstd/Compressor.hpp +++ b/components/core/src/streaming_compression/zstd/Compressor.hpp @@ -55,8 +55,8 @@ namespace streaming_compression { namespace zstd { /** * Tries to get the current position of the write head * @param pos Position of the write head - * @return ErrorCode_NotInit if the compressor is not open - * @return ErrorCode_Success on success + * @return ErrorCode::NotInit if the compressor is not open + * @return ErrorCode::Success on success */ ErrorCode try_get_pos (size_t& pos) const override; diff --git a/components/core/src/streaming_compression/zstd/Decompressor.cpp b/components/core/src/streaming_compression/zstd/Decompressor.cpp index 8a1a2fdb9c..105d6b59ef 100644 --- a/components/core/src/streaming_compression/zstd/Decompressor.cpp +++ b/components/core/src/streaming_compression/zstd/Decompressor.cpp @@ -20,7 +20,7 @@ namespace streaming_compression { namespace zstd { m_decompression_stream = ZSTD_createDStream(); if (nullptr == m_decompression_stream) { SPDLOG_ERROR("streaming_compression::zstd::Decompressor: ZSTD_createDStream() error"); - throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::Failure, __FILENAME__, __LINE__); } // Create block to hold unused decompressed data @@ -34,10 +34,10 @@ namespace streaming_compression { namespace zstd { ErrorCode Decompressor::try_read (char* buf, size_t num_bytes_to_read, size_t& num_bytes_read) { if (InputType::NotInitialized == m_input_type) { - return ErrorCode_NotInit; + return ErrorCode::NotInit; } if (nullptr == buf) { - return ErrorCode_BadParam; + return ErrorCode::BadParam; } num_bytes_read = 0; @@ -49,20 +49,20 @@ namespace streaming_compression { namespace zstd { if (InputType::File != m_input_type) { num_bytes_read = decompressed_stream_block.pos; if (0 == decompressed_stream_block.pos) { - return ErrorCode_EndOfFile; + return ErrorCode::EndOfFile; } else { - return ErrorCode_Success; + return ErrorCode::Success; } } else { auto error_code = m_file_reader->try_read(reinterpret_cast(m_file_read_buffer.get()), m_file_read_buffer_capacity, m_file_read_buffer_length); - if (ErrorCode_Success != error_code) { - if (ErrorCode_EndOfFile == error_code) { + if (ErrorCode::Success != error_code) { + if (ErrorCode::EndOfFile == error_code) { num_bytes_read = decompressed_stream_block.pos; if (0 == decompressed_stream_block.pos) { - return ErrorCode_EndOfFile; + return ErrorCode::EndOfFile; } else { - return ErrorCode_Success; + return ErrorCode::Success; } } else { return error_code; @@ -78,7 +78,7 @@ namespace streaming_compression { namespace zstd { size_t error = ZSTD_decompressStream(m_decompression_stream, &decompressed_stream_block, &m_compressed_stream_block); if (ZSTD_isError(error)) { SPDLOG_ERROR("streaming_compression::zstd::Decompressor: ZSTD_decompressStream() error: {}", ZSTD_getErrorName(error)); - return ErrorCode_Failure; + return ErrorCode::Failure; } } @@ -86,12 +86,12 @@ namespace streaming_compression { namespace zstd { m_decompressed_stream_pos += decompressed_stream_block.pos; num_bytes_read = decompressed_stream_block.pos; - return ErrorCode_Success; + return ErrorCode::Success; } ErrorCode Decompressor::try_seek_from_begin (size_t pos) { if (InputType::NotInitialized == m_input_type) { - throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotInit, __FILENAME__, __LINE__); } // Check if we've already decompressed passed the desired position @@ -105,21 +105,21 @@ namespace streaming_compression { namespace zstd { while (m_decompressed_stream_pos < pos) { size_t num_bytes_to_decompress = std::min(m_unused_decompressed_stream_block_size, pos - m_decompressed_stream_pos); error = try_read_exact_length(m_unused_decompressed_stream_block_buffer.get(), num_bytes_to_decompress); - if (ErrorCode_Success != error) { + if (ErrorCode::Success != error) { return error; } } - return ErrorCode_Success; + return ErrorCode::Success; } ErrorCode Decompressor::try_get_pos (size_t& pos) { if (InputType::NotInitialized == m_input_type) { - return ErrorCode_NotInit; + return ErrorCode::NotInit; } pos = m_decompressed_stream_pos; - return ErrorCode_Success; + return ErrorCode::Success; } void Decompressor::close () { @@ -139,7 +139,7 @@ namespace streaming_compression { namespace zstd { void Decompressor::open (const char* compressed_data_buf, size_t compressed_data_buf_size) { if (InputType::NotInitialized != m_input_type) { - throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotReady, __FILENAME__, __LINE__); } m_input_type = InputType::CompressedDataBuf; @@ -151,7 +151,7 @@ namespace streaming_compression { namespace zstd { ErrorCode Decompressor::open (const std::string& compressed_file_path) { if (InputType::NotInitialized != m_input_type) { - throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotReady, __FILENAME__, __LINE__); } m_input_type = InputType::MemoryMappedCompressedFile; @@ -161,7 +161,7 @@ namespace streaming_compression { namespace zstd { if (boost_error_code) { SPDLOG_ERROR("streaming_compression::zstd::Decompressor: Unable to obtain file size for '{}' - {}.", compressed_file_path.c_str(), boost_error_code.message().c_str()); - return ErrorCode_Failure; + return ErrorCode::Failure; } boost::iostreams::mapped_file_params memory_map_params; @@ -172,7 +172,7 @@ namespace streaming_compression { namespace zstd { m_memory_mapped_compressed_file.open(memory_map_params); if (!m_memory_mapped_compressed_file.is_open()) { SPDLOG_ERROR("streaming_compression::zstd::Decompressor: Unable to memory map the compressed file with path: {}", compressed_file_path.c_str()); - return ErrorCode_Failure; + return ErrorCode::Failure; } // Configure input stream @@ -180,12 +180,12 @@ namespace streaming_compression { namespace zstd { reset_stream(); - return ErrorCode_Success; + return ErrorCode::Success; } void Decompressor::open (FileReader& file_reader, size_t file_read_buffer_capacity) { if (InputType::NotInitialized != m_input_type) { - throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__); + throw OperationFailed(ErrorCode::NotReady, __FILENAME__, __LINE__); } m_input_type = InputType::File; @@ -203,7 +203,7 @@ namespace streaming_compression { namespace zstd { ErrorCode Decompressor::get_decompressed_stream_region (size_t decompressed_stream_pos, char* extraction_buf, size_t extraction_len) { auto error_code = try_seek_from_begin(decompressed_stream_pos); - if (ErrorCode_Success != error_code) { + if (ErrorCode::Success != error_code) { return error_code; } diff --git a/components/core/src/streaming_compression/zstd/Decompressor.hpp b/components/core/src/streaming_compression/zstd/Decompressor.hpp index 6f2b80c5b6..b1bc5b17b1 100644 --- a/components/core/src/streaming_compression/zstd/Decompressor.hpp +++ b/components/core/src/streaming_compression/zstd/Decompressor.hpp @@ -51,26 +51,26 @@ namespace streaming_compression { namespace zstd { * @param num_bytes_to_read The number of bytes to try and read * @param num_bytes_read The actual number of bytes read * @return Same as FileReader::try_read if the decompressor is attached to a file - * @return ErrorCode_NotInit if the decompressor is not open - * @return ErrorCode_BadParam if buf is invalid - * @return ErrorCode_EndOfFile on EOF - * @return ErrorCode_Failure on decompression failure - * @return ErrorCode_Success on success + * @return ErrorCode::NotInit if the decompressor is not open + * @return ErrorCode::BadParam if buf is invalid + * @return ErrorCode::EndOfFile on EOF + * @return ErrorCode::Failure on decompression failure + * @return ErrorCode::Success on success */ ErrorCode try_read (char* buf, size_t num_bytes_to_read, size_t& num_bytes_read) override; /** * Tries to seek from the beginning to the given position * @param pos - * @return ErrorCode_NotInit if the decompressor is not open + * @return ErrorCode::NotInit if the decompressor is not open * @return Same as ReaderInterface::try_read_exact_length - * @return ErrorCode_Success on success + * @return ErrorCode::Success on success */ ErrorCode try_seek_from_begin (size_t pos) override; /** * Tries to get the current position of the read head * @param pos Position of the read head in the file - * @return ErrorCode_NotInit if the decompressor is not open - * @return ErrorCode_Success on success + * @return ErrorCode::NotInit if the decompressor is not open + * @return ErrorCode::Success on success */ ErrorCode try_get_pos (size_t& pos) override; @@ -98,8 +98,8 @@ namespace streaming_compression { namespace zstd { * Initialize streaming decompressor to decompress from a compressed file specified by the given path * @param compressed_file_path * @param decompressed_stream_block_size - * @return ErrorCode_Failure if the provided path cannot be memory mapped - * @return ErrorCode_Success on success + * @return ErrorCode::Failure if the provided path cannot be memory mapped + * @return ErrorCode::Success on success */ ErrorCode open (const std::string& compressed_file_path); diff --git a/components/core/tests/test-Segment.cpp b/components/core/tests/test-Segment.cpp index c4c54d0bfa..b9570c3536 100644 --- a/components/core/tests/test-Segment.cpp +++ b/components/core/tests/test-Segment.cpp @@ -31,7 +31,7 @@ TEST_CASE("Test writing and reading a segment", "[Segment]") { // Create directory for segments string segments_dir_path = "unit-test-segment/"; error_code = create_directory_structure(segments_dir_path, 0700); - REQUIRE(ErrorCode_Success == error_code); + REQUIRE(ErrorCode::Success == error_code); // Test segment writing writer::Segment writer_segment; @@ -48,11 +48,11 @@ TEST_CASE("Test writing and reading a segment", "[Segment]") { reader::Segment reader_segment; error_code = reader_segment.try_open(segments_dir_path, segment_id); - REQUIRE(ErrorCode_Success == error_code); + REQUIRE(ErrorCode::Success == error_code); // Read out error_code = reader_segment.try_read(0, decompressed_data, uncompressed_data_size); - REQUIRE(ErrorCode_Success == error_code); + REQUIRE(ErrorCode::Success == error_code); REQUIRE(memcmp(uncompressed_data, decompressed_data, uncompressed_data_size) == 0); reader_segment.close(); diff --git a/components/core/tests/test-StreamingCompression.cpp b/components/core/tests/test-StreamingCompression.cpp index 7710c0dacd..6110f8ad83 100644 --- a/components/core/tests/test-StreamingCompression.cpp +++ b/components/core/tests/test-StreamingCompression.cpp @@ -50,38 +50,38 @@ TEST_CASE("StreamingCompression", "[StreamingCompression]") { // Decompress streaming_compression::zstd::Decompressor decompressor; - REQUIRE(ErrorCode_Success == decompressor.open(compressed_file_path)); + REQUIRE(ErrorCode::Success == decompressor.open(compressed_file_path)); size_t uncompressed_bytes = 0; - REQUIRE(ErrorCode_Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, ZSTD_CStreamInSize())); + REQUIRE(ErrorCode::Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, ZSTD_CStreamInSize())); REQUIRE(memcmp(uncompressed_data, decompressed_data, ZSTD_CStreamInSize()) == 0); memset(decompressed_data, 0, uncompressed_data_size); uncompressed_bytes += ZSTD_CStreamInSize(); - REQUIRE(ErrorCode_Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size/100)); + REQUIRE(ErrorCode::Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size/100)); REQUIRE(memcmp(uncompressed_data, decompressed_data, uncompressed_data_size/100) == 0); memset(decompressed_data, 0, uncompressed_data_size); uncompressed_bytes += uncompressed_data_size/100; - REQUIRE(ErrorCode_Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size/50)); + REQUIRE(ErrorCode::Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size/50)); REQUIRE(memcmp(uncompressed_data, decompressed_data, uncompressed_data_size/50) == 0); memset(decompressed_data, 0, uncompressed_data_size); uncompressed_bytes += uncompressed_data_size/50; - REQUIRE(ErrorCode_Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size/25)); + REQUIRE(ErrorCode::Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size/25)); REQUIRE(memcmp(uncompressed_data, decompressed_data, uncompressed_data_size/25) == 0); memset(decompressed_data, 0, uncompressed_data_size); uncompressed_bytes += uncompressed_data_size/25; - REQUIRE(ErrorCode_Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size/10)); + REQUIRE(ErrorCode::Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size/10)); REQUIRE(memcmp(uncompressed_data, decompressed_data, uncompressed_data_size/10) == 0); memset(decompressed_data, 0, uncompressed_data_size); uncompressed_bytes += uncompressed_data_size/10; - REQUIRE(ErrorCode_Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size/5)); + REQUIRE(ErrorCode::Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size/5)); REQUIRE(memcmp(uncompressed_data, decompressed_data, uncompressed_data_size/5) == 0); memset(decompressed_data, 0, uncompressed_data_size); uncompressed_bytes += uncompressed_data_size/5; - REQUIRE(ErrorCode_Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size/2)); + REQUIRE(ErrorCode::Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size/2)); REQUIRE(memcmp(uncompressed_data, decompressed_data, uncompressed_data_size/2) == 0); memset(decompressed_data, 0, uncompressed_data_size); uncompressed_bytes += uncompressed_data_size/2; - REQUIRE(ErrorCode_Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size)); + REQUIRE(ErrorCode::Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size)); REQUIRE(memcmp(uncompressed_data, decompressed_data, uncompressed_data_size) == 0); memset(decompressed_data, 0, uncompressed_data_size); uncompressed_bytes += uncompressed_data_size; @@ -129,31 +129,31 @@ TEST_CASE("StreamingCompression", "[StreamingCompression]") { decompressor.open(memory_mapped_compressed_file.data(), compressed_file_size); size_t uncompressed_bytes = 0; - REQUIRE(ErrorCode_Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size/100)); + REQUIRE(ErrorCode::Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size/100)); REQUIRE(memcmp(uncompressed_data, decompressed_data, uncompressed_data_size/100) == 0); memset(decompressed_data, 0, uncompressed_data_size); uncompressed_bytes += uncompressed_data_size/100; - REQUIRE(ErrorCode_Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size/50)); + REQUIRE(ErrorCode::Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size/50)); REQUIRE(memcmp(uncompressed_data, decompressed_data, uncompressed_data_size/50) == 0); memset(decompressed_data, 0, uncompressed_data_size); uncompressed_bytes += uncompressed_data_size/50; - REQUIRE(ErrorCode_Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size/25)); + REQUIRE(ErrorCode::Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size/25)); REQUIRE(memcmp(uncompressed_data, decompressed_data, uncompressed_data_size/25) == 0); memset(decompressed_data, 0, uncompressed_data_size); uncompressed_bytes += uncompressed_data_size/25; - REQUIRE(ErrorCode_Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size/10)); + REQUIRE(ErrorCode::Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size/10)); REQUIRE(memcmp(uncompressed_data, decompressed_data, uncompressed_data_size/10) == 0); memset(decompressed_data, 0, uncompressed_data_size); uncompressed_bytes += uncompressed_data_size/10; - REQUIRE(ErrorCode_Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size/5)); + REQUIRE(ErrorCode::Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size/5)); REQUIRE(memcmp(uncompressed_data, decompressed_data, uncompressed_data_size/5) == 0); memset(decompressed_data, 0, uncompressed_data_size); uncompressed_bytes += uncompressed_data_size/5; - REQUIRE(ErrorCode_Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size/2)); + REQUIRE(ErrorCode::Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size/2)); REQUIRE(memcmp(uncompressed_data, decompressed_data, uncompressed_data_size/2) == 0); memset(decompressed_data, 0, uncompressed_data_size); uncompressed_bytes += uncompressed_data_size/2; - REQUIRE(ErrorCode_Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size)); + REQUIRE(ErrorCode::Success == decompressor.get_decompressed_stream_region(uncompressed_bytes, decompressed_data, uncompressed_data_size)); REQUIRE(memcmp(uncompressed_data, decompressed_data, uncompressed_data_size) == 0); memset(decompressed_data, 0, uncompressed_data_size); uncompressed_bytes += uncompressed_data_size; diff --git a/components/core/tests/test-Utils.cpp b/components/core/tests/test-Utils.cpp index 745fc8a8b9..ea1eb0aa71 100644 --- a/components/core/tests/test-Utils.cpp +++ b/components/core/tests/test-Utils.cpp @@ -82,15 +82,15 @@ TEST_CASE("create_directory_structure", "[create_directory_structure]") { string path; path = "a/b/c"; - REQUIRE(ErrorCode_Success == create_directory_structure(path, 0700)); + REQUIRE(ErrorCode::Success == create_directory_structure(path, 0700)); REQUIRE(stat(path.c_str(), &s) == 0); path = "d/e/f/"; - REQUIRE(ErrorCode_Success == create_directory_structure(path, 0700)); + REQUIRE(ErrorCode::Success == create_directory_structure(path, 0700)); REQUIRE(stat(path.c_str(), &s) == 0); path = "/tmp/5807"; - REQUIRE(ErrorCode_Success == create_directory_structure(path, 0700)); + REQUIRE(ErrorCode::Success == create_directory_structure(path, 0700)); REQUIRE(stat(path.c_str(), &s) == 0); REQUIRE(0 == rmdir("a/b/c"));