Skip to content

Commit

Permalink
BRAYNS-588 Check morphology path validation. (#1209)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrien4193 committed Nov 2, 2023
1 parent b4f9d54 commit 6c21d01
Showing 1 changed file with 5 additions and 26 deletions.
31 changes: 5 additions & 26 deletions plugins/CircuitExplorer/io/sonataloader/data/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,9 @@ class MorphologyPathResolver
return it->second;
}

static bool isValid(const std::string &path, const std::string &extension)
static bool isValid(const std::string &path)
{
auto pathObject = std::filesystem::path(path);
if (!std::filesystem::is_directory(pathObject))
{
return false;
}

auto testExtension = "." + extension;
for (auto &item : std::filesystem::directory_iterator(pathObject))
{
if (!std::filesystem::is_regular_file(item))
{
continue;
}

auto &file = item.path();
auto fileExtension = file.extension().string();
if (fileExtension == testExtension)
{
return true;
}
}
return false;
return std::filesystem::is_directory(path);
}
};

Expand Down Expand Up @@ -184,19 +163,19 @@ MorphologyPath Config::getMorphologyPath(const std::string &populationName) cons
{
auto properties = _config.getNodePopulationProperties(populationName);

if (MorphologyPathResolver::isValid(properties.morphologiesDir, "swc"))
if (MorphologyPathResolver::isValid(properties.morphologiesDir))
{
return MorphologyPath(properties.morphologiesDir, MorphologyFormat::swc);
}

auto asciiPath = MorphologyPathResolver::getFormatPath(properties, MorphologyFormat::ascii);
if (MorphologyPathResolver::isValid(asciiPath, "asc"))
if (MorphologyPathResolver::isValid(asciiPath))
{
return MorphologyPath(asciiPath, "asc");
}

auto h5Path = MorphologyPathResolver::getFormatPath(properties, MorphologyFormat::h5);
if (MorphologyPathResolver::isValid(h5Path, "h5"))
if (MorphologyPathResolver::isValid(h5Path))
{
return MorphologyPath(h5Path, "h5");
}
Expand Down

0 comments on commit 6c21d01

Please sign in to comment.