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:
parent
aa7cea405b
commit
d01d261f0e
@ -43,6 +43,7 @@
|
|||||||
#include "pbd/unwind.h"
|
#include "pbd/unwind.h"
|
||||||
#include "pbd/xml++.h"
|
#include "pbd/xml++.h"
|
||||||
|
|
||||||
|
#include "ardour/filename_extensions.h"
|
||||||
#include "ardour/filesystem_paths.h"
|
#include "ardour/filesystem_paths.h"
|
||||||
#include "ardour/search_paths.h"
|
#include "ardour/search_paths.h"
|
||||||
#include "ardour/revision.h"
|
#include "ardour/revision.h"
|
||||||
@ -462,13 +463,24 @@ UIConfiguration::save_state()
|
|||||||
|
|
||||||
if (_dirty) {
|
if (_dirty) {
|
||||||
std::string rcfile = Glib::build_filename (user_config_directory(), ui_config_file_name);
|
std::string rcfile = Glib::build_filename (user_config_directory(), ui_config_file_name);
|
||||||
|
std::string tmp = rcfile + temp_suffix;
|
||||||
|
|
||||||
XMLTree tree;
|
XMLTree tree;
|
||||||
|
|
||||||
tree.set_root (&get_state());
|
tree.set_root (&get_state());
|
||||||
|
|
||||||
if (!tree.write (rcfile.c_str())){
|
if (!tree.write (tmp.c_str())){
|
||||||
error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user