diff --git a/src/ClientConfig_TEST.cc b/src/ClientConfig_TEST.cc index 74c5d246..372b2005 100644 --- a/src/ClientConfig_TEST.cc +++ b/src/ClientConfig_TEST.cc @@ -58,6 +58,20 @@ std::string homePath() return homePath; } +///////////////////////////////////////////////// +/// \brief Get cache directory. +/// \return Cache directory +/// \ToDo: Move this function to ignition::common::Filesystem +std::string cachePath() +{ + std::string cachePath; +#ifndef _WIN32 + return std::string("/tmp/ignition/fuel"); +#else + return std::string("C:\\Windows\\Temp"); +#endif +} + ///////////////////////////////////////////////// /// \brief Initially only the default server in config TEST(ClientConfig, InitiallyDefaultServers) @@ -115,8 +129,9 @@ TEST(ClientConfig, CustomConfiguration) << "" << std::endl << "# Where are the assets stored in disk." << std::endl << "cache:" << std::endl - << " path: /tmp/ignition/fuel" << std::endl + << " path: " + cachePath() << std::endl << std::endl; + ofs.close(); EXPECT_TRUE(config.LoadConfig(testPath)); @@ -128,8 +143,7 @@ TEST(ClientConfig, CustomConfiguration) EXPECT_EQ("https://myserver", config.Servers().back().Url().Str()); - EXPECT_EQ("/tmp/ignition/fuel", config.CacheLocation()); - + EXPECT_EQ(cachePath(), config.CacheLocation()); // Remove the configuration file. removeFileTemp(testPath); } @@ -156,8 +170,9 @@ TEST(ClientConfig, RepeatedServerConfiguration) << "" << std::endl << "# Where are the assets stored in disk." << std::endl << "cache:" << std::endl - << " path: /tmp/ignition/fuel" << std::endl + << " path: " + cachePath() << std::endl << std::endl; + ofs.close(); EXPECT_TRUE(config.LoadConfig(testPath)); @@ -182,6 +197,7 @@ TEST(ClientConfig, NoServerUrlConfiguration) << " -" << std::endl << " banana: coconut" << std::endl << std::endl; + ofs.close(); EXPECT_FALSE(config.LoadConfig(testPath)); @@ -206,6 +222,7 @@ TEST(ClientConfig, EmptyServerUrlConfiguration) << " -" << std::endl << " url: " << std::endl << std::endl; + ofs.close(); EXPECT_FALSE(config.LoadConfig(testPath)); @@ -227,6 +244,7 @@ TEST(ClientConfig, NoCachePathConfiguration) ofs << "---" << std::endl << "cache:" << std::endl << std::endl; + ofs.close(); EXPECT_FALSE(config.LoadConfig(testPath)); @@ -249,6 +267,7 @@ TEST(ClientConfig, EmptyCachePathConfiguration) << "cache:" << std::endl << " path:" << std::endl << std::endl; + ofs.close(); EXPECT_FALSE(config.LoadConfig(testPath)); @@ -417,4 +436,3 @@ int main(int argc, char **argv) ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } - diff --git a/src/CollectionIdentifier.cc b/src/CollectionIdentifier.cc index 86cac429..02cf65d6 100644 --- a/src/CollectionIdentifier.cc +++ b/src/CollectionIdentifier.cc @@ -156,4 +156,3 @@ std::string CollectionIdentifier::AsPrettyString( << this->Server().AsPrettyString(_prefix + " "); return out.str(); } - diff --git a/src/CollectionIdentifier_TEST.cc b/src/CollectionIdentifier_TEST.cc index 8df2ea9f..6fe674f3 100644 --- a/src/CollectionIdentifier_TEST.cc +++ b/src/CollectionIdentifier_TEST.cc @@ -57,7 +57,6 @@ TEST(CollectionIdentifier, UniqueName) CollectionIdentifier id; id.SetName("hello"); id.SetOwner("alice"); -#ifndef _WIN32 id.SetServer(srv1); EXPECT_EQ("https://localhost:8001/alice/collections/hello", id.UniqueName()); @@ -66,19 +65,6 @@ TEST(CollectionIdentifier, UniqueName) id.SetServer(srv3); EXPECT_EQ("https://localhost:8003/alice/collections/hello", id.UniqueName()); -#else - id.SetServer(srv1); - EXPECT_EQ("https://localhost:8001\\alice\\collections\\hello", - id.UniqueName()); - - id.SetServer(srv2); - EXPECT_EQ("https://localhost:8002\\alice\\collections\\hello", - id.UniqueName()); - - id.SetServer(srv3); - EXPECT_EQ("https://localhost:8003\\alice\\collections\\hello", - id.UniqueName()); -#endif } ///////////////////////////////////////////////// @@ -132,11 +118,12 @@ TEST(CollectionIdentifier, AsString) common::Console::SetVerbosity(4); { CollectionIdentifier id; + #ifndef _WIN32 std::string str = "Name: \n"\ "Owner: \n"\ - "Unique name: https://fuel.ignitionrobotics.org//collections/\n" + "Unique name: https://fuel.ignitionrobotics.org/collections/\n" "Server:\n" " URL: https://fuel.ignitionrobotics.org\n" " Version: 1.0\n" @@ -145,7 +132,7 @@ TEST(CollectionIdentifier, AsString) std::string str = "Name: \n"\ "Owner: \n"\ - "Unique name: https://fuel.ignitionrobotics.org\\collections\n" + "Unique name: https://fuel.ignitionrobotics.org/collections\n" "Server:\n" " URL: https://fuel.ignitionrobotics.org\n" " Version: 1.0\n" diff --git a/src/FuelClient.cc b/src/FuelClient.cc index ae7037a5..21f249bd 100644 --- a/src/FuelClient.cc +++ b/src/FuelClient.cc @@ -1018,6 +1018,7 @@ bool FuelClient::ParseWorldFileUrl(const common::URI &_fileUrl, return true; } + ////////////////////////////////////////////////// bool FuelClient::ParseCollectionUrl(const common::URI &_url, CollectionIdentifier &_id) @@ -1230,6 +1231,12 @@ Result FuelClient::CachedModelFile(const common::URI &_fileUrl, // Check if file exists filePath = common::joinPaths(modelPath, filePath); + std::vector tokens = ignition::common::split(filePath, "/"); + std::string sTemp; + for (auto s : tokens) + sTemp = ignition::common::joinPaths(sTemp, s); + filePath = sTemp; + if (common::exists(filePath)) { _path = filePath; diff --git a/src/FuelClient_TEST.cc b/src/FuelClient_TEST.cc index 54e6d4f0..002e5a7e 100644 --- a/src/FuelClient_TEST.cc +++ b/src/FuelClient_TEST.cc @@ -394,7 +394,7 @@ TEST_F(FuelClientTest, ParseModelFileURL) ///////////////////////////////////////////////// // Protocol "https" not supported or disabled in libcurl for Windows // https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 -TEST_F(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(DownloadModel)) +TEST_F(FuelClientTest, DownloadModel) { // Configure to use binary path as cache ASSERT_EQ(0, ChangeDirectory(PROJECT_BINARY_PATH)); @@ -593,7 +593,7 @@ TEST_F(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(DownloadModel)) ///////////////////////////////////////////////// // Windows doesn't support colons in filenames // https://github.com/ignitionrobotics/ign-fuel-tools/issues/106 -TEST_F(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(CachedModel)) +TEST_F(FuelClientTest, CachedModel) { // Configure to use binary path as cache and populate it ASSERT_EQ(0, ChangeDirectory(PROJECT_BINARY_PATH)); @@ -983,7 +983,7 @@ TEST_F(FuelClientTest, ParseWorldFileUrl) ////////////////////////////////////////////////// // Protocol "https" not supported or disabled in libcurl for Windows // https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 -TEST_F(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(DownloadWorld)) +TEST_F(FuelClientTest, DownloadWorld) { // Configure to use binary path as cache ASSERT_EQ(0, ChangeDirectory(PROJECT_BINARY_PATH)); @@ -1061,7 +1061,7 @@ TEST_F(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(DownloadWorld)) ///////////////////////////////////////////////// // Windows doesn't support colons in filenames // https://github.com/ignitionrobotics/ign-fuel-tools/issues/106 -TEST_F(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(CachedWorld)) +TEST_F(FuelClientTest, CachedWorld) { // Configure to use binary path as cache and populate it ASSERT_EQ(0, ChangeDirectory(PROJECT_BINARY_PATH)); @@ -1251,7 +1251,7 @@ TEST_F(FuelClientTest, WorldDetails) ///////////////////////////////////////////////// // Protocol "https" not supported or disabled in libcurl for Windows // https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 -TEST_F(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(Models)) +TEST_F(FuelClientTest, Models) { ClientConfig config; config.SetCacheLocation(common::joinPaths(common::cwd(), "test_cache")); @@ -1285,7 +1285,7 @@ TEST_F(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(Models)) ///////////////////////////////////////////////// // Protocol "https" not supported or disabled in libcurl for Windows // https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 -TEST_F(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(Worlds)) +TEST_F(FuelClientTest, Worlds) { ClientConfig config; config.SetCacheLocation(common::joinPaths(common::cwd(), "test_cache")); diff --git a/src/Interface.cc b/src/Interface.cc index c2cf3a6f..34ebe4cc 100644 --- a/src/Interface.cc +++ b/src/Interface.cc @@ -53,7 +53,7 @@ namespace ignition auto modelUri = _uri.substr(0, _uri.find("files", model.UniqueName().size())-1); _client.DownloadModel(common::URI(modelUri), result); - result += "/" + fileUrl; + result = common::joinPaths(result, fileUrl); } // Download the world, if it is a world URI else if (_client.ParseWorldUrl(uri, world) && @@ -68,7 +68,8 @@ namespace ignition auto worldUri = _uri.substr(0, _uri.find("files", world.UniqueName().size())-1); _client.DownloadWorld(common::URI(worldUri), result); - result += "/" + fileUrl; + result = common::joinPaths(result, fileUrl); + } return result; diff --git a/src/Interface_TEST.cc b/src/Interface_TEST.cc index 41a9a379..4f342f17 100644 --- a/src/Interface_TEST.cc +++ b/src/Interface_TEST.cc @@ -39,7 +39,7 @@ using namespace ignition::fuel_tools; ///////////////////////////////////////////////// // Protocol "https" not supported or disabled in libcurl for Windows // https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 -TEST(Interface, IGN_UTILS_TEST_DISABLED_ON_WIN32(FetchResources)) +TEST(Interface, FetchResources) { common::Console::SetVerbosity(4); @@ -71,30 +71,31 @@ TEST(Interface, IGN_UTILS_TEST_DISABLED_ON_WIN32(FetchResources)) std::string path = fetchResourceWithClient(modelUrl.Str(), client); // Check it was downloaded to `2` - EXPECT_EQ(path, common::cwd() + - "/test_cache/fuel.ignitionrobotics.org/chapulina/models/test box/2"); + EXPECT_EQ(path, common::joinPaths(common::cwd(), "test_cache", + "fuel.ignitionrobotics.org", "chapulina", "models", "test box", "2")); EXPECT_TRUE(common::exists( - "test_cache/fuel.ignitionrobotics.org/chapulina/models/test box/2")); + common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "chapulina", "models", "test box", "2"))); EXPECT_TRUE(common::exists( - "test_cache/fuel.ignitionrobotics.org/chapulina/models/test box/2/" - "model.sdf")); + common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "chapulina", "models", "test box", "2", "model.sdf"))); EXPECT_TRUE(common::exists( - "test_cache/fuel.ignitionrobotics.org/chapulina/models/test box/2/" - "model.config")); + common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "chapulina", "models", "test box", "2", "model.config"))); // Check it wasn't downloaded to model root directory EXPECT_FALSE(common::exists( - "test_cache/fuel.ignitionrobotics.org/chapulina/models" - "/Test box/model.config")); + common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "chapulina", "models", "Test box", "model.config"))); // Check it is cached { Result res = client.CachedModel(modelUrl, cachedPath); EXPECT_TRUE(res); EXPECT_EQ(Result(ResultType::FETCH_ALREADY_EXISTS), res); - EXPECT_EQ(common::cwd() + - "/test_cache/fuel.ignitionrobotics.org/chapulina/models/test box/2", - cachedPath); + EXPECT_EQ(common::joinPaths(common::cwd(), "test_cache", + "fuel.ignitionrobotics.org", "chapulina", "models", "test box", "2"), + cachedPath); } } @@ -123,34 +124,36 @@ TEST(Interface, IGN_UTILS_TEST_DISABLED_ON_WIN32(FetchResources)) // Check entire model was downloaded to `1` EXPECT_TRUE(common::exists( - "test_cache/fuel.ignitionrobotics.org/openrobotics/models/bus/1")); - EXPECT_EQ(path, common::cwd() + - "/test_cache/fuel.ignitionrobotics.org/openrobotics/models/bus/1/" - "meshes/bus.obj"); + common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "models", "bus", "1"))); + EXPECT_EQ(path, common::joinPaths(common::cwd(), "test_cache", + "fuel.ignitionrobotics.org", "openrobotics", "models", "bus", + "1", "meshes", "bus.obj")); EXPECT_TRUE(common::exists( - "test_cache/fuel.ignitionrobotics.org/openrobotics/models/bus/1/" - "model.sdf")); + common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "models", "bus", "1", "model.sdf"))); EXPECT_TRUE(common::exists( - "test_cache/fuel.ignitionrobotics.org/openrobotics/models/bus/1/" - "model.config")); + common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "models", "bus", "1", "model.config"))); EXPECT_TRUE(common::exists( - "test_cache/fuel.ignitionrobotics.org/openrobotics/models/bus/1/" - "meshes/bus.obj")); + common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "models", "bus", "1", "meshes/bus.obj"))); EXPECT_TRUE(common::exists( - "test_cache/fuel.ignitionrobotics.org/openrobotics/models/bus/1/" - "meshes/bus.mtl")); + common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "models", "bus", "1", "meshes/bus.mtl"))); EXPECT_TRUE(common::exists( - "test_cache/fuel.ignitionrobotics.org/openrobotics/models/bus/1/" - "materials/textures/bus.png")); + common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "models", "bus", "1", "materials", "textures", + "bus.png"))); // Check model is cached { Result res = client.CachedModel(modelUrl, cachedPath); EXPECT_TRUE(res); EXPECT_EQ(Result(ResultType::FETCH_ALREADY_EXISTS), res); - EXPECT_EQ(common::cwd() + - "/test_cache/fuel.ignitionrobotics.org/openrobotics/models/bus/1", - cachedPath); + EXPECT_EQ(common::joinPaths(common::cwd(), "test_cache", + "fuel.ignitionrobotics.org", "openrobotics", "models", "bus", "1"), + cachedPath); } // Check file is cached @@ -158,10 +161,9 @@ TEST(Interface, IGN_UTILS_TEST_DISABLED_ON_WIN32(FetchResources)) Result res = client.CachedModelFile(modelFileUrl, cachedPath); EXPECT_TRUE(res); EXPECT_EQ(Result(ResultType::FETCH_ALREADY_EXISTS), res); - EXPECT_EQ(common::cwd() + - "/test_cache/fuel.ignitionrobotics.org/openrobotics/models/bus/1" - "/meshes/bus.obj", - cachedPath); + EXPECT_EQ(common::joinPaths(common::cwd(), "test_cache", + "fuel.ignitionrobotics.org", "openrobotics", "models", "bus", "1", + "meshes", "bus.obj"), cachedPath); } } @@ -180,21 +182,24 @@ TEST(Interface, IGN_UTILS_TEST_DISABLED_ON_WIN32(FetchResources)) std::string path = fetchResourceWithClient(worldUrl.Str(), client); // Check it was downloaded to `1` - EXPECT_EQ(path, common::cwd() + "/test_cache/fuel.ignitionrobotics.org/" - "openrobotics/worlds/test world/2"); - EXPECT_TRUE(common::exists("test_cache/fuel.ignitionrobotics.org/" - "openrobotics/worlds/test world/2")); - EXPECT_TRUE(common::exists("test_cache/fuel.ignitionrobotics.org/" - "openrobotics/worlds/test world/2/test.world")); + EXPECT_EQ(path, common::joinPaths(common::cwd(), "test_cache", + "fuel.ignitionrobotics.org", "openrobotics", "worlds", + "test world", "2")); + EXPECT_TRUE(common::exists(common::joinPaths("test_cache", + "fuel.ignitionrobotics.org", "openrobotics", "worlds", "test world", + "2"))); + EXPECT_TRUE(common::exists(common::joinPaths("test_cache", + "fuel.ignitionrobotics.org", "openrobotics", "worlds", "test world", "2", + "test.world"))); // Check it is cached { Result res = client.CachedWorld(worldUrl, cachedPath); EXPECT_TRUE(res); EXPECT_EQ(Result(ResultType::FETCH_ALREADY_EXISTS), res); - EXPECT_EQ(common::cwd() + - "/test_cache/fuel.ignitionrobotics.org/openrobotics/worlds/" - "test world/2", cachedPath); + EXPECT_EQ(common::joinPaths(common::cwd(), "test_cache", + "fuel.ignitionrobotics.org", "openrobotics", "worlds", "test world", + "2"), cachedPath); } } @@ -223,22 +228,23 @@ TEST(Interface, IGN_UTILS_TEST_DISABLED_ON_WIN32(FetchResources)) // Check entire world was downloaded to `1` EXPECT_TRUE(common::exists( - "test_cache/fuel.ignitionrobotics.org/chapulina/worlds/test world/2")); - EXPECT_EQ(path, common::cwd() + - "/test_cache/fuel.ignitionrobotics.org/chapulina/worlds/test world/2/" - "thumbnails/1.png"); + common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "chapulina", "worlds", "test world", "2"))); + EXPECT_EQ(path, common::joinPaths(common::cwd(), "test_cache", + "fuel.ignitionrobotics.org", "chapulina", "worlds", "test world", "2", + "thumbnails", "1.png")); EXPECT_TRUE(common::exists( - "test_cache/fuel.ignitionrobotics.org/chapulina/worlds/test world/2/" - "test.world")); + common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "chapulina", "worlds", "test world", "2", "test.world"))); // Check world is cached { Result res = client.CachedWorld(worldUrl, cachedPath); EXPECT_TRUE(res); EXPECT_EQ(Result(ResultType::FETCH_ALREADY_EXISTS), res); - EXPECT_EQ(common::cwd() + - "/test_cache/fuel.ignitionrobotics.org/chapulina/worlds/test world/2", - cachedPath); + EXPECT_EQ(common::joinPaths(common::cwd(), "test_cache", + "fuel.ignitionrobotics.org", "chapulina", "worlds", "test world", "2"), + cachedPath); } // Check file is cached @@ -246,10 +252,9 @@ TEST(Interface, IGN_UTILS_TEST_DISABLED_ON_WIN32(FetchResources)) Result res = client.CachedWorldFile(worldFileUrl, cachedPath); EXPECT_TRUE(res); EXPECT_EQ(Result(ResultType::FETCH_ALREADY_EXISTS), res); - EXPECT_EQ(common::cwd() + - "/test_cache/fuel.ignitionrobotics.org/chapulina/worlds/test world/2" - "/thumbnails/1.png", - cachedPath); + EXPECT_EQ(common::joinPaths(common::cwd(), "test_cache", + "fuel.ignitionrobotics.org", "chapulina", "worlds", "test world", "2", + "thumbnails", "1.png"), cachedPath); } } } diff --git a/src/LocalCache.cc b/src/LocalCache.cc index c0167192..934e1f55 100644 --- a/src/LocalCache.cc +++ b/src/LocalCache.cc @@ -406,7 +406,11 @@ bool LocalCache::SaveModel( } auto zipFile = common::joinPaths(modelVersionedDir, _id.Name() + ".zip"); +#ifdef _WIN32 + std::ofstream ofs(zipFile, std::ofstream::out | std::ofstream::binary); +#else std::ofstream ofs(zipFile, std::ofstream::out); +#endif ofs << _data; ofs.close(); @@ -750,7 +754,11 @@ bool LocalCache::SaveWorld( } auto zipFile = common::joinPaths(worldVersionedDir, _id.Name() + ".zip"); - std::ofstream ofs(zipFile, std::ofstream::out); + #ifdef _WIN32 + std::ofstream ofs(zipFile, std::ofstream::out | std::ofstream::binary); + #else + std::ofstream ofs(zipFile, std::ofstream::out); + #endif ofs << _data; ofs.close(); @@ -771,4 +779,3 @@ bool LocalCache::SaveWorld( return true; } - diff --git a/src/LocalCache_TEST.cc b/src/LocalCache_TEST.cc index 7317023d..d30fe045 100644 --- a/src/LocalCache_TEST.cc +++ b/src/LocalCache_TEST.cc @@ -226,7 +226,7 @@ class LocalCacheTest : public ::testing::Test /// \brief Iterate through all models in cache // Windows doesn't support colons in filenames // https://github.com/ignitionrobotics/ign-fuel-tools/issues/106 -TEST_F(LocalCacheTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(AllModels)) +TEST_F(LocalCacheTest, AllModels) { ASSERT_EQ(0, ChangeDirectory(PROJECT_BINARY_PATH)); common::removeAll("test_cache"); @@ -256,7 +256,7 @@ TEST_F(LocalCacheTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(AllModels)) /// \brief Iterate through all models in cache // Windows doesn't support colons in filenames // https://github.com/ignitionrobotics/ign-fuel-tools/issues/106 -TEST_F(LocalCacheTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(MatchingModels)) +TEST_F(LocalCacheTest, MatchingModels) { ASSERT_EQ(0, ChangeDirectory(PROJECT_BINARY_PATH)); common::removeAll("test_cache"); @@ -304,7 +304,7 @@ TEST_F(LocalCacheTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(MatchingModels)) /// \brief Iterate through all models in cache // Windows doesn't support colons in filenames // https://github.com/ignitionrobotics/ign-fuel-tools/issues/106 -TEST_F(LocalCacheTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(MatchingModel)) +TEST_F(LocalCacheTest, MatchingModel) { ASSERT_EQ(0, ChangeDirectory(PROJECT_BINARY_PATH)); common::removeAll("test_cache"); @@ -362,7 +362,7 @@ TEST_F(LocalCacheTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(MatchingModel)) /// \brief Iterate through all models in cache // Windows doesn't support colons in filenames // https://github.com/ignitionrobotics/ign-fuel-tools/issues/106 -TEST_F(LocalCacheTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(AllWorlds)) +TEST_F(LocalCacheTest, AllWorlds) { ASSERT_EQ(0, ChangeDirectory(PROJECT_BINARY_PATH)); common::removeAll("test_cache"); @@ -382,9 +382,13 @@ TEST_F(LocalCacheTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(AllWorlds)) ++iter; } EXPECT_EQ(9u, uniqueNames.size()); - +#ifdef _WIN32 EXPECT_NE(uniqueNames.end(), uniqueNames.find( - "localhost:8001/alice/worlds/am1")); + ignition::common::joinPaths("localhost8001", "alice", "worlds", "am1"))); +#else + EXPECT_NE(uniqueNames.end(), uniqueNames.find( + ignition::common::joinPaths("localhost:8001", "alice", "worlds", "am1"))); +#endif } ///////////////////////////////////////////////// @@ -392,7 +396,7 @@ TEST_F(LocalCacheTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(AllWorlds)) /// \brief Iterate through all models in cache // Windows doesn't support colons in filenames // https://github.com/ignitionrobotics/ign-fuel-tools/issues/106 -TEST_F(LocalCacheTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(MatchingWorlds)) +TEST_F(LocalCacheTest, MatchingWorlds) { ASSERT_EQ(0, ChangeDirectory(PROJECT_BINARY_PATH)); common::removeAll("test_cache"); @@ -428,7 +432,7 @@ TEST_F(LocalCacheTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(MatchingWorlds)) /// \brief Iterate through all models in cache // Windows doesn't support colons in filenames // https://github.com/ignitionrobotics/ign-fuel-tools/issues/106 -TEST_F(LocalCacheTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(MatchingWorld)) +TEST_F(LocalCacheTest, MatchingWorld) { ASSERT_EQ(0, ChangeDirectory(PROJECT_BINARY_PATH)); common::removeAll("test_cache"); diff --git a/src/ModelIdentifier.cc b/src/ModelIdentifier.cc index 9d7a15a2..1b50d0c4 100644 --- a/src/ModelIdentifier.cc +++ b/src/ModelIdentifier.cc @@ -144,8 +144,7 @@ ModelIdentifier::~ModelIdentifier() std::string ModelIdentifier::UniqueName() const { return common::joinPaths(this->dataPtr->server.Url().Str(), - this->dataPtr->owner, - "models", + this->dataPtr->owner, "models", this->dataPtr->name); } diff --git a/src/ModelIdentifier_TEST.cc b/src/ModelIdentifier_TEST.cc index b4c79960..b1dd87ef 100644 --- a/src/ModelIdentifier_TEST.cc +++ b/src/ModelIdentifier_TEST.cc @@ -153,7 +153,7 @@ TEST(ModelIdentifier, AsString) "Name: \n"\ "Owner: \n"\ "Version: tip\n"\ - "Unique name: https://fuel.ignitionrobotics.org//models/\n" + "Unique name: https://fuel.ignitionrobotics.org/models/\n" "Description: \n" "File size: 0\n" "Upload date: 0\n" @@ -172,7 +172,7 @@ TEST(ModelIdentifier, AsString) "Name: \n"\ "Owner: \n"\ "Version: tip\n"\ - "Unique name: https://fuel.ignitionrobotics.org\\models\n" + "Unique name: https://fuel.ignitionrobotics.org/models\n" "Description: \n" "File size: 0\n" "Upload date: 0\n" diff --git a/src/ModelIter.cc b/src/ModelIter.cc index ed1e8f96..3f199243 100644 --- a/src/ModelIter.cc +++ b/src/ModelIter.cc @@ -16,6 +16,7 @@ */ #include +#include #include #include #include @@ -168,7 +169,9 @@ IterRestIds::IterRestIds(const Rest &_rest, const ServerConfig &_config, // Fire the request. resp = this->rest.Request(method, this->config.Url().Str(), - this->config.Version(), path, {queryStrPage}, headers, ""); + this->config.Version(), + std::regex_replace(path, std::regex(R"(\\)"), "/"), + {queryStrPage}, headers, ""); // TODO(nkoenig): resp.statusCode should return != 200 when the page // requested does diff --git a/src/WorldIdentifier_TEST.cc b/src/WorldIdentifier_TEST.cc index f2384c34..52d4cf0d 100644 --- a/src/WorldIdentifier_TEST.cc +++ b/src/WorldIdentifier_TEST.cc @@ -120,7 +120,7 @@ TEST(WorldIdentifier, AsString) "Name: \n"\ "Owner: \n"\ "Version: tip\n"\ - "Unique name: fuel.ignitionrobotics.org//worlds/\n" + "Unique name: fuel.ignitionrobotics.org/worlds/\n" "Local path: \n" "Server:\n" " URL: https://fuel.ignitionrobotics.org\n" diff --git a/src/WorldIter.cc b/src/WorldIter.cc index 06ccf1f9..dd0aa630 100644 --- a/src/WorldIter.cc +++ b/src/WorldIter.cc @@ -16,6 +16,7 @@ */ #include +#include #include #include #include @@ -115,9 +116,12 @@ WorldIterRestIds::WorldIterRestIds(const Rest &_rest, std::string queryStrPageKey = "page="; do { + // Fire the request. // Fire the request. resp = this->rest.Request(method, this->config.Url().Str(), - this->config.Version(), _path, {queryStrPage}, headers, ""); + this->config.Version(), + std::regex_replace(_path, std::regex(R"(\\)"), "/"), + {queryStrPage}, headers, ""); // Reset the query string queryStrPage = ""; diff --git a/src/Zip.cc b/src/Zip.cc index 4ac51e79..f4d5be81 100644 --- a/src/Zip.cc +++ b/src/Zip.cc @@ -140,18 +140,16 @@ bool Zip::Extract(const std::string &_src, common::changeFromUnixPath(entryname); std::string dst = ignition::common::joinPaths(_dst, entryname); - // Create intermediate directories if needed. - std::string dirname = dst; - - auto pos = dirname.rfind(ignition::common::separator("")); - if (pos != std::string::npos && pos != dirname.size() - 1) - dirname.erase(pos); - - if (!ignition::common::createDirectories(dirname)) + // Check if the entryname contains a / at the end. if so it's a directory + auto pos = entryname.rfind(ignition::common::separator("")); + if (pos != std::string::npos && pos == (entryname.size() - 1)) { - ignerr << "Error creating directory [" << dirname << "]. " - << "Do you have the right permissions?" << std::endl; - return false; + if (!ignition::common::createDirectories(dst)) + { + ignerr << "Error creating directory [" << dst << "]. " + << "Do you have the right permissions?" << std::endl; + return false; + } } // Create and write the files. diff --git a/src/ign_src_TEST.cc b/src/ign_src_TEST.cc index 59197f64..622bb9a3 100644 --- a/src/ign_src_TEST.cc +++ b/src/ign_src_TEST.cc @@ -80,7 +80,7 @@ TEST(CmdLine, ModelListFail) ///////////////////////////////////////////////// // Protocol "https" not supported or disabled in libcurl for Windows // https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 -TEST(CmdLine, IGN_UTILS_TEST_DISABLED_ON_WIN32(ModelListConfigServerUgly)) +TEST(CmdLine, ModelListConfigServerUgly) { std::stringstream stdOutBuffer; std::stringstream stdErrBuffer; @@ -100,7 +100,7 @@ TEST(CmdLine, IGN_UTILS_TEST_DISABLED_ON_WIN32(ModelListConfigServerUgly)) ///////////////////////////////////////////////// // Protocol "https" not supported or disabled in libcurl for Windows // https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 -TEST(CmdLine, IGN_UTILS_TEST_DISABLED_ON_WIN32(ModelListConfigServerPretty)) +TEST(CmdLine, ModelListConfigServerPretty) { std::stringstream stdOutBuffer; std::stringstream stdErrBuffer; @@ -129,8 +129,7 @@ TEST(CmdLine, IGN_UTILS_TEST_DISABLED_ON_WIN32(ModelListConfigServerPretty)) ///////////////////////////////////////////////// // Protocol "https" not supported or disabled in libcurl for Windows // https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 -TEST(CmdLine, IGN_UTILS_TEST_DISABLED_ON_WIN32( - ModelListConfigServerPrettyOwner)) +TEST(CmdLine, ModelListConfigServerPrettyOwner) { std::stringstream stdOutBuffer; std::stringstream stdErrBuffer; @@ -199,7 +198,7 @@ TEST(CmdLine, ModelDownloadWrongUrl) ///////////////////////////////////////////////// // Protocol "https" not supported or disabled in libcurl for Windows // https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 -TEST(CmdLine, IGN_UTILS_TEST_DISABLED_ON_WIN32(ModelDownloadUnversioned)) +TEST(CmdLine, ModelDownloadUnversioned) { cmdVerbosity("4"); @@ -236,7 +235,7 @@ TEST(CmdLine, IGN_UTILS_TEST_DISABLED_ON_WIN32(ModelDownloadUnversioned)) ///////////////////////////////////////////////// // Protocol "https" not supported or disabled in libcurl for Windows // https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 -TEST(CmdLine, IGN_UTILS_TEST_DISABLED_ON_WIN32(DownloadConfigCache)) +TEST(CmdLine, DownloadConfigCache) { cmdVerbosity("4"); @@ -307,8 +306,7 @@ TEST(CmdLine, WorldListFail) ///////////////////////////////////////////////// // Protocol "https" not supported or disabled in libcurl for Windows // https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 -TEST(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32( - WorldListConfigServerUgly)) +TEST(FuelClientTest, WorldListConfigServerUgly) { std::stringstream stdOutBuffer; std::stringstream stdErrBuffer; @@ -330,8 +328,7 @@ TEST(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32( ///////////////////////////////////////////////// // Protocol "https" not supported or disabled in libcurl for Windows // https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 -TEST(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32( - WorldListConfigServerPretty)) +TEST(FuelClientTest, WorldListConfigServerPretty) { std::stringstream stdOutBuffer; std::stringstream stdErrBuffer; @@ -390,8 +387,7 @@ TEST(CmdLine, WorldListCustomServerPrettyOwner) ///////////////////////////////////////////////// // Protocol "https" not supported or disabled in libcurl for Windows // https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 -TEST(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32( - WorldDownloadBadUrl)) +TEST(FuelClientTest, WorldDownloadBadUrl) { std::stringstream stdOutBuffer; std::stringstream stdErrBuffer; @@ -428,8 +424,7 @@ TEST(CmdLine, WorldDownloadWrongUrl) ///////////////////////////////////////////////// // Protocol "https" not supported or disabled in libcurl for Windows // https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 -TEST(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32( - WorldDownloadUnversioned)) +TEST(FuelClientTest, WorldDownloadUnversioned) { cmdVerbosity("4"); @@ -452,12 +447,14 @@ TEST(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32( // Check files EXPECT_TRUE(ignition::common::isDirectory( - "test_cache/fuel.ignitionrobotics.org/openrobotics/worlds/test world")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "worlds", "test world"))); EXPECT_TRUE(ignition::common::isDirectory( - "test_cache/fuel.ignitionrobotics.org/openrobotics/worlds/test world/2")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "worlds", "test world", "2"))); EXPECT_TRUE(ignition::common::isFile( - std::string("test_cache/fuel.ignitionrobotics.org/openrobotics/worlds/") - + "test world/2/test.world")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "worlds", "test world", "2", "test.world"))); clearIOStreams(stdOutBuffer, stdErrBuffer); restoreIO(); @@ -474,7 +471,7 @@ INSTANTIATE_TEST_CASE_P(CollectionTest, DownloadCollectionTest, ///////////////////////////////////////////////// // Protocol "https" not supported or disabled in libcurl for Windows // https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 -TEST_P(DownloadCollectionTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(AllItems)) +TEST_P(DownloadCollectionTest, AllItems) { cmdVerbosity("4"); @@ -500,40 +497,47 @@ TEST_P(DownloadCollectionTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(AllItems)) // Check files // Model: Backpack EXPECT_TRUE(ignition::common::isDirectory( - "test_cache/fuel.ignitionrobotics.org/openrobotics/models/backpack")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "models", "backpack"))); EXPECT_TRUE(ignition::common::isDirectory( - "test_cache/fuel.ignitionrobotics.org/openrobotics/models/backpack/2")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "models", "backpack", "2"))); EXPECT_TRUE(ignition::common::isFile( - std::string("test_cache/fuel.ignitionrobotics.org/openrobotics/models/") + - "backpack/2/model.sdf")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "models", "backpack", "2", "model.sdf"))); // Model: TEAMBASE EXPECT_TRUE(ignition::common::isDirectory( - "test_cache/fuel.ignitionrobotics.org/openrobotics/models/teambase")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "models", "teambase"))); EXPECT_TRUE(ignition::common::isDirectory( - "test_cache/fuel.ignitionrobotics.org/openrobotics/models/teambase/2")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "models", "teambase", "2"))); EXPECT_TRUE(ignition::common::isFile( - std::string("test_cache/fuel.ignitionrobotics.org/openrobotics/models/") + - "teambase/2/model.sdf")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "models", "teambase", "2", "model.sdf"))); // World: Test World EXPECT_TRUE(ignition::common::isDirectory( - "test_cache/fuel.ignitionrobotics.org/openrobotics/worlds/test world")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "worlds", "test world"))); EXPECT_TRUE(ignition::common::isDirectory( - "test_cache/fuel.ignitionrobotics.org/openrobotics/worlds/test world/2")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "worlds", "test world", "2"))); EXPECT_TRUE(ignition::common::isFile( - std::string("test_cache/fuel.ignitionrobotics.org/openrobotics/worlds/") + - "test world/2/test.world")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "worlds", "test world", "2", "test.world"))); // World: Test World 2 EXPECT_TRUE(ignition::common::isDirectory( - "test_cache/fuel.ignitionrobotics.org/openrobotics/worlds/test world 2")); - EXPECT_TRUE( - ignition::common::isDirectory("test_cache/fuel.ignitionrobotics.org/" - "openrobotics/worlds/test world 2/2")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "worlds", "test world 2"))); + EXPECT_TRUE(ignition::common::isDirectory( + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "worlds", "test world 2", "2"))); EXPECT_TRUE(ignition::common::isFile( - std::string("test_cache/fuel.ignitionrobotics.org/openrobotics/worlds/") + - "test world 2/2/test.world")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "worlds", "test world 2", "2", "test.world"))); clearIOStreams(stdOutBuffer, stdErrBuffer); restoreIO(); } @@ -542,7 +546,7 @@ TEST_P(DownloadCollectionTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(AllItems)) /// Download only models // Protocol "https" not supported or disabled in libcurl for Windows // https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 -TEST_P(DownloadCollectionTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(Models)) +TEST_P(DownloadCollectionTest, Models) { cmdVerbosity("4"); @@ -568,29 +572,35 @@ TEST_P(DownloadCollectionTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(Models)) // Check files // Model: Backpack EXPECT_TRUE(ignition::common::isDirectory( - "test_cache/fuel.ignitionrobotics.org/openrobotics/models/backpack")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "models", "backpack"))); EXPECT_TRUE(ignition::common::isDirectory( - "test_cache/fuel.ignitionrobotics.org/openrobotics/models/backpack/2")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "models", "backpack", "2"))); EXPECT_TRUE(ignition::common::isFile( - std::string("test_cache/fuel.ignitionrobotics.org/openrobotics/models/") + - "backpack/2/model.sdf")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "models", "backpack", "2", "model.sdf"))); // Model: TEAMBASE EXPECT_TRUE(ignition::common::isDirectory( - "test_cache/fuel.ignitionrobotics.org/openrobotics/models/teambase")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "models", "teambase"))); EXPECT_TRUE(ignition::common::isDirectory( - "test_cache/fuel.ignitionrobotics.org/openrobotics/models/teambase/2")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "models", "teambase", "2"))); EXPECT_TRUE(ignition::common::isFile( - std::string("test_cache/fuel.ignitionrobotics.org/openrobotics/models/") + - "teambase/2/model.sdf")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "models", "teambase", "2", "model.sdf"))); // World: Test World EXPECT_FALSE(ignition::common::isDirectory( - "test_cache/fuel.ignitionrobotics.org/openrobotics/worlds/test world")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "worlds", "test world"))); // World: Test World 2 EXPECT_FALSE(ignition::common::isDirectory( - "test_cache/fuel.ignitionrobotics.org/openrobotics/worlds/test world 2")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "worlds", "test world2"))); clearIOStreams(stdOutBuffer, stdErrBuffer); restoreIO(); } @@ -599,7 +609,7 @@ TEST_P(DownloadCollectionTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(Models)) /// Download only worlds // Protocol "https" not supported or disabled in libcurl for Windows // https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 -TEST_P(DownloadCollectionTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(Worlds)) +TEST_P(DownloadCollectionTest, Worlds) { cmdVerbosity("4"); @@ -625,30 +635,35 @@ TEST_P(DownloadCollectionTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(Worlds)) // Check files // Model: Backpack EXPECT_FALSE(ignition::common::isDirectory( - "test_cache/fuel.ignitionrobotics.org/openrobotics/models/backpack")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "models", "backpack"))); // Model: TEAMBASE EXPECT_FALSE(ignition::common::isDirectory( - "test_cache/fuel.ignitionrobotics.org/openrobotics/models/teambase")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "models", "teambase"))); // World: Test World EXPECT_TRUE(ignition::common::isDirectory( - "test_cache/fuel.ignitionrobotics.org/openrobotics/worlds/test world")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "worlds", "test world"))); EXPECT_TRUE(ignition::common::isDirectory( - "test_cache/fuel.ignitionrobotics.org/openrobotics/worlds/test world/2")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "worlds", "test world", "2"))); EXPECT_TRUE(ignition::common::isFile( - std::string("test_cache/fuel.ignitionrobotics.org/openrobotics/worlds/") + - "test world/2/test.world")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "worlds", "test world", "2", "test.world"))); // World: Test World 2 EXPECT_TRUE(ignition::common::isDirectory( - "test_cache/fuel.ignitionrobotics.org/openrobotics/worlds/test world 2")); - EXPECT_TRUE( - ignition::common::isDirectory("test_cache/fuel.ignitionrobotics.org/" - "openrobotics/worlds/test world 2/2")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "worlds", "test world 2"))); + EXPECT_TRUE(ignition::common::isDirectory( + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "worlds", "test world 2", "2"))); EXPECT_TRUE(ignition::common::isFile( - std::string("test_cache/fuel.ignitionrobotics.org/openrobotics/worlds/") + - "test world 2/2/test.world")); + ignition::common::joinPaths("test_cache", "fuel.ignitionrobotics.org", + "openrobotics", "worlds", "test world 2", "2", "test.world"))); clearIOStreams(stdOutBuffer, stdErrBuffer); restoreIO(); }