From f3d37cc0ad95cc8e6d71246dd842e6e1d9e7b06c Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 5 Mar 2025 00:47:09 +0100 Subject: Extract some bits from search_by_name(). --- src/lib/find_missing.cc | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'src/lib') diff --git a/src/lib/find_missing.cc b/src/lib/find_missing.cc index 585a6e713..14394af04 100644 --- a/src/lib/find_missing.cc +++ b/src/lib/find_missing.cc @@ -34,6 +34,31 @@ using std::vector; typedef map, vector> Replacements; +/* Turn a path into one from the "other" platform (posix -> windows or vice versa) */ +static +boost::filesystem::path +path_from_other_platform(boost::filesystem::path path) +{ + string other = path.string(); +#ifdef DCPOMATIC_POSIX + std::replace(other.begin(), other.end(), '\\', '/'); +#else + std::replace(other.begin(), other.end(), '/', '\\'); +#endif + return boost::filesystem::path(other); +} + + +static +bool +should_replace(boost::filesystem::path old_path, boost::filesystem::path new_path) +{ + auto const other_path = path_from_other_platform(old_path); + return !dcp::filesystem::exists(old_path) && (old_path.filename() == new_path.filename() || other_path.filename() == new_path.filename()); +} + + + static void search_by_name(Replacements& replacement_paths, boost::filesystem::path directory, int depth = 0) @@ -43,19 +68,7 @@ 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) { - /* 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())) { + if (should_replace(path, candidate.path())) { path = candidate.path(); } } -- cgit v1.2.3