mirror of
https://git.mirrors.martin98.com/https://github.com/bambulab/BambuStudio.git
synced 2025-09-22 21:33:16 +08:00
FIX: save backup mesh with temp file safely
Change-Id: I39ed281e271add443c41cb177d203f0b0decf2b6
This commit is contained in:
parent
2ecdf43ca1
commit
71d81ad78b
@ -3863,18 +3863,38 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result)
|
|||||||
|
|
||||||
auto filename = boost::format("3D/Objects/%s_%d.model") % object.name % obj_id;
|
auto filename = boost::format("3D/Objects/%s_%d.model") % object.name % obj_id;
|
||||||
std::string filepath = temp_path + "/" + filename.str();
|
std::string filepath = temp_path + "/" + filename.str();
|
||||||
if (!open_zip_writer(&archive, filepath)) {
|
std::string filepath_tmp = filepath + ".tmp";
|
||||||
|
boost::system::error_code ec;
|
||||||
|
boost::filesystem::remove(filepath_tmp, ec);
|
||||||
|
if (!open_zip_writer(&archive, filepath_tmp)) {
|
||||||
add_error("Unable to open the file");
|
add_error("Unable to open the file");
|
||||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":" << __LINE__ << boost::format(", Unable to open the file\n");
|
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":" << __LINE__ << boost::format(", Unable to open the file\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct close_lock
|
||||||
|
{
|
||||||
|
mz_zip_archive & archive;
|
||||||
|
std::string const * filename;
|
||||||
|
void close() {
|
||||||
|
close_zip_writer(&archive);
|
||||||
|
filename = nullptr;
|
||||||
|
}
|
||||||
|
~close_lock() {
|
||||||
|
if (filename) {
|
||||||
|
close_zip_writer(&archive);
|
||||||
|
boost::filesystem::remove(*filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} lock{archive, &filepath_tmp};
|
||||||
|
|
||||||
IdToObjectDataMap objects_data;
|
IdToObjectDataMap objects_data;
|
||||||
objects_data.insert({obj_id, {&object, obj_id}});
|
objects_data.insert({obj_id, {&object, obj_id}});
|
||||||
_add_model_file_to_archive(filename.str(), archive, model, objects_data);
|
_add_model_file_to_archive(filename.str(), archive, model, objects_data);
|
||||||
|
|
||||||
mz_zip_writer_finalize_archive(&archive);
|
mz_zip_writer_finalize_archive(&archive);
|
||||||
close_zip_writer(&archive);
|
lock.close();
|
||||||
|
boost::filesystem::rename(filepath_tmp, filepath, ec);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user