diff --git a/src/fileio.cpp b/src/fileio.cpp index aef3c1844e..b0edd86b5c 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -87,6 +87,8 @@ static void FillValidSearchPaths(bool only_local_path) std::set seen{}; for (Searchpath sp = SP_FIRST_DIR; sp < NUM_SEARCHPATHS; sp++) { + if (sp == SP_WORKING_DIR) continue; + if (only_local_path) { switch (sp) { case SP_WORKING_DIR: // Can be influence by "-c" option. @@ -105,6 +107,13 @@ static void FillValidSearchPaths(bool only_local_path) _valid_searchpaths.emplace_back(sp); } } + + /* The working-directory is special, as it is controlled by _do_scan_working_directory. + * Only add the search path if it isn't already in the set. To preserve the same order + * as the enum, insert it in the front. */ + if (IsValidSearchPath(SP_WORKING_DIR) && seen.count(_searchpaths[SP_WORKING_DIR]) == 0) { + _valid_searchpaths.insert(_valid_searchpaths.begin(), SP_WORKING_DIR); + } } /**