Fix search path de-duplication changing search path order
This commit is contained in:
@@ -64,6 +64,7 @@ static_assert(lengthof(_subdirs) == NUM_SUBDIRS);
|
|||||||
*/
|
*/
|
||||||
std::array<std::string, NUM_SEARCHPATHS> _searchpaths;
|
std::array<std::string, NUM_SEARCHPATHS> _searchpaths;
|
||||||
std::vector<Searchpath> _valid_searchpaths;
|
std::vector<Searchpath> _valid_searchpaths;
|
||||||
|
std::vector<Searchpath> _valid_searchpaths_excluding_cwd;
|
||||||
std::array<TarList, NUM_SUBDIRS> _tar_list;
|
std::array<TarList, NUM_SUBDIRS> _tar_list;
|
||||||
TarFileList _tar_filelist[NUM_SUBDIRS];
|
TarFileList _tar_filelist[NUM_SUBDIRS];
|
||||||
|
|
||||||
@@ -85,11 +86,11 @@ static bool IsValidSearchPath(Searchpath sp)
|
|||||||
static void FillValidSearchPaths(bool only_local_path)
|
static void FillValidSearchPaths(bool only_local_path)
|
||||||
{
|
{
|
||||||
_valid_searchpaths.clear();
|
_valid_searchpaths.clear();
|
||||||
|
_valid_searchpaths_excluding_cwd.clear();
|
||||||
|
|
||||||
btree::btree_set<std::string_view> seen{};
|
btree::btree_set<std::string_view> seen{};
|
||||||
|
btree::btree_set<std::string_view> seen_excluding_cwd{};
|
||||||
for (Searchpath sp = SP_FIRST_DIR; sp < NUM_SEARCHPATHS; sp++) {
|
for (Searchpath sp = SP_FIRST_DIR; sp < NUM_SEARCHPATHS; sp++) {
|
||||||
if (sp == SP_WORKING_DIR) continue;
|
|
||||||
|
|
||||||
if (only_local_path) {
|
if (only_local_path) {
|
||||||
switch (sp) {
|
switch (sp) {
|
||||||
case SP_WORKING_DIR: // Can be influence by "-c" option.
|
case SP_WORKING_DIR: // Can be influence by "-c" option.
|
||||||
@@ -103,17 +104,15 @@ static void FillValidSearchPaths(bool only_local_path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (IsValidSearchPath(sp)) {
|
if (IsValidSearchPath(sp)) {
|
||||||
if (seen.count(_searchpaths[sp]) != 0) continue;
|
if (seen.count(_searchpaths[sp]) == 0) {
|
||||||
seen.insert(_searchpaths[sp]);
|
seen.insert(_searchpaths[sp]);
|
||||||
_valid_searchpaths.emplace_back(sp);
|
_valid_searchpaths.emplace_back(sp);
|
||||||
}
|
}
|
||||||
|
if (sp != SP_WORKING_DIR && seen_excluding_cwd.count(_searchpaths[sp]) == 0) {
|
||||||
|
seen_excluding_cwd.insert(_searchpaths[sp]);
|
||||||
|
_valid_searchpaths_excluding_cwd.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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1014,8 +1013,8 @@ void DeterminePaths(const char *exe, bool only_local_path)
|
|||||||
AppendPathSeparator(config_home);
|
AppendPathSeparator(config_home);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (Searchpath sp : _valid_searchpaths) {
|
const std::vector<Searchpath> &vsp = _do_scan_working_directory ? _valid_searchpaths : _valid_searchpaths_excluding_cwd;
|
||||||
if (sp == SP_WORKING_DIR && !_do_scan_working_directory) continue;
|
for (Searchpath sp : vsp) {
|
||||||
DEBUG(misc, 3, "%s added as search path", _searchpaths[sp].c_str());
|
DEBUG(misc, 3, "%s added as search path", _searchpaths[sp].c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1246,10 +1245,8 @@ uint FileScanner::Scan(const char *extension, Subdirectory sd, bool tars, bool r
|
|||||||
|
|
||||||
uint num = 0;
|
uint num = 0;
|
||||||
|
|
||||||
for (Searchpath sp : _valid_searchpaths) {
|
const std::vector<Searchpath> &vsp = _do_scan_working_directory ? _valid_searchpaths : _valid_searchpaths_excluding_cwd;
|
||||||
/* Don't search in the working directory */
|
for (Searchpath sp : vsp) {
|
||||||
if (sp == SP_WORKING_DIR && !_do_scan_working_directory) continue;
|
|
||||||
|
|
||||||
std::string path = FioGetDirectory(sp, sd);
|
std::string path = FioGetDirectory(sp, sd);
|
||||||
num += ScanPath(this, extension, path.c_str(), path.size(), recursive);
|
num += ScanPath(this, extension, path.c_str(), path.size(), recursive);
|
||||||
}
|
}
|
||||||
|
@@ -35,6 +35,7 @@ bool ExtractTar(const std::string &tar_filename, Subdirectory subdir);
|
|||||||
|
|
||||||
extern std::string _personal_dir; ///< custom directory for personal settings, saves, newgrf, etc.
|
extern std::string _personal_dir; ///< custom directory for personal settings, saves, newgrf, etc.
|
||||||
extern std::vector<Searchpath> _valid_searchpaths;
|
extern std::vector<Searchpath> _valid_searchpaths;
|
||||||
|
extern std::vector<Searchpath> _valid_searchpaths_excluding_cwd;
|
||||||
|
|
||||||
/** Helper for scanning for files with a given name */
|
/** Helper for scanning for files with a given name */
|
||||||
class FileScanner {
|
class FileScanner {
|
||||||
|
Reference in New Issue
Block a user