Skip to content

Commit cc463c1

Browse files
committed
fix(clp-s): Skip empty files during compression to avoid false errors (fixes y-scope#1993).
1 parent 35b5ef1 commit cc463c1

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

components/core/src/clp_s/JsonParser.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
#include <cctype>
44
#include <cstddef>
55
#include <cstdint>
6+
#include <filesystem>
67
#include <memory>
78
#include <optional>
89
#include <stack>
910
#include <string>
1011
#include <string_view>
12+
#include <system_error>
1113
#include <utility>
1214
#include <vector>
1315

@@ -647,6 +649,15 @@ void JsonParser::parse_line(
647649
bool JsonParser::ingest() {
648650
auto archive_creator_id = boost::uuids::to_string(m_generator());
649651
for (auto const& [path, file_name_in_metadata] : m_input_paths_and_canonical_filenames) {
652+
if (InputSource::Filesystem == path.source) {
653+
std::error_code ec{};
654+
auto const file_size{std::filesystem::file_size(path.path, ec)};
655+
if (std::errc{} == ec && 0 == file_size) {
656+
SPDLOG_INFO("Skipping empty file: {}", path.path);
657+
continue;
658+
}
659+
}
660+
650661
auto reader{try_create_reader(path, m_network_auth)};
651662
if (nullptr == reader) {
652663
std::ignore = m_archive_writer->close();

components/core/src/clp_s/log_converter/log_converter.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ auto convert_files(CommandLineArguments const& command_line_arguments) -> bool {
7171
}
7272

7373
for (auto const& path : command_line_arguments.get_input_paths()) {
74+
if (clp_s::InputSource::Filesystem == path.source) {
75+
std::error_code ec{};
76+
auto const file_size{std::filesystem::file_size(path.path, ec)};
77+
if (std::errc{} == ec && 0 == file_size) {
78+
SPDLOG_INFO("Skipping empty file: {}", path.path);
79+
continue;
80+
}
81+
}
82+
7483
auto reader{clp_s::try_create_reader(path, command_line_arguments.get_network_auth())};
7584
if (nullptr == reader) {
7685
SPDLOG_ERROR("Failed to open input {} for reading.", path.path);

0 commit comments

Comments
 (0)