Skip to content

Commit

Permalink
#810 Add a try/catch for the ZipInputStream::read() method
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitri Baron <[email protected]>
  • Loading branch information
barondim committed Jan 23, 2025
1 parent 5c6b1cd commit 84599e1
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion sources/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <libzip/ZipFileFactory.h>
#include <libzip/ZipInputStream.h>
#include <libzip/ZipOutputStream.h>
#include <libzip/ZipException.h>

#include <chrono>
#include <cstdlib>
Expand Down Expand Up @@ -204,7 +205,24 @@ int main(int argc, char *argv[]) {
boost::filesystem::path contingencyPath(runtimeConfig.contingenciesFilePath);
if (!runtimeConfig.zipArchivePath.empty()) {
if (mpiContext.isRootProc()) {
boost::shared_ptr<zip::ZipFile> archive = zip::ZipInputStream::read(runtimeConfig.zipArchivePath);
boost::shared_ptr<zip::ZipFile> archive;
try {
archive = zip::ZipInputStream::read(runtimeConfig.zipArchivePath);
} catch (const zip::ZipException& e) {
switch (e.getErrorCode()) {
case zip::Error::Code::LIBARCHIVE_INTERNAL_ERROR:
std::cerr << e.what() << " for the " << runtimeConfig.zipArchivePath << " archive" << std::endl;
return EXIT_FAILURE;
case zip::Error::Code::FILE_NOT_FOUND:
std::cerr << "File " << e.what() << " not found" << std::endl;
return EXIT_FAILURE;
default:
// other libzip errors
std::cerr << e.what() << std::endl;
return EXIT_FAILURE;
}
}

std::string archiveParentPath = boost::filesystem::path(runtimeConfig.zipArchivePath).parent_path().string();
for (std::map<std::string, boost::shared_ptr<zip::ZipEntry>>::const_iterator archiveIt = archive->getEntries().begin();
archiveIt != archive->getEntries().end(); ++archiveIt) {
Expand Down

0 comments on commit 84599e1

Please sign in to comment.