Skip to content

Commit

Permalink
Retouch the IR decompression path
Browse files Browse the repository at this point in the history
  • Loading branch information
haiqi96 committed May 29, 2024
1 parent 2dd3a14 commit 88f2db9
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 36 deletions.
16 changes: 8 additions & 8 deletions components/core/src/clp/clp/CommandLineArguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ CommandLineArguments::parse_arguments(int argc, char const* argv[]) {
switch (command_input) {
case (char)Command::Compress:
case (char)Command::Extract:
case (char)Command::Ir:
case (char)Command::IR:
m_command = (Command)command_input;
break;
default:
Expand Down Expand Up @@ -224,19 +224,19 @@ CommandLineArguments::parse_arguments(int argc, char const* argv[]) {
if (m_archives_dir.empty()) {
throw invalid_argument("ARCHIVES_DIR cannot be empty.");
}
} else if (Command::Ir == m_command) {
// Define if hidden positional options
} else if (Command::IR == m_command) {
// Define ir decompression hidden positional options
po::options_description ir_positional_options;
// clang-format off
ir_positional_options.add_options()
("archives-dir", po::value<string>(&m_archives_dir))
("output-dir", po::value<string>(&m_output_dir))
("file-id", po::value<string>(&m_file_id));
("orig-file-id", po::value<string>(&m_orig_file_id));
// clang-format on
po::positional_options_description ir_positional_options_description;
ir_positional_options_description.add("archives-dir", 1);
ir_positional_options_description.add("output-dir", 1);
ir_positional_options_description.add("file-id", 1);
ir_positional_options_description.add("orig-file-id", 1);

po::options_description options_ir("IR decompression Options");
options_ir.add_options()(
Expand All @@ -262,7 +262,7 @@ CommandLineArguments::parse_arguments(int argc, char const* argv[]) {
all_ir_options.add(ir_positional_options);
all_ir_options.add(options_ir);

// Parse extraction options
// Parse ir decompression options
vector<string> unrecognized_options
= po::collect_unrecognized(parsed.options, po::include_positional);
unrecognized_options.erase(unrecognized_options.begin());
Expand Down Expand Up @@ -297,7 +297,7 @@ CommandLineArguments::parse_arguments(int argc, char const* argv[]) {
}

// Validate file id is not empty
if (m_file_id.empty()) {
if (m_orig_file_id.empty()) {
throw invalid_argument("FILE_ID cannot be empty.");
}

Expand Down Expand Up @@ -487,7 +487,7 @@ void CommandLineArguments::print_extraction_basic_usage() const {
}

void CommandLineArguments::print_ir_basic_usage() const {
cerr << "Usage: " << get_program_name() << " [OPTIONS] i ARCHIVES_DIR OUTPUT_DIR FILE_ID]"
cerr << "Usage: " << get_program_name() << " [OPTIONS] i ARCHIVES_DIR OUTPUT_DIR ORIG_FILE_ID"
<< endl;
}
} // namespace clp::clp
10 changes: 5 additions & 5 deletions components/core/src/clp/clp/CommandLineArguments.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CommandLineArguments : public CommandLineArgumentsBase {
enum class Command : char {
Compress = 'c',
Extract = 'x',
Ir = 'i'
IR = 'i'
};

// Constructors
Expand Down Expand Up @@ -69,7 +69,7 @@ class CommandLineArguments : public CommandLineArgumentsBase {

std::vector<std::string> const& get_input_paths() const { return m_input_paths; }

std::string const& get_file_id() const { return m_file_id; }
std::string const& get_orig_file_id() const { return m_orig_file_id; }

size_t get_ir_msg_ix() const { return m_ir_msg_ix; }

Expand All @@ -86,12 +86,12 @@ class CommandLineArguments : public CommandLineArgumentsBase {
// Variables
std::string m_path_list_path;
std::string m_path_prefix_to_remove;
bool m_sort_input_files;
std::string m_file_id;
std::string m_orig_file_id;
size_t m_ir_msg_ix;
size_t m_ir_target_size;
std::string m_output_dir;
bool m_sort_input_files;
std::string m_ir_temp_output_dir;
std::string m_output_dir;
std::string m_schema_file_path;
bool m_show_progress;
bool m_print_archive_stats_progress;
Expand Down
42 changes: 23 additions & 19 deletions components/core/src/clp/clp/IrDecompression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ using std::unique_ptr;
using std::unordered_set;

namespace clp::clp {
bool decompress_ir(CommandLineArguments& command_line_args, string const& file_id) {
bool decompress_ir(CommandLineArguments& command_line_args, string const& file_orig_id) {
ErrorCode error_code;

// Create output directory in case it doesn't exist
Expand All @@ -49,15 +49,14 @@ bool decompress_ir(CommandLineArguments& command_line_args, string const& file_i

if (false
== global_metadata_db->get_file_split(
file_id,
file_orig_id,
command_line_args.get_ir_msg_ix(),
archive_id,
file_split_id
))
{
SPDLOG_ERROR(
"Failed to find file {} with msg_ix {}",
file_id,
"Failed to find file split containing msg_ix {}",
command_line_args.get_ir_msg_ix()
);
return false;
Expand All @@ -67,24 +66,29 @@ bool decompress_ir(CommandLineArguments& command_line_args, string const& file_i
archive_reader.open(archive_path.string());
archive_reader.refresh_dictionaries();

// Decompress all splits with the given path
// Decompress the split
auto file_metadata_ix_ptr = archive_reader.get_file_iterator_by_split_id(file_split_id);
for (auto& file_metadata_ix = *file_metadata_ix_ptr; file_metadata_ix.has_next();
file_metadata_ix.next())
if (false == file_metadata_ix_ptr->has_next()) {
SPDLOG_ERROR(
"File split doesn't exist {} in the archive {}",
file_split_id,
archive_id
);
return false;
}
// Decompress file
if (false
== file_decompressor.decompress_ir(
*file_metadata_ix_ptr,
command_line_args.get_output_dir(),
command_line_args.get_ir_temp_output_dir(),
archive_reader,
command_line_args.get_ir_target_size()
))
{
// Decompress file
if (false
== file_decompressor.decompress_ir(
file_metadata_ix,
command_line_args.get_output_dir(),
command_line_args.get_ir_temp_output_dir(),
archive_reader,
command_line_args.get_ir_target_size()
))
{
return false;
}
return false;
}

file_metadata_ix_ptr.reset(nullptr);

archive_reader.close();
Expand Down
4 changes: 2 additions & 2 deletions components/core/src/clp/clp/IrDecompression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace clp::clp {
/**
* Decompresses a file split into an IR into the given directory
* @param command_line_args
* @param file_id
* @param file_orig_id
* @return true if decompression was successful, false otherwise
*/
bool decompress_ir(CommandLineArguments& command_line_args, std::string const& file_id);
bool decompress_ir(CommandLineArguments& command_line_args, std::string const& file_orig_id);
} // namespace clp::clp

#endif // CLP_CLP_IRDECOMPRESSION_HPP
4 changes: 2 additions & 2 deletions components/core/src/clp/clp/run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ int run(int argc, char const* argv[]) {
return -1;
}
}
} else { // CommandLineArguments::Command::Ir == command
if (!decompress_ir(command_line_args, command_line_args.get_file_id())) {
} else { // CommandLineArguments::Command::IR == command
if (!decompress_ir(command_line_args, command_line_args.get_orig_file_id())) {
return -1;
}
}
Expand Down

0 comments on commit 88f2db9

Please sign in to comment.