Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll committed Feb 9, 2022
1 parent 0038e2f commit 10f0df8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/Filesystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ bool ignition::common::createDirectories(const std::string &_path)
/////////////////////////////////////////////////
std::string const ignition::common::separator(std::string const &_s)
{
fs::path path(_s);
return (_s / fs::path("")).string();
return _s + std::string{fs::path::preferred_separator};
}

/////////////////////////////////////////////////
Expand Down Expand Up @@ -138,6 +137,11 @@ std::string ignition::common::joinPaths(
fs::path p1{_path1};
fs::path p2{_path2};

if (p1.empty())
{
p1 = ignition::common::separator("");
}

bool is_url = false;

if (_path1.find("://") == std::string::npos)
Expand Down Expand Up @@ -195,11 +199,12 @@ bool ignition::common::chdir(const std::string &_dir)
/////////////////////////////////////////////////
std::string ignition::common::basename(const std::string &_path)
{
fs::path p(_path);
// Maintain compatibility with ign-common
if (*_path.rbegin() == fs::path::preferred_separator)
p = fs::path(_path.substr(0, _path.size()-1));
return p.filename().string();
fs::path p = fs::path(_path);
p /= "FOO.TXT";
p = p.lexically_normal();
p = p.parent_path();
return p.filename().string().empty() ?
std::string{fs::path::preferred_separator} : p.filename().string();
}

/////////////////////////////////////////////////
Expand Down
10 changes: 10 additions & 0 deletions src/Filesystem_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,16 @@ TEST_F(FilesystemTest, uniquePaths)
EXPECT_TRUE(removeDirectory(dirExistingRt)) << dirExistingRt;
}

/////////////////////////////////////////////////
TEST_F(FilesystemTest, separator)
{
#ifndef _WIN32
EXPECT_EQ("/", ignition::common::separator(""));
#else
EXPECT_EQ("\\", ignition::common::separator(""));
#endif
}

/////////////////////////////////////////////////
/// Main
int main(int argc, char **argv)
Expand Down

0 comments on commit 10f0df8

Please sign in to comment.