realpath returns a path, not a string.

This commit is contained in:
James Turner 2016-07-04 09:04:46 +01:00
parent c40044feeb
commit 9812315d96
2 changed files with 7 additions and 12 deletions

View File

@ -927,7 +927,7 @@ SGPath SGPath::documents(const SGPath& def)
}
//------------------------------------------------------------------------------
std::string SGPath::realpath() const
SGPath SGPath::realpath() const
{
#if defined(_MSC_VER) /*for MS compilers */ || defined(_WIN32) /*needed for non MS windows compilers like MingW*/
// with absPath NULL, will allocate, and ignore length
@ -947,21 +947,16 @@ std::string SGPath::realpath() const
this_dir = "/";
}
if (file() == "..") {
this_dir = SGPath(SGPath(this_dir).realpath()).dir();
this_dir = SGPath(this_dir).realpath().dir();
if (this_dir.empty()) { // invalid path: .. above root
return "";
return SGPath();
}
return SGPath(this_dir).realpath(); // use native path separator,
// and handle 'existing/nonexisting/../symlink' paths
}
return SGPath(this_dir).realpath() +
#if defined(_MSC_VER) || defined(_WIN32)
"\\" + file();
#else
"/" + file();
#endif
return SGPath(this_dir).realpath() / file();
}
std::string p(buf);
SGPath p(SGPath::fromLocal8Bit(buf));
free(buf);
return p;
}

View File

@ -131,10 +131,10 @@ public:
void concat( const std::string& p );
/**
* Returns a string with the absolute pathname that names the same file, whose
* Returns a path with the absolute pathname that names the same file, whose
* resolution does not involve '.', '..', or symbolic links.
*/
std::string realpath() const;
SGPath realpath() const;
/**
* Get the file part of the path (everything after the last path sep)