From 84ab0601173b2b359c3b075dfda73b7639660802 Mon Sep 17 00:00:00 2001 From: Steve Cotton Date: Fri, 20 Dec 2019 23:28:57 +0100 Subject: [PATCH] Log a warning if a file is found in more than one [binary_path] The Boost-based C++ unit tests generate three messages about duplicates, however as those tests don't run in strict mode this doesn't cause a failure (and it's not the only warning-level message in those tests). (cherry picked from commit 0bbbdff1906bba10069c5a8b0e261fb7a469fb88) --- src/filesystem.cpp | 10 ++++++++-- src/tests/test_filesystem.cpp | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/filesystem.cpp b/src/filesystem.cpp index f4aab82f9b8..d83a08b5166 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -1428,6 +1428,7 @@ std::string get_binary_file_location(const std::string& type, const std::string& return std::string(); } + std::string result; for(const std::string& bp : get_binary_paths(type)) { bfs::path bpath(bp); bpath /= filename; @@ -1436,12 +1437,17 @@ std::string get_binary_file_location(const std::string& type, const std::string& if(file_exists(bpath)) { DBG_FS << " found at '" << bpath.string() << "'\n"; - return bpath.string(); + if(result.empty()) { + result = bpath.string(); + } else { + WRN_FS << "Conflicting files in binary_path: '" << sanitize_path(result) + << "' and '" << sanitize_path(bpath.string()) << "'\n"; + } } } DBG_FS << " not found\n"; - return std::string(); + return result; } std::string get_binary_dir_location(const std::string& type, const std::string& filename) diff --git a/src/tests/test_filesystem.cpp b/src/tests/test_filesystem.cpp index 38da37cd234..47cf9df4ba0 100644 --- a/src/tests/test_filesystem.cpp +++ b/src/tests/test_filesystem.cpp @@ -142,6 +142,9 @@ BOOST_AUTO_TEST_CASE( test_fs_binary_path ) { BOOST_CHECK_EQUAL( get_binary_dir_location("images", "."), gamedata + "/images/." ); + // This test depends on get_binary_file_location() deterministically choosing + // which order to search the [binary_path] entries, as there are four "images" + // directories that could match. BOOST_CHECK_EQUAL( get_binary_file_location("images", "././././././"), gamedata + "/images/././././././" );