Skip to content

Commit

Permalink
Fix local cache so that models/worlds downloaded via fuel.ignitionrob…
Browse files Browse the repository at this point in the history
…otics.org can be found in the cache

Signed-off-by: Addisu Z. Taddese <[email protected]>
  • Loading branch information
azeey committed Mar 16, 2024
1 parent 8b4ead3 commit a59c107
Showing 1 changed file with 22 additions and 7 deletions.
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

0 comments on commit a59c107

Please sign in to comment.