Fixing horrendous error in destructor.

This commit is contained in:
tamasmeszaros 2019-03-27 13:22:04 +01:00
parent ccafc43874
commit c332dc1c1d
4 changed files with 29 additions and 10 deletions

View file

@ -266,6 +266,8 @@ public:
m_layers_rst[i].rawbytes.size());
}
}
writer.close();
} catch(std::exception& e) {
BOOST_LOG_TRIVIAL(error) << e.what();
// Rethrow the exception

View file

@ -231,7 +231,7 @@ public:
return true; // m_zip blows up if something goes wrong...
}
inline void close() { /* m_zip closes upon destruction */ }
inline void close() { m_zip.close(); }
};
/**

View file

@ -5,6 +5,7 @@
#include "Zipper.hpp"
#include "miniz/miniz_zip.h"
#include <boost/filesystem/path.hpp>
#include <boost/log/trivial.hpp>
#include "I18N.hpp"
@ -25,7 +26,7 @@ public:
mz_zip_archive arch;
std::string m_zipname;
std::string get_errorstr(mz_zip_error mz_err)
static std::string get_errorstr(mz_zip_error mz_err)
{
switch (mz_err)
{
@ -100,10 +101,15 @@ public:
return "unknown error";
}
SLIC3R_NORETURN void blow_up() {
std::string prefix(L("Error with zip archive"));
throw std::runtime_error(prefix + " " + m_zipname + ": " +
get_errorstr(arch.m_last_error) + "!");
std::string formatted_errorstr() const
{
return L("Error with zip archive") + " " + m_zipname + ": " +
get_errorstr(arch.m_last_error) + "!";
}
SLIC3R_NORETURN void blow_up() const
{
throw std::runtime_error(formatted_errorstr());
}
};
@ -123,10 +129,11 @@ Zipper::Zipper(const std::string &zipfname, e_compression compression)
Zipper::~Zipper()
{
finish_entry();
if(!mz_zip_writer_finalize_archive(&m_impl->arch)) m_impl->blow_up();
if(!mz_zip_writer_end(&m_impl->arch)) m_impl->blow_up();
try {
close();
} catch(...) {
BOOST_LOG_TRIVIAL(error) << m_impl->formatted_errorstr();
}
}
Zipper::Zipper(Zipper &&m):
@ -191,4 +198,12 @@ std::string Zipper::get_name() const {
return boost::filesystem::path(m_impl->m_zipname).stem().string();
}
void Zipper::close()
{
finish_entry();
if(!mz_zip_writer_finalize_archive(&m_impl->arch)) m_impl->blow_up();
if(!mz_zip_writer_end(&m_impl->arch)) m_impl->blow_up();
}
}

View file

@ -78,6 +78,8 @@ public:
/// Gets the name of the archive without the path or extension.
std::string get_name() const;
void close();
};