KWSys 2015-05-27 (61e0419f)
Extract upstream KWSys using the following shell commands. $ git archive --prefix=upstream-kwsys/ 61e0419f | tar x $ git shortlog --no-merges --abbrev=8 --format='%h %s' b1d560a0..61e0419f Brad King (1): 61e0419f SystemTools: Teach RemoveFile to tolerate missing file Matt McCormick (1): 9a6b7c3f cmake: Set CMP0056 to NEW
This commit is contained in:
parent
3b815ed283
commit
ee71b75133
|
@ -88,6 +88,9 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6.3 FATAL_ERROR)
|
|||
IF(POLICY CMP0025)
|
||||
CMAKE_POLICY(SET CMP0025 NEW)
|
||||
ENDIF()
|
||||
IF(POLICY CMP0056)
|
||||
CMAKE_POLICY(SET CMP0056 NEW)
|
||||
ENDIF()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# If a namespace is not specified, use "kwsys" and enable testing.
|
||||
|
|
|
@ -2674,27 +2674,43 @@ kwsys_stl::string SystemTools::GetLastSystemError()
|
|||
bool SystemTools::RemoveFile(const kwsys_stl::string& source)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
mode_t mode;
|
||||
if ( !SystemTools::GetPermissions(source, mode) )
|
||||
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;
|
||||
}
|
||||
/* 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 )
|
||||
/* The file may be read-only. Try adding write permission. */
|
||||
mode_t mode;
|
||||
if (!SystemTools::GetPermissions(source, mode) ||
|
||||
!SystemTools::SetPermissions(source, S_IWRITE))
|
||||
{
|
||||
SystemTools::SetPermissions(source, mode);
|
||||
SetLastError(err);
|
||||
return false;
|
||||
}
|
||||
if (DeleteFileW(ws.c_str()) ||
|
||||
GetLastError() == ERROR_FILE_NOT_FOUND ||
|
||||
GetLastError() == ERROR_PATH_NOT_FOUND)
|
||||
{
|
||||
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)
|
||||
|
|
|
@ -156,6 +156,24 @@ static bool CheckFileOperations()
|
|||
res = false;
|
||||
}
|
||||
|
||||
kwsys_stl::string const testFileMissing(testNewDir + "/testMissingFile.txt");
|
||||
if (!kwsys::SystemTools::RemoveFile(testFileMissing))
|
||||
{
|
||||
std::string const& msg = kwsys::SystemTools::GetLastSystemError();
|
||||
kwsys_ios::cerr <<
|
||||
"RemoveFile(\"" << testFileMissing << "\") failed: " << msg << "\n";
|
||||
res = false;
|
||||
}
|
||||
|
||||
kwsys_stl::string const testFileMissingDir(testNewDir + "/missing/file.txt");
|
||||
if (!kwsys::SystemTools::RemoveFile(testFileMissingDir))
|
||||
{
|
||||
std::string const& msg = kwsys::SystemTools::GetLastSystemError();
|
||||
kwsys_ios::cerr <<
|
||||
"RemoveFile(\"" << testFileMissingDir << "\") failed: " << msg << "\n";
|
||||
res = false;
|
||||
}
|
||||
|
||||
kwsys::SystemTools::Touch(testNewFile.c_str(), true);
|
||||
if (!kwsys::SystemTools::RemoveADirectory(testNewDir))
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue