diff --git a/src/zip.cpp b/src/zip.cpp index 121b824..f2e458f 100644 --- a/src/zip.cpp +++ b/src/zip.cpp @@ -46,6 +46,7 @@ std::vector list(const fs::path &filepath) toc.emplace_back(archive_entry_pathname_utf8(entry)); archive_read_data_skip(zipfile); } + close_file(zipfile, filepath); return toc; @@ -69,12 +70,15 @@ std::string read_file(const fs::path &filepath, std::string_view entry_path) if (result_length != length) { + close_file(zipfile, filepath); + throw exception{ format(translate("Could not read {0:s} in {1:s}.").str(), entry_path, filepath.string())}; } close_file(zipfile, filepath); + return filecontents; } archive_read_data_skip(zipfile); @@ -95,6 +99,8 @@ struct archive *open_file(const fs::path &filepath) auto result{archive_read_open_filename(zipfile, filepath.c_str(), 10240)}; if (result != ARCHIVE_OK) { + close_file(zipfile, filepath); + throw exception{format(translate("Could not open {0:s}.").str(), filepath.string())}; }