Fix try_compile RemoveFile anti-virus loop (#11503)
Commit 3827991e
(...fix...not being able to remove try compile code,
2008-03-26) introduced a loop of RemoveFile attempts to overcome
anti-virus locks on recently created try_compile executables. Fix the
logic in this loop to work when the file is already missing.
This commit is contained in:
parent
c300ef1c66
commit
097294e667
|
@ -396,33 +396,23 @@ void cmCoreTryCompile::CleanupFiles(const char* binDir)
|
|||
}
|
||||
else
|
||||
{
|
||||
if(!cmSystemTools::RemoveFile(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)
|
||||
// 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()))
|
||||
{
|
||||
cmSystemTools::Delay(500);
|
||||
if(cmSystemTools::RemoveFile(fullPath.c_str()))
|
||||
{
|
||||
removed = true;
|
||||
}
|
||||
numAttempts++;
|
||||
}
|
||||
if(!removed)
|
||||
if(tries == 0)
|
||||
{
|
||||
std::string m = "Remove failed on file: ";
|
||||
m += fullPath;
|
||||
std::string m = "Remove failed on file: " + fullPath;
|
||||
cmSystemTools::ReportLastSystemError(m.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cmCoreTryCompile::FindOutputFile(const char* targetName)
|
||||
|
|
Loading…
Reference in New Issue