Skip to content

Commit

Permalink
Merge pull request #390 from AsherGlick/simplifying_reading_functions
Browse files Browse the repository at this point in the history
Adding Zip file crawling
  • Loading branch information
AsherGlick authored Feb 10, 2025
2 parents ed94351 + 3f754fc commit 13ed5c1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
27 changes: 24 additions & 3 deletions xml_converter/src/file_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ vector<MarkerPackFile> get_files_by_suffix(
cout << "Error: " << base << " does not exist" << endl;
return vector<MarkerPackFile>();
}
// If it is a directory, call open_directory_file_to_read
// If it is a directory and parse the directory contents.
else if (filesystem::is_directory(base)) {
DIR* dir = opendir(join_file_paths(base, subpath).c_str());
struct dirent* entry;
Expand All @@ -97,8 +97,29 @@ vector<MarkerPackFile> get_files_by_suffix(
}
closedir(dir);
}
// else if (filesystem::is_regular_file(file.base)) {
// }
// If it is a file, assume it is a zip file and read the zip contents.
else if (filesystem::is_regular_file(base)) {
int error = 0;
zip* zip_archive = zip_open(base.c_str(), ZIP_RDONLY, &error);

if (zip_archive == nullptr) {
cerr << "Error: could not open the zip archive " << base << ". Got Error code " << error << endl;
return files;
}

int64_t num_entries = zip_get_num_entries(zip_archive, 0x00);
for (int64_t i = 0; i < num_entries; i++) {
const char* filename = zip_get_name(zip_archive, i, 0x00);

if (has_suffix(filename, suffix)) {
MarkerPackFile new_file(base, filename);
files.push_back(new_file);
}
}
}
else {
cerr << "Error: " << base << " is not a file or directory" << endl;
}

sort(files.begin(), files.end(), marker_pack_file_comp);
return files;
Expand Down
36 changes: 18 additions & 18 deletions xml_converter/src/xml_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ map<string, vector<string>> read_taco_directory(
if (!filesystem::exists(input_path)) {
cout << "Error: " << input_path << " is not an existing directory or file" << endl;
}
else if (filesystem::is_directory(input_path)) {
string directory_name = filesystem::path(input_path).filename();
vector<MarkerPackFile> xml_files = get_files_by_suffix(input_path, ".xml");
for (const MarkerPackFile& path : xml_files) {
set<string> top_level_category_names = parse_xml_file(path, marker_categories, parsed_pois);
string relative_path = join_file_paths(directory_name, path.relative_filepath);
for (set<string>::iterator it = top_level_category_names.begin(); it != top_level_category_names.end(); it++) {
top_level_category_file_locations[*it].push_back(relative_path);
}

string directory_name = filesystem::path(input_path).filename();
vector<MarkerPackFile> xml_files = get_files_by_suffix(input_path, ".xml");
for (const MarkerPackFile& path : xml_files) {
set<string> top_level_category_names = parse_xml_file(path, marker_categories, parsed_pois);
string relative_path = join_file_paths(directory_name, path.relative_filepath);
for (set<string>::iterator it = top_level_category_names.begin(); it != top_level_category_names.end(); it++) {
top_level_category_file_locations[*it].push_back(relative_path);
}
}

return top_level_category_file_locations;
}

Expand All @@ -63,17 +63,17 @@ map<string, vector<string>> read_burrito_directory(
if (!filesystem::exists(input_path)) {
cout << "Error: " << input_path << " is not an existing directory or file" << endl;
}
else if (filesystem::is_directory(input_path)) {
string directory_name = filesystem::path(input_path).filename();
vector<MarkerPackFile> burrito_files = get_files_by_suffix(input_path, ".guildpoint");
for (const MarkerPackFile& path : burrito_files) {
set<string> top_level_category_names = read_protobuf_file(path, marker_categories, parsed_pois);
string relative_path = join_file_paths(directory_name, path.relative_filepath);
for (set<string>::iterator it = top_level_category_names.begin(); it != top_level_category_names.end(); it++) {
top_level_category_file_locations[*it].push_back(relative_path);
}

string directory_name = filesystem::path(input_path).filename();
vector<MarkerPackFile> burrito_files = get_files_by_suffix(input_path, ".guildpoint");
for (const MarkerPackFile& path : burrito_files) {
set<string> top_level_category_names = read_protobuf_file(path, marker_categories, parsed_pois);
string relative_path = join_file_paths(directory_name, path.relative_filepath);
for (set<string>::iterator it = top_level_category_names.begin(); it != top_level_category_names.end(); it++) {
top_level_category_file_locations[*it].push_back(relative_path);
}
}

return top_level_category_file_locations;
}

Expand Down

0 comments on commit 13ed5c1

Please sign in to comment.