Skip to content

Commit

Permalink
Minimize diff
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll committed Sep 27, 2023
1 parent b5e7312 commit 839deae
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 43 deletions.
10 changes: 7 additions & 3 deletions include/gz/fuel_tools/Helpers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
#define gz_strdup strdup
#endif

namespace gz::fuel_tools
namespace gz
{
namespace fuel_tools
{
/// \brief Convert the authority portion of a URI to a string
/// suitable to be used as a path on disk for all platforms.
Expand All @@ -58,6 +60,8 @@ std::string sanitizeAuthority(const std::string &_uriAuthority);
/// \return String suitable to use in file paths
GZ_FUEL_TOOLS_VISIBLE
std::string uriToPath(const gz::common::URI &_uri);
} // namespace gz::fuel_tools
}
}

#endif // GZ_FUEL_TOOLS_HELPERS_HH_
// GZ_FUEL_TOOLS_HELPERS_HH_
#endif
1 change: 0 additions & 1 deletion include/gz/fuel_tools/WorldIdentifier.hh
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ namespace gz
/// \return Unique world name.
public: std::string UniqueName() const;


// /// \brief Sets the SHA 2 256 hash of the world
// /// \param[in] _hash a 256 bit SHA 2 hash
// /// \returns true if successful
Expand Down
28 changes: 14 additions & 14 deletions src/FuelClient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,20 +251,22 @@ FuelClient::FuelClient(const ClientConfig &_config, const Rest &_rest)

this->dataPtr->cache = std::make_unique<LocalCache>(&(this->dataPtr->config));

this->dataPtr->urlModelRegex =
std::make_unique<std::regex>(this->dataPtr->kModelUrlRegexStr);
this->dataPtr->urlWorldRegex =
std::make_unique<std::regex>(this->dataPtr->kWorldUrlRegexStr);
this->dataPtr->urlModelFileRegex =
std::make_unique<std::regex>(this->dataPtr->kModelFileUrlRegexStr);
this->dataPtr->urlWorldFileRegex =
std::make_unique<std::regex>(this->dataPtr->kWorldFileUrlRegexStr);
this->dataPtr->urlCollectionRegex =
std::make_unique<std::regex>(this->dataPtr->kCollectionUrlRegexStr);
this->dataPtr->urlModelRegex.reset(new std::regex(
this->dataPtr->kModelUrlRegexStr));
this->dataPtr->urlWorldRegex.reset(new std::regex(
this->dataPtr->kWorldUrlRegexStr));
this->dataPtr->urlModelFileRegex.reset(new std::regex(
this->dataPtr->kModelFileUrlRegexStr));
this->dataPtr->urlWorldFileRegex.reset(new std::regex(
this->dataPtr->kWorldFileUrlRegexStr));
this->dataPtr->urlCollectionRegex.reset(new std::regex(
this->dataPtr->kCollectionUrlRegexStr));
}

//////////////////////////////////////////////////
FuelClient::~FuelClient() = default;
FuelClient::~FuelClient()
{
}

//////////////////////////////////////////////////
ClientConfig &FuelClient::Config()
Expand Down Expand Up @@ -334,6 +336,7 @@ ModelIter FuelClient::Models(const ServerConfig &_server) const
Result FuelClient::WorldDetails(const WorldIdentifier &_id,
WorldIdentifier &_world) const
{

return this->WorldDetails(_id, _world, {});
}

Expand Down Expand Up @@ -713,11 +716,8 @@ 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);
}

std::cout << "Getting dependencies" << std::endl;
return this->ModelDependencies(_id, _dependencies);
}

Expand Down
9 changes: 4 additions & 5 deletions src/FuelClient_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ using namespace gz::fuel_tools;
/// Taken from LocalCache_TEST
void createLocalModel(ClientConfig &_conf)
{
gzdbg << "Creating local model in [" << common::cwd() << "]" << std::endl;

auto modelPath = common::joinPaths(
"test_cache",
sanitizeAuthority("localhost:8007"),
Expand Down Expand Up @@ -93,6 +95,8 @@ void createLocalModel(ClientConfig &_conf)
/// Taken from LocalCache_TEST
void createLocalWorld(ClientConfig &_conf)
{
gzdbg << "Creating local world in [" << common::cwd() << "]" << std::endl;

auto worldPath = common::joinPaths(
"test_cache",
sanitizeAuthority("localhost:8007"),
Expand Down Expand Up @@ -131,11 +135,9 @@ 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 @@ -541,20 +543,17 @@ TEST_P(FuelClientDownloadTest, DownloadModel)
EXPECT_FALSE(res2);
EXPECT_EQ(ResultType::FETCH_ERROR, res2.Type());

std::cout << "Download model" << std::endl;
// Download
std::string path;
Result res3 = client.DownloadModel(url, path);
EXPECT_TRUE(res3);
EXPECT_EQ(ResultType::FETCH, res3.Type());

std::cout << "Check cache for url " << std::endl;
// Check it is cached
Result res4 = client.CachedModel(url, cachedPath);
EXPECT_TRUE(res4);
EXPECT_EQ(ResultType::FETCH_ALREADY_EXISTS, res4.Type());

std::cout << "Check cache for depurl " << std::endl;
// Check the dependency is cached
Result res5 = client.CachedModel(depUrl, cachedPath);
EXPECT_TRUE(res5);
Expand Down
1 change: 0 additions & 1 deletion src/Helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ std::string gz::fuel_tools::uriToPath(const common::URI &_uri)
}

authority = sanitizeAuthority(authority);

if (authority.empty())
{
return path;
Expand Down
22 changes: 5 additions & 17 deletions src/LocalCache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,10 @@ ModelIter LocalCache::AllModels()
{
for (auto &server : this->dataPtr->config->Servers())
{
auto uri = server.Url();

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

auto srvModels = this->dataPtr->ModelsInServer(path);

for (auto &mod : srvModels)
{
mod.dataPtr->id.SetServer(server);
Expand Down Expand Up @@ -284,14 +281,9 @@ Model LocalCache::MatchingModel(const ModelIdentifier &_id)
bool tip = (_id.Version() == 0);
Model tipModel;

std::cout << "Searching for: " << _id.UniqueName() << std::endl;

for (ModelIter iter = this->AllModels(); iter; ++iter)
{
ModelIdentifier id = iter->Identification();

std::cout << "Found: " << id.UniqueName() << std::endl;

if (_id == id)
{
if (_id.Version() == id.Version())
Expand Down Expand Up @@ -396,8 +388,8 @@ bool LocalCache::SaveModel(

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

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

std::string modelVersionedDir =
common::joinPaths(modelRootDir, _id.VersionStr());
Expand Down Expand Up @@ -749,13 +741,9 @@ bool LocalCache::SaveWorld(
return false;
}

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

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

std::string worldVersionedDir =
common::joinPaths(worldRootDir , _id.VersionStr());
auto cacheLocation = this->dataPtr->config->CacheLocation();
auto worldRootDir = common::joinPaths(cacheLocation, _id.UniqueName());
auto worldVersionedDir = common::joinPaths(worldRootDir, _id.VersionStr());

// Is it already in the cache?
if (common::isDirectory(worldVersionedDir) && !_overwrite)
Expand Down
4 changes: 3 additions & 1 deletion src/ModelIdentifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ bool ModelIdentifier::operator!=(const ModelIdentifier &_rhs) const
}

//////////////////////////////////////////////////
ModelIdentifier::~ModelIdentifier() = default;
ModelIdentifier::~ModelIdentifier()
{
}

//////////////////////////////////////////////////
std::string ModelIdentifier::UniqueName() const
Expand Down
4 changes: 3 additions & 1 deletion src/WorldIdentifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ bool WorldIdentifier::operator==(const WorldIdentifier &_rhs) const
}

//////////////////////////////////////////////////
WorldIdentifier::~WorldIdentifier() = default;
WorldIdentifier::~WorldIdentifier()
{
}

//////////////////////////////////////////////////
std::string WorldIdentifier::UniqueName() const
Expand Down

0 comments on commit 839deae

Please sign in to comment.