mirror of
https://github.com/etlegacy/Update-Installer.git
synced 2024-11-26 22:01:39 +00:00
Add FileOps method to get the canonical path for a file and the Unix implementation.
This commit is contained in:
parent
b49332eaab
commit
55ebb233cb
2 changed files with 21 additions and 0 deletions
|
@ -233,3 +233,23 @@ void FileOps::rmdirRecursive(const char* path) throw (IOException)
|
|||
rmdir(path);
|
||||
}
|
||||
|
||||
std::string FileOps::canonicalPath(const char* path)
|
||||
{
|
||||
#ifdef PLATFORM_UNIX
|
||||
// on Linux and Mac OS 10.6, realpath() can allocate the required
|
||||
// amount of memory automatically, however Mac OS 10.5 does not support
|
||||
// this, so we used a fixed-sized buffer on all platforms
|
||||
char canonicalPathBuffer[PATH_MAX+1];
|
||||
if (realpath(path,canonicalPathBuffer) != 0)
|
||||
{
|
||||
return std::string(canonicalPathBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw IOException("Error reading canonical path for " + std::string(path));
|
||||
}
|
||||
#else
|
||||
throw IOException("Not implemented");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -36,5 +36,6 @@ class FileOps
|
|||
static void touch(const char* path) throw (IOException);
|
||||
static std::string dirname(const char* path);
|
||||
static void rmdirRecursive(const char* dir) throw (IOException);
|
||||
static std::string canonicalPath(const char* path);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue