ENH: backup: add logic to cleanup directory under cli

Change-Id: I7a846e362f45d1c7e34bef59be3b2c312799d0d2
This commit is contained in:
lane.wei 2023-02-22 11:46:12 +08:00 committed by Lane.Wei
parent dbe61652c7
commit 6fab32c98b
3 changed files with 29 additions and 1 deletions

View file

@ -311,11 +311,17 @@ static PrinterTechnology get_printer_technology(const DynamicConfig &config)
g_cli_callback_mgr.stop();\
boost::nowide::cout.flush();\
boost::nowide::cerr.flush();\
for (Model &model : m_models) {\
model.remove_backup_path_if_exist();\
}\
return(ret);}
#else
#define flush_and_exit(ret) { boost::nowide::cout << __FUNCTION__ << " found error, exit" << std::endl;\
boost::nowide::cout.flush();\
boost::nowide::cerr.flush();\
for (Model &model : m_models) {\
model.remove_backup_path_if_exist();\
}\
return(ret);}
#endif
@ -2371,6 +2377,9 @@ int CLI::run(int argc, char **argv)
g_cli_callback_mgr.stop();
#endif
for (Model &model : m_models) {
model.remove_backup_path_if_exist();
}
//BBS: flush logs
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", Finished" << std::endl;
boost::nowide::cout.flush();

View file

@ -790,9 +790,11 @@ std::string Model::get_backup_path()
buf << this->id().id;
backup_path = parent_path.string() + buf.str();
BOOST_LOG_TRIVIAL(info) << boost::format("model %1%, id %2%, backup_path empty, set to %3%")%this%this->id().id%backup_path;
boost::filesystem::path temp_path(backup_path);
if (boost::filesystem::exists(temp_path))
{
BOOST_LOG_TRIVIAL(info) << boost::format("model %1%, id %2%, remove previous %3%")%this%this->id().id%backup_path;
boost::filesystem::remove_all(temp_path);
}
}
@ -815,6 +817,19 @@ std::string Model::get_backup_path()
return backup_path;
}
void Model::remove_backup_path_if_exist()
{
if (!backup_path.empty()) {
boost::filesystem::path temp_path(backup_path);
if (boost::filesystem::exists(temp_path))
{
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format("model %1%, id %2% remove backup_path %3%")%this%this->id().id%backup_path;
boost::filesystem::remove_all(temp_path);
}
backup_path.clear();
}
}
std::string Model::get_backup_path(const std::string &sub_path)
{
auto path = get_backup_path() + "/" + sub_path;
@ -837,9 +852,12 @@ void Model::set_backup_path(std::string const& path)
backup_path.clear();
return;
}
if (!backup_path.empty())
if (!backup_path.empty()) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__<<boost::format(", model %1%, id %2%, remove previous backup %3%")%this%this->id().id%backup_path;
Slic3r::remove_backup(*this, true);
}
backup_path = path;
BOOST_LOG_TRIVIAL(info) << __FUNCTION__<<boost::format(", model %1%, id %2%, set backup to %3%")%this%this->id().id%backup_path;
}
void Model::load_from(Model& model)

View file

@ -1433,6 +1433,7 @@ public:
void load_from(Model & model);
bool is_need_backup() { return need_backup; }
void set_need_backup();
void remove_backup_path_if_exist();
// Checks if any of objects is painted using the fdm support painting gizmo.
bool is_fdm_support_painted() const;