Find missing files better in projects coming from other platforms (#2935).
authorCarl Hetherington <cth@carlh.net>
Sun, 19 Jan 2025 21:23:05 +0000 (22:23 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 19 Jan 2025 21:23:05 +0000 (22:23 +0100)
src/lib/find_missing.cc
test/data
test/find_missing_test.cc

index 65776d02e9b1fe6e0c37d0505b7a694cbc520a75..af91b3682cbaa2b48cce3886666a0f8b4a7239ae 100644 (file)
@@ -27,6 +27,7 @@
 
 using std::map;
 using std::shared_ptr;
+using std::string;
 using std::vector;
 
 
@@ -42,7 +43,19 @@ search_by_name(Replacements& replacement_paths, boost::filesystem::path director
                if (dcp::filesystem::is_regular_file(candidate.path())) {
                        for (auto& replacement: replacement_paths) {
                                for (auto& path: replacement.second) {
-                                       if (!dcp::filesystem::exists(path) && path.filename() == candidate.path().filename()) {
+                                       /* Extract a filename as if this path were from a platform with a different
+                                        * separator.
+                                        */
+                                       string other = path.string();
+#ifdef DCPOMATIC_POSIX
+                                       std::replace(other.begin(), other.end(), '\\', '/');
+#else
+                                       std::replace(other.begin(), other.end(), '/', '\\');
+#endif
+                                       boost::filesystem::path other_path(other);
+                                       if (
+                                               !dcp::filesystem::exists(path) &&
+                                               (path.filename() == candidate.path().filename() || other_path.filename() == candidate.path().filename())) {
                                                path = candidate.path();
                                        }
                                }
index 8cf2d01f470c8e5be3ab4a241dd88236c041a5c0..6a0da3e92abf6f6fd2f7b5dfd5f03eee44c585e4 160000 (submodule)
--- a/test/data
+++ b/test/data
@@ -1 +1 @@
-Subproject commit 8cf2d01f470c8e5be3ab4a241dd88236c041a5c0
+Subproject commit 6a0da3e92abf6f6fd2f7b5dfd5f03eee44c585e4
index 809a8f864a7d9b709a51f3b1d2f353b5ea3ba841..94c2fc53bd92282781791cdb4e82b7113d2086db 100644 (file)
@@ -197,3 +197,26 @@ BOOST_AUTO_TEST_CASE(find_missing_test_with_rename)
 
 }
 
+
+BOOST_AUTO_TEST_CASE(test_film_saved_on_windows)
+{
+       auto film = make_shared<Film>(boost::filesystem::path("test/data/windows_film"));
+       film->read_metadata();
+       dcpomatic::find_missing(film->content(), TestPaths::private_data());
+
+       for (auto content: film->content()) {
+               BOOST_CHECK(content->paths_valid());
+       }
+}
+
+
+BOOST_AUTO_TEST_CASE(test_film_saved_on_posix)
+{
+       auto film = make_shared<Film>(boost::filesystem::path("test/data/posix_film"));
+       film->read_metadata();
+       dcpomatic::find_missing(film->content(), TestPaths::private_data());
+
+       for (auto content: film->content()) {
+               BOOST_CHECK(content->paths_valid());
+       }
+}