13
0

Safe ui-config file saving

This prevents corrupt ui-config files in case the disk is full.
This is a safeguard, since Ardour does not start if the
config file is corrupt.
This commit is contained in:
Robin Gareus 2021-07-06 21:12:30 +02:00
parent aa7cea405b
commit d01d261f0e
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04

View File

@ -43,6 +43,7 @@
#include "pbd/unwind.h"
#include "pbd/xml++.h"
#include "ardour/filename_extensions.h"
#include "ardour/filesystem_paths.h"
#include "ardour/search_paths.h"
#include "ardour/revision.h"
@ -462,13 +463,24 @@ UIConfiguration::save_state()
if (_dirty) {
std::string rcfile = Glib::build_filename (user_config_directory(), ui_config_file_name);
std::string tmp = rcfile + temp_suffix;
XMLTree tree;
tree.set_root (&get_state());
if (!tree.write (rcfile.c_str())){
error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
if (!tree.write (tmp.c_str())){
error << string_compose (_("Config file %1 not saved"), tmp) << endmsg;
if (g_remove (tmp.c_str()) != 0) {
error << string_compose(_("Could not remove temporary ui-config file \"%1\" (%2)"), tmp, g_strerror (errno)) << endmsg;
}
return -1;
}
if (::g_rename (tmp.c_str(), rcfile.c_str()) != 0) {
error << string_compose (_("could not rename temporary ui-config file %1 to %2 (%3)"), tmp, rcfile, g_strerror(errno)) << endmsg;
if (g_remove (tmp.c_str()) != 0) {
error << string_compose(_("Could not remove temporary ui-config file \"%1\" (%2)"), tmp, g_strerror (errno)) << endmsg;
}
return -1;
}