diff --git a/rosbag2_compression/src/rosbag2_compression/sequential_compression_writer.cpp b/rosbag2_compression/src/rosbag2_compression/sequential_compression_writer.cpp index cc04ecec7..3747f3c80 100644 --- a/rosbag2_compression/src/rosbag2_compression/sequential_compression_writer.cpp +++ b/rosbag2_compression/src/rosbag2_compression/sequential_compression_writer.cpp @@ -333,12 +333,17 @@ void SequentialCompressionWriter::compress_file( BaseCompressorInterface & compressor, const std::string & file_relative_to_bag) { + if (file_relative_to_bag.empty()) { + ROSBAG2_COMPRESSION_LOG_DEBUG_STREAM("Cannot compress file with empty path relative to bag." + " Skipping compression."); + return; + } const auto file_relative_to_pwd = fs::path(base_folder_) / file_relative_to_bag; - ROSBAG2_COMPRESSION_LOG_INFO_STREAM("Compressing file: " << file_relative_to_pwd.string()); - if (fs::exists(file_relative_to_pwd) && + if (fs::exists(file_relative_to_pwd) && !fs::is_directory(file_relative_to_pwd) && fs::file_size(file_relative_to_pwd) > 0u) { + ROSBAG2_COMPRESSION_LOG_INFO_STREAM("Compressing file: " << file_relative_to_pwd.string()); const auto compressed_uri = compressor.compress_uri(file_relative_to_pwd.string()); const auto relative_compressed_uri = fs::path(compressed_uri).filename(); { @@ -367,7 +372,7 @@ void SequentialCompressionWriter::compress_file( "will not be halted because the compressed output was successfully created."); } } else { - ROSBAG2_COMPRESSION_LOG_DEBUG_STREAM( + ROSBAG2_COMPRESSION_LOG_WARN_STREAM( "Removing last file: \"" << file_relative_to_pwd.string() << "\" because it either is empty or does not exist."); }