Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed parentPath() return when input has no parent #307

Merged
merged 3 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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