Skip to content

Commit

Permalink
Fixed parentPath() return when input has no parent (#307)
Browse files Browse the repository at this point in the history
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
  • Loading branch information
jennuine authored Feb 9, 2022
1 parent e79b31f commit ef9e3a0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/Filesystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 _path;

return p.parent_path().string();
}

Expand Down
3 changes: 3 additions & 0 deletions src/Filesystem_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/////////////////////////////////////////////////
Expand Down
6 changes: 3 additions & 3 deletions src/Timer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -71,7 +71,7 @@ std::chrono::duration<double> Timer::ElapsedTime() const
}
else
{
std::chrono::duration<double> diff =
std::chrono::duration<double> diff =
this->dataPtr->stop - this->dataPtr->start;
return diff;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Timer_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/Util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
/// destruction order fiasco issues.
ignition::common::SystemPaths& GetSystemPaths()
{
static
static
ignition::utils::NeverDestroyed<ignition::common::SystemPaths> paths;
return paths.Access();
}
Expand Down

0 comments on commit ef9e3a0

Please sign in to comment.