Skip to content

Commit

Permalink
Additional fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll committed Sep 20, 2023
1 parent aa8695c commit 42e9ee0
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/ClientConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class gz::fuel_tools::ServerConfigPrivate
}

/// \brief URL to reach server
public: common::URI url{"https://fuel.gazebosim.org"};
public: common::URI url{"https://fuel.gazebosim.org", true};

/// \brief A key to auth with the server
public: std::string key = "";
Expand Down
20 changes: 17 additions & 3 deletions src/FuelClient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,9 @@ Result FuelClient::DownloadModel(const ModelIdentifier &_id,
// Save
// Note that the save function doesn't return the path
if (zipData.empty() || !this->dataPtr->cache->SaveModel(newId, zipData, true))
{
return Result(ResultType::FETCH_ERROR);
}

return this->ModelDependencies(_id, _dependencies);
}
Expand Down Expand Up @@ -1236,7 +1238,11 @@ bool FuelClient::ParseModelFileUrl(const common::URI &_modelFileUrl,
}

// Get remaining server information from config
_id.Server().SetUrl(common::URI(scheme + "://" + server));
common::URI serverUri;
serverUri.SetScheme(scheme);
serverUri.SetAuthority(gz::common::URIAuthority("//" + server));

_id.Server().SetUrl(serverUri);
_id.Server().SetVersion(apiVersion);
for (const auto &s : this->dataPtr->config.Servers())
{
Expand Down Expand Up @@ -1305,7 +1311,11 @@ bool FuelClient::ParseWorldFileUrl(const common::URI &_worldFileUrl,
}

// Get remaining server information from config
_id.Server().SetUrl(common::URI(scheme + "://" + server));
common::URI serverUri;
serverUri.SetScheme(scheme);
serverUri.SetAuthority(gz::common::URIAuthority("//" + server));

_id.Server().SetUrl(serverUri);
_id.Server().SetVersion(apiVersion);
for (const auto &s : this->dataPtr->config.Servers())
{
Expand Down Expand Up @@ -1372,7 +1382,11 @@ bool FuelClient::ParseCollectionUrl(const common::URI &_url,
}

// Get remaining server information from config
_id.Server().SetUrl(common::URI(scheme + "://" + server));
common::URI serverUri;
serverUri.SetScheme(scheme);
serverUri.SetAuthority(gz::common::URIAuthority("//" + server));

_id.Server().SetUrl(serverUri);
_id.Server().SetVersion(apiVersion);
for (const auto &s : this->dataPtr->config.Servers())
{
Expand Down
13 changes: 9 additions & 4 deletions src/FuelClient_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ class FuelClientTest: public ::testing::Test
ASSERT_FALSE(common::exists("test_cache"));
ASSERT_TRUE(common::createDirectories("test_cache"));
ASSERT_TRUE(common::isDirectory("test_cache"));

ASSERT_FALSE(common::exists("test_cache/fuel.gazebosim.org"));
ASSERT_TRUE(common::createDirectories("test_cache/fuel.gazebosim.org"));
ASSERT_TRUE(common::isDirectory("test_cache/fuel.gazebosim.org"));

}

public: std::shared_ptr<gz::common::TempDirectory> tempDir;
Expand Down Expand Up @@ -1167,7 +1172,7 @@ TEST_F(FuelClientTest, CachedWorld)

// Cached world (no version)
{
common::URI url{"http://localhost:8007/1.0/banana/worlds/My World"};
common::URI url{"http://localhost:8007/1.0/banana/worlds/My World", true};
std::string path;
auto result = client.CachedWorld(url, path);
EXPECT_TRUE(result);
Expand All @@ -1178,7 +1183,7 @@ TEST_F(FuelClientTest, CachedWorld)

// Cached world (tip)
{
common::URI url{"http://localhost:8007/1.0/banana/worlds/My World/tip"};
common::URI url{"http://localhost:8007/1.0/banana/worlds/My World/tip", true};
std::string path;
auto result = client.CachedWorld(url, path);
EXPECT_TRUE(result);
Expand All @@ -1189,7 +1194,7 @@ TEST_F(FuelClientTest, CachedWorld)

// Cached world (version number)
{
common::URI url{"http://localhost:8007/1.0/banana/worlds/My World/2"};
common::URI url{"http://localhost:8007/1.0/banana/worlds/My World/2", true};
std::string path;
auto result = client.CachedWorld(url, path);
EXPECT_TRUE(result);
Expand All @@ -1201,7 +1206,7 @@ TEST_F(FuelClientTest, CachedWorld)
// Cached world file (tip)
{
common::URI url{"http://localhost:8007/1.0/banana/worlds/My World/tip/"
"files/strawberry.world"};
"files/strawberry.world", true};
std::string path;
auto result = client.CachedWorldFile(url, path);
EXPECT_TRUE(result);
Expand Down
14 changes: 9 additions & 5 deletions src/LocalCache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,9 @@ bool LocalCache::SaveModel(

std::string cacheLocation = this->dataPtr->config->CacheLocation();

std::string modelRootDir = common::joinPaths(cacheLocation,
uriToPath(_id.Server().Url()), _id.Owner(), "models", _id.Name());
std::string modelRootDir =
common::joinPaths(cacheLocation, _id.UniqueName());

std::string modelVersionedDir =
common::joinPaths(modelRootDir, _id.VersionStr());

Expand Down Expand Up @@ -744,10 +745,13 @@ bool LocalCache::SaveWorld(
return false;
}

auto cacheLocation = this->dataPtr->config->CacheLocation();
std::string cacheLocation = this->dataPtr->config->CacheLocation();

std::string worldRootDir =
common::joinPaths(cacheLocation, _id.UniqueName());

auto worldRootDir = common::joinPaths(cacheLocation, _id.UniqueName());
auto worldVersionedDir = common::joinPaths(worldRootDir, _id.VersionStr());
std::string worldVersionedDir =
common::joinPaths(worldRootDir , _id.VersionStr());

// Is it already in the cache?
if (common::isDirectory(worldVersionedDir) && !_overwrite)
Expand Down
2 changes: 1 addition & 1 deletion src/ModelIdentifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ ModelIdentifier::~ModelIdentifier()
//////////////////////////////////////////////////
std::string ModelIdentifier::UniqueName() const
{
return common::joinPaths(this->dataPtr->server.Url().Str(),
return common::joinPaths(uriToPath(this->dataPtr->server.Url()),
this->dataPtr->owner, "models",
this->dataPtr->name);
}
Expand Down
2 changes: 1 addition & 1 deletion src/WorldIdentifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ WorldIdentifier::~WorldIdentifier()
//////////////////////////////////////////////////
std::string WorldIdentifier::UniqueName() const
{
return common::joinPaths(this->dataPtr->server.Url().Str(),
return common::joinPaths(uriToPath(this->dataPtr->server.Url()),
this->dataPtr->owner,
"worlds",
this->dataPtr->name);
Expand Down

0 comments on commit 42e9ee0

Please sign in to comment.