From a9b6419d281797ec1c1afbaf33b784e970733ffc Mon Sep 17 00:00:00 2001 From: Jenn Nguyen Date: Tue, 8 Feb 2022 18:08:54 -0800 Subject: [PATCH 1/3] fixed parentPath() when no parent Signed-off-by: Jenn Nguyen --- src/Filesystem.cc | 4 ++++ src/Filesystem_TEST.cc | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/Filesystem.cc b/src/Filesystem.cc index ba4fda7e..d0d15a36 100644 --- a/src/Filesystem.cc +++ b/src/Filesystem.cc @@ -209,6 +209,10 @@ std::string ignition::common::parentPath(const std::string &_path) // Maintain compatibility with ign-common if (*_path.rbegin() == fs::path::preferred_separator) p = fs::path(_path.substr(0, _path.size()-1)); + + if (!p.has_parent_path()) + return p.string(); + return p.parent_path().string(); } diff --git a/src/Filesystem_TEST.cc b/src/Filesystem_TEST.cc index a193767f..64b9899c 100644 --- a/src/Filesystem_TEST.cc +++ b/src/Filesystem_TEST.cc @@ -473,6 +473,9 @@ TEST_F(FilesystemTest, parentPath) child_with_slash = separator(child_with_slash); std::string parent2 = parentPath(child_with_slash); EXPECT_EQ(parent, parent2); + + std::string childOnly = "child"; + EXPECT_EQ(childOnly, parentPath(childOnly)); } ///////////////////////////////////////////////// From 7d82908b3cbccccb30d1c67e4db7f23106cf8212 Mon Sep 17 00:00:00 2001 From: Jenn Nguyen Date: Tue, 8 Feb 2022 18:11:04 -0800 Subject: [PATCH 2/3] codecheck whitespaces Signed-off-by: Jenn Nguyen --- src/Timer.cc | 6 +++--- src/Timer_TEST.cc | 2 +- src/Util.cc | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Timer.cc b/src/Timer.cc index f1c9add3..4fa56f85 100644 --- a/src/Timer.cc +++ b/src/Timer.cc @@ -24,10 +24,10 @@ using namespace common; class ignition::common::Timer::Implementation { /// \brief The time of the last call to Start - public: std::chrono::steady_clock::time_point start; + public: std::chrono::steady_clock::time_point start; /// \brief The time when Stop was called. - public: std::chrono::steady_clock::time_point stop; + public: std::chrono::steady_clock::time_point stop; /// \brief True if the timer is running. public: bool running {false}; @@ -71,7 +71,7 @@ std::chrono::duration Timer::ElapsedTime() const } else { - std::chrono::duration diff = + std::chrono::duration diff = this->dataPtr->stop - this->dataPtr->start; return diff; } diff --git a/src/Timer_TEST.cc b/src/Timer_TEST.cc index 7dad64c1..7f2e7944 100644 --- a/src/Timer_TEST.cc +++ b/src/Timer_TEST.cc @@ -66,7 +66,7 @@ TEST(Timer_TEST, Copy) ignition::common::Timer t2 = t1; EXPECT_TRUE(t2.Running()); - // Stop the original + // Stop the original t1.Stop(); EXPECT_FALSE(t1.Running()); EXPECT_TRUE(t2.Running()); diff --git a/src/Util.cc b/src/Util.cc index d22ba30e..b713b20a 100644 --- a/src/Util.cc +++ b/src/Util.cc @@ -64,7 +64,7 @@ /// destruction order fiasco issues. ignition::common::SystemPaths& GetSystemPaths() { - static + static ignition::utils::NeverDestroyed paths; return paths.Access(); } From ea1e7238bce0b7c5f0b9b24de04c2ea9a66672cf Mon Sep 17 00:00:00 2001 From: Jenn Nguyen Date: Tue, 8 Feb 2022 18:17:54 -0800 Subject: [PATCH 3/3] return input _path instead Signed-off-by: Jenn Nguyen --- src/Filesystem.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Filesystem.cc b/src/Filesystem.cc index d0d15a36..ce66d6d6 100644 --- a/src/Filesystem.cc +++ b/src/Filesystem.cc @@ -211,7 +211,7 @@ std::string ignition::common::parentPath(const std::string &_path) p = fs::path(_path.substr(0, _path.size()-1)); if (!p.has_parent_path()) - return p.string(); + return _path; return p.parent_path().string(); }