From 90e10697a23e443cd2fa0647c85db36d6a8bbf52 Mon Sep 17 00:00:00 2001 From: John Shepherd Date: Tue, 6 Oct 2020 22:49:57 -0700 Subject: [PATCH] Add support for model config dependencies Signed-off-by: John Shepherd --- src/FuelClient.cc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/FuelClient.cc b/src/FuelClient.cc index 20aa9c87..36a7fc02 100644 --- a/src/FuelClient.cc +++ b/src/FuelClient.cc @@ -694,6 +694,8 @@ Result FuelClient::DownloadModel(const ModelIdentifier &_id, { std::string metadataPath = ignition::common::joinPaths(path, "metadata.pbtxt"); + std::string modelConfigPath = + ignition::common::joinPaths(path, "model.config"); if (ignition::common::exists(metadataPath)) { // Read the pbtxt file. @@ -704,6 +706,28 @@ Result FuelClient::DownloadModel(const ModelIdentifier &_id, // Parse the file into the fuel metadata message google::protobuf::TextFormat::ParseFromString(inputStr, &meta); + for (int i = 0; i < meta.dependencies_size(); i++) + { + std::string dependencyPath; + ignition::common::URI dependencyURI(meta.dependencies(i).uri()); + + // If the model is not already cached, download it; this prevents + // any sort of cyclic dependencies fromo running infinitely + if (!this->CachedModel(dependencyURI, dependencyPath)) + this->DownloadModel(dependencyURI, dependencyPath); + } + } + else if (ignition::common::exists(modelConfigPath)) + { + std::ifstream inputFile(modelConfigPath); + std::string inputStr((std::istreambuf_iterator(inputFile)), + std::istreambuf_iterator()); + + if (!ignition::msgs::ConvertFuelMetadata(inputStr, meta)) + { + return Result(ResultType::UPLOAD_ERROR); + } + for (int i = 0; i < meta.dependencies_size(); i++) { std::string dependencyPath;