diff options
author | Brad King <brad.king@kitware.com> | 2015-05-28 12:21:55 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2015-05-28 12:21:55 (GMT) |
commit | bf365792a11ce84426c8fc61738891c8e14fee43 (patch) | |
tree | c7d5fe9ab5a3d3924aa5f9d05ce8c1e71663d422 /Source/kwsys/SystemTools.cxx | |
parent | 2d4bef07d9450984bd865eae44192a2137ad899e (diff) | |
parent | ee71b75133d3e515172b5fbe3dccf7d3906f5a19 (diff) | |
download | CMake-bf365792a11ce84426c8fc61738891c8e14fee43.zip CMake-bf365792a11ce84426c8fc61738891c8e14fee43.tar.gz CMake-bf365792a11ce84426c8fc61738891c8e14fee43.tar.bz2 |
Merge branch 'upstream-kwsys' into update-kwsys
Diffstat (limited to 'Source/kwsys/SystemTools.cxx')
-rw-r--r-- | Source/kwsys/SystemTools.cxx | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 6c4a7a6..c834e34 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -2674,27 +2674,43 @@ kwsys_stl::string SystemTools::GetLastSystemError() bool SystemTools::RemoveFile(const kwsys_stl::string& source) { #ifdef _WIN32 + kwsys_stl::wstring const& ws = + SystemTools::ConvertToWindowsExtendedPath(source); + if (DeleteFileW(ws.c_str())) + { + return true; + } + DWORD err = GetLastError(); + if (err == ERROR_FILE_NOT_FOUND || + err == ERROR_PATH_NOT_FOUND) + { + return true; + } + if (err != ERROR_ACCESS_DENIED) + { + return false; + } + /* The file may be read-only. Try adding write permission. */ mode_t mode; - if ( !SystemTools::GetPermissions(source, mode) ) + if (!SystemTools::GetPermissions(source, mode) || + !SystemTools::SetPermissions(source, S_IWRITE)) { + SetLastError(err); return false; } - /* Win32 unlink is stupid --- it fails if the file is read-only */ - SystemTools::SetPermissions(source, S_IWRITE); -#endif -#ifdef _WIN32 - bool res = - _wunlink(SystemTools::ConvertToWindowsExtendedPath(source).c_str()) == 0; -#else - bool res = unlink(source.c_str()) != 0 ? false : true; -#endif -#ifdef _WIN32 - if ( !res ) + if (DeleteFileW(ws.c_str()) || + GetLastError() == ERROR_FILE_NOT_FOUND || + GetLastError() == ERROR_PATH_NOT_FOUND) { - SystemTools::SetPermissions(source, mode); + return true; } + /* Try to restore the original permissions. */ + SystemTools::SetPermissions(source, mode); + SetLastError(err); + return false; +#else + return unlink(source.c_str()) == 0 || errno == ENOENT; #endif - return res; } bool SystemTools::RemoveADirectory(const kwsys_stl::string& source) |