diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-03-05 00:47:09 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-03-05 23:52:14 +0100 |
| commit | f3d37cc0ad95cc8e6d71246dd842e6e1d9e7b06c (patch) | |
| tree | 437f12ac752147e427c0ecdf9e05972142d6daa9 /src/lib/find_missing.cc | |
| parent | 474e13cf51457a51a6870c324e77ca30290a0d28 (diff) | |
Extract some bits from search_by_name().
Diffstat (limited to 'src/lib/find_missing.cc')
| -rw-r--r-- | src/lib/find_missing.cc | 39 |
1 files changed, 26 insertions, 13 deletions
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<shared_ptr<const Content>, vector<boost::filesystem::path>> 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(); } } |
