summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-12-21 02:35:55 +0100
committerCarl Hetherington <cth@carlh.net>2021-12-24 15:36:15 +0100
commitb502b5723f4516bfd33c17a6b71a72831933d212 (patch)
tree5027413035a12dcba5e9ca90a005ffd202745b44 /src
parent453410542a8721bb65b6295a5286524266f3fee8 (diff)
Tidy up backing up of config files, improve the tests a little and fix it for the
case when the user has specified their own config file path.
Diffstat (limited to 'src')
-rw-r--r--src/lib/config.cc36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/lib/config.cc b/src/lib/config.cc
index 419436995..5496c0b3c 100644
--- a/src/lib/config.cc
+++ b/src/lib/config.cc
@@ -125,6 +125,9 @@ Config::set_defaults ()
#ifdef DCPOMATIC_WINDOWS
_win32_console = false;
#endif
+ /* At the moment we don't write these files anywhere new after a version change, so they will be read from
+ * ~/.config/dcpomatic2 (or equivalent) and written back there.
+ */
_cinemas_file = read_path ("cinemas.xml");
_dkdm_recipients_file = read_path ("dkdm_recipients.xml");
_show_hints_before_make_dcp = true;
@@ -212,16 +215,37 @@ Config::create_certificate_chain ()
void
Config::backup ()
{
- /* Make a copy of the configuration */
- try {
+ using namespace boost::filesystem;
+
+ auto copy_adding_number = [](path const& path_to_copy) {
+
+ auto add_number = [](path const& path, int number) {
+ return String::compose("%1.%2", path, number);
+ };
+
int n = 1;
- while (n < 100 && boost::filesystem::exists(write_path(String::compose("config.xml.%1", n)))) {
+ while (n < 100 && exists(add_number(path_to_copy, n))) {
++n;
}
+ copy_file(path_to_copy, add_number(path_to_copy, n));
+ };
- boost::filesystem::copy_file(read_path("config.xml"), write_path(String::compose("config.xml.%1", n)));
- boost::filesystem::copy_file(read_path("cinemas.xml"), write_path(String::compose("cinemas.xml.%1", n)));
- boost::filesystem::copy_file(read_path("dkdm_recipients.xml"), write_path(String::compose("dkdm_recipients.xml.%1", n)));
+ /* Make a backup copy of any config.xml, cinemas.xml, dkdm_recipients.xml that we might be about
+ * to write over. This is more intended for the situation where we have a corrupted config.xml,
+ * and decide to overwrite it with a new one (possibly losing important details in the corrupted
+ * file). But we might as well back up the other files while we're about it.
+ */
+ try {
+ /* This uses the State::write_path stuff so, e.g. for a current version 2.16 we might copy
+ * ~/.config/dcpomatic2/2.16/config.xml to ~/.config/dcpomatic2/2.16/config.xml.1
+ */
+ copy_adding_number (config_write_file());
+
+ /* These do not use State::write_path, so whatever path is in the Config we will copy
+ * adding a number.
+ */
+ copy_adding_number (_cinemas_file);
+ copy_adding_number (_dkdm_recipients_file);
} catch (...) {}
}