Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix LocalCache so that models/worlds downloaded via fuel.ignitionrobotics.org can be found in the cache #406

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions src/LocalCache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,23 @@ Model LocalCache::MatchingModel(const ModelIdentifier &_id)
// For the tip, we have to find the highest version
bool tip = (_id.Version() == 0);
Model tipModel;
if (!this->dataPtr->config)
return tipModel;

for (ModelIter iter = this->AllModels(); iter; ++iter)
std::string path = common::joinPaths(
this->dataPtr->config->CacheLocation(), uriToPath(_id.Server().Url()));

auto srvModels = this->dataPtr->ModelsInServer(path);
for (auto &model: srvModels)
{
ModelIdentifier id = iter->Identification();
model.dataPtr->id.SetServer(_id.Server());
auto id = model.Identification();
if (_id == id)
{
if (_id.Version() == id.Version())
return *iter;
return model;
else if (tip && id.Version() > tipModel.Identification().Version())
tipModel = *iter;
tipModel = model;
}
}

Expand All @@ -302,16 +309,24 @@ bool LocalCache::MatchingWorld(WorldIdentifier &_id) const
bool tip = (_id.Version() == 0);
WorldIdentifier tipWorld;

for (auto id = this->AllWorlds(); id; ++id)
if (!this->dataPtr->config)
return false;

std::string path = common::joinPaths(
this->dataPtr->config->CacheLocation(), uriToPath(_id.Server().Url()));

auto srvWorlds = this->dataPtr->WorldsInServer(path);
for (auto id: srvWorlds)
{
id.SetServer(_id.Server());
if (_id == id)
{
if (_id.Version() == id->Version())
if (_id.Version() == id.Version())
{
_id = id;
return true;
}
else if (tip && id->Version() > tipWorld.Version())
else if (tip && id.Version() > tipWorld.Version())
{
tipWorld = id;
}
Expand Down
Loading