Skip to content

Commit

Permalink
Path: small adjustments to getAbsolutePath() Windows implementation…
Browse files Browse the repository at this point in the history
… to match Linux one
  • Loading branch information
firewave committed Aug 14, 2024
1 parent f229fde commit 49daf24
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,16 @@ bool Path::isHeader(const std::string &path)

std::string Path::getAbsoluteFilePath(const std::string& filePath)
{
if (filePath.empty())
return "";

std::string absolute_path;
#ifdef _WIN32
char absolute[_MAX_PATH];
if (_fullpath(absolute, filePath.c_str(), _MAX_PATH))
absolute_path = absolute;
if (absolute_path.back() == '\\')
absolute_path.pop_back();
#elif defined(__linux__) || defined(__sun) || defined(__hpux) || defined(__GNUC__) || defined(__CPPCHECK__)
// simplify the path since any non-existent part has to exist even if discarded by ".."
std::string spath = Path::simplifyPath(filePath);
Expand Down
7 changes: 7 additions & 0 deletions test/testpath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,13 @@ class TestPath : public TestFixture {
ASSERT_EQUALS(cwd_up, Path::getAbsoluteFilePath(Path::join(cwd, ".\\..\\")));

ASSERT_EQUALS(cwd, Path::getAbsoluteFilePath("."));
#ifndef _WIN32
TODO_ASSERT_EQUALS(cwd, "", Path::getAbsoluteFilePath("./"));
TODO_ASSERT_EQUALS(cwd, "", Path::getAbsoluteFilePath(".\\"));
#else
ASSERT_EQUALS(cwd, Path::getAbsoluteFilePath("./"));
ASSERT_EQUALS(cwd, Path::getAbsoluteFilePath(".\\"));
#endif

ASSERT_EQUALS("", Path::getAbsoluteFilePath(""));

Expand All @@ -475,6 +480,8 @@ class TestPath : public TestFixture {
#else
ASSERT_EQUALS(Path::toNativeSeparators(Path::join(cwd, "testabspath2.txt")), Path::getAbsoluteFilePath("testabspath2.txt"));
#endif

// TODO: test with symlinks
}
};

Expand Down

0 comments on commit 49daf24

Please sign in to comment.