Skip to content

Commit

Permalink
Check if lookupDir exists before iterating
Browse files Browse the repository at this point in the history
std::filesystem::recursive_directory_iterator throws if the directory
doesn't exist.
  • Loading branch information
syyyr committed Nov 20, 2023
1 parent a631070 commit 1d1db8e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions libosmscout-client/src/osmscoutclient/MapManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ CancelableFuture<bool> MapManager::LookupDatabases()
std::vector<std::filesystem::path> databaseFsDirectories;

for (const auto &lookupDir:databaseLookupDirs){
// Symlinks are automatically resolved when using exists() and is_directory().
// https://en.cppreference.com/w/cpp/filesystem/exists
// https://en.cppreference.com/w/cpp/filesystem/is_directory
// https://en.cppreference.com/w/cpp/filesystem/status
if (!std::filesystem::exists(lookupDir) || !std::filesystem::is_directory(lookupDir)) {
osmscout::log.Warn() << "Lookup dir" << lookupDir.string() << "doesn't exist or isn't a directory";
continue;
}

for (const auto & fInfo : std::filesystem::recursive_directory_iterator(lookupDir)) {
auto entryPath = fInfo.path();
if (fInfo.is_regular_file() && entryPath.has_filename() && entryPath.has_parent_path() && entryPath.filename() == TypeConfig::FILE_TYPES_DAT){
Expand Down

0 comments on commit 1d1db8e

Please sign in to comment.