Merge topic 'try_compile-RemoveFile'
097294e
Fix try_compile RemoveFile anti-virus loop (#11503)
This commit is contained in:
commit
72ebd4ee12
|
@ -397,28 +397,18 @@ void cmCoreTryCompile::CleanupFiles(const char* binDir)
|
|||
}
|
||||
else
|
||||
{
|
||||
if(!cmSystemTools::RemoveFile(fullPath.c_str()))
|
||||
// Sometimes anti-virus software hangs on to new files so we
|
||||
// cannot delete them immediately. Try a few times.
|
||||
int tries = 5;
|
||||
while(!cmSystemTools::RemoveFile(fullPath.c_str()) &&
|
||||
--tries && cmSystemTools::FileExists(fullPath.c_str()))
|
||||
{
|
||||
bool removed = false;
|
||||
int numAttempts = 0;
|
||||
// sometimes anti-virus software hangs on to
|
||||
// new files and we can not delete them, so try
|
||||
// 5 times with .5 second delay between tries.
|
||||
while(!removed && numAttempts < 5)
|
||||
{
|
||||
cmSystemTools::Delay(500);
|
||||
if(cmSystemTools::RemoveFile(fullPath.c_str()))
|
||||
{
|
||||
removed = true;
|
||||
}
|
||||
numAttempts++;
|
||||
}
|
||||
if(!removed)
|
||||
{
|
||||
std::string m = "Remove failed on file: ";
|
||||
m += fullPath;
|
||||
cmSystemTools::ReportLastSystemError(m.c_str());
|
||||
}
|
||||
cmSystemTools::Delay(500);
|
||||
}
|
||||
if(tries == 0)
|
||||
{
|
||||
std::string m = "Remove failed on file: " + fullPath;
|
||||
cmSystemTools::ReportLastSystemError(m.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue