diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-02-09 23:36:42 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-02-10 23:35:26 +0100 |
| commit | fa580d756b32cd46f735cbbdabc9218bb8df2560 (patch) | |
| tree | dfdf3c50e968cadb131202da0ad75ba98d5296b4 | |
| parent | 06a33b6d5114e4b9c76c2b98c3a6936fb9a4208a (diff) | |
Apply the same fix for DKDM recipients as we previously had for cinemas.
Otherwise the same problem happens with dkdm_recipients.xml - it is
moved to sqlite3 but the configuration still has the XML path, causing a
crash the next time we try to access the DKDM recipients list.
| -rw-r--r-- | src/lib/config.cc | 3 | ||||
| -rw-r--r-- | test/config_test.cc | 65 | ||||
| m--------- | test/data | 0 |
3 files changed, 38 insertions, 30 deletions
diff --git a/src/lib/config.cc b/src/lib/config.cc index 79584326c..dc33b26bc 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -714,8 +714,9 @@ Config::instance() auto sqlite = dkdm_recipients_file; sqlite.replace_extension(".sqlite3"); + _instance->set_dkdm_recipients_file(sqlite); + if (dcp::filesystem::exists(dkdm_recipients_file) && !dcp::filesystem::exists(sqlite)) { - _instance->set_dkdm_recipients_file(sqlite); DKDMRecipientList recipients; recipients.read_legacy_file(dkdm_recipients_file); } diff --git a/test/config_test.cc b/test/config_test.cc index a588691c6..a9b95bedf 100644 --- a/test/config_test.cc +++ b/test/config_test.cc @@ -347,8 +347,8 @@ BOOST_AUTO_TEST_CASE(read_dkdm_recipients_xml_and_write_sqlite) { Editor editor(dir / "2.18" / "config.xml"); editor.replace( - "build/test/config_upgrade_test/dkdm_recipients.xml", - boost::filesystem::canonical(dir / "dkdm_recipients.xml").string() + "<DKDMRecipientsFile>/home/realldoesnt/exist/this/path/is/nonsense.sqlite3", + string{"<DKDMRecipientsFile>"} + boost::filesystem::canonical(dir / "dkdm_recipients.xml").string() ); } @@ -520,36 +520,43 @@ BOOST_AUTO_TEST_CASE(load_config_from_zip_with_only_xml_ignore) BOOST_AUTO_TEST_CASE(use_sqlite_if_present) { - /* Set up a config with an XML cinemas file */ - boost::filesystem::path dir = "build/test/read_cinemas_xml_and_write_sqlite"; - boost::filesystem::remove_all(dir); - boost::filesystem::create_directories(dir); - boost::filesystem::create_directories(dir / "2.18"); - - boost::filesystem::copy_file("test/data/cinemas.xml", dir / "cinemas.xml"); - boost::filesystem::copy_file("test/data/2.18.config.xml", dir / "2.18" / "config.xml"); - { - Editor editor(dir / "2.18" / "config.xml"); - editor.replace( - "/home/realldoesnt/exist/this/path/is/nonsense.sqlite3", - boost::filesystem::canonical(dir / "cinemas.xml").string() - ); - } - - ConfigRestorer cr(dir); - - /* This should make a sqlite3 file containing the recipients from cinemas.xml. - * But it won't write config.xml, so config.xml will still point to cinemas.xml. - * This also happens in real life - but I'm not sure how (perhaps just when DoM is - * loaded but doesn't save the config, and then another tool is loaded). - */ - Config::instance(); + for (auto file: { string("cinemas"), string("dkdm_recipients") }) { + + /* Set up a config with an XML file */ + boost::filesystem::path dir = "build/test/use_sqlite_if_present"; + boost::filesystem::remove_all(dir); + boost::filesystem::create_directories(dir); + boost::filesystem::create_directories(dir / "2.18"); + + boost::filesystem::copy_file("test/data/cinemas.xml", dir / (file + ".xml")); + boost::filesystem::copy_file("test/data/2.18.config.xml", dir / "2.18" / "config.xml"); + { + Editor editor(dir / "2.18" / "config.xml"); + editor.replace( + "/home/realldoesnt/exist/this/path/is/nonsense.sqlite3", + boost::filesystem::canonical(dir / (file + ".xml")).string() + ); + } + + ConfigRestorer cr(dir); + + /* This should make a sqlite3 file containing the recipients from cinemas.xml. + * But it won't write config.xml, so config.xml will still point to cinemas.xml. + * This also happens in real life - but I'm not sure how (perhaps just when DoM is + * loaded but doesn't save the config, and then another tool is loaded). + */ + Config::instance(); - BOOST_CHECK(boost::filesystem::exists(dir / "cinemas.sqlite3")); + BOOST_CHECK(boost::filesystem::exists(dir / (file + ".sqlite3"))); - Config::drop(); + Config::drop(); - BOOST_CHECK(Config::instance()->cinemas_file() == boost::filesystem::canonical(dir / "cinemas.sqlite3")); + if (file == "cinemas") { + BOOST_CHECK(Config::instance()->cinemas_file() == boost::filesystem::canonical(dir / (file + ".sqlite3"))); + } else { + BOOST_CHECK(Config::instance()->dkdm_recipients_file() == boost::filesystem::canonical(dir / (file + ".sqlite3"))); + } + } } diff --git a/test/data b/test/data -Subproject 1e01eeb70531597223b7b8cdfe4f129c7d802ba +Subproject 51744f96aa9a56a7ccc8a64c612d42559b2f82e |
