diff options
| author | Carl Hetherington <cth@carlh.net> | 2024-05-13 23:25:25 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2024-05-13 23:27:08 +0200 |
| commit | 8aa25e2ec75dada5f07a3860d668241821056f61 (patch) | |
| tree | a534401a90c31f24fc157ad9f57c6878edf95b1d | |
| parent | d2c665cba983c625933817e0bf05e298f80f0119 (diff) | |
Fix case where both XML and sqlite3 files are present, and config.xml still refers to the XML.
Then we would leave the config.xml pointing at the XML, and everything
after that assumes that cinemas_file is sqlite3. Instead we always set
the cinemas file to the sqlite3 version, and convert if it it wasn't
there before.
| -rw-r--r-- | src/lib/config.cc | 6 | ||||
| -rw-r--r-- | test/config_test.cc | 41 |
2 files changed, 45 insertions, 2 deletions
diff --git a/src/lib/config.cc b/src/lib/config.cc index 02ae7880f..374605521 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -686,9 +686,11 @@ Config::instance () if (cinemas_file.extension() == ".xml") { auto sqlite = cinemas_file; sqlite.replace_extension(".sqlite3"); + bool const had_sqlite = dcp::filesystem::exists(sqlite); - if (dcp::filesystem::exists(cinemas_file) && !dcp::filesystem::exists(sqlite)) { - _instance->set_cinemas_file(sqlite); + _instance->set_cinemas_file(sqlite); + + if (dcp::filesystem::exists(cinemas_file) && !had_sqlite) { CinemaList cinemas; cinemas.read_legacy_file(cinemas_file); } diff --git a/test/config_test.cc b/test/config_test.cc index 1c35f0a78..6c7a3323d 100644 --- a/test/config_test.cc +++ b/test/config_test.cc @@ -532,3 +532,44 @@ BOOST_AUTO_TEST_CASE(load_config_from_zip_with_only_xml_ignore) auto cinemas = cinema_list.cinemas(); BOOST_CHECK(!cinemas.empty()); } + + +BOOST_AUTO_TEST_CASE(use_sqlite_if_present) +{ + ConfigRestorer cr; + + /* 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.xml", + boost::filesystem::canonical(dir / "cinemas.xml").string() + ); + } + + Config::override_path = dir; + Config::drop(); + + /* 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")); + + Config::drop(); + + BOOST_CHECK(Config::instance()->cinemas_file() == boost::filesystem::canonical(dir / "cinemas.sqlite3")); +} + + + |
