CPack: Try harder to remove temporary dir (#10793)

Windows filesystems sometimes lock files temporarily.  Try removing the
CPack temp install folder multiple times before giving up.
This commit is contained in:
Brad King 2010-06-04 14:32:08 -04:00
parent 3ac3dea6f0
commit fdb5f78705
3 changed files with 20 additions and 2 deletions

View File

@ -789,7 +789,7 @@ int cmCPackGenerator::DoPackage()
cmCPackLogger(cmCPackLog::LOG_VERBOSE,
"Remove toplevel directory: "
<< toplevelDirectory << std::endl);
if ( !cmSystemTools::RemoveADirectory(toplevelDirectory) )
if ( !cmSystemTools::RepeatedRemoveDirectory(toplevelDirectory) )
{
cmCPackLogger(cmCPackLog::LOG_ERROR,
"Problem removing toplevel directory: "
@ -1084,7 +1084,7 @@ int cmCPackGenerator::CleanTemporaryDirectory()
cmCPackLogger(cmCPackLog::LOG_OUTPUT,
"- Clean temporary : "
<< tempInstallDirectory << std::endl);
if(!cmsys::SystemTools::RemoveADirectory(tempInstallDirectory))
if(!cmSystemTools::RepeatedRemoveDirectory(tempInstallDirectory))
{
cmCPackLogger(cmCPackLog::LOG_ERROR,
"Problem removing temporary directory: " <<

View File

@ -2938,3 +2938,18 @@ bool cmSystemTools::CheckRPath(std::string const& file,
return false;
#endif
}
//----------------------------------------------------------------------------
bool cmSystemTools::RepeatedRemoveDirectory(const char* dir)
{
// Windows sometimes locks files temporarily so try a few times.
for(int i = 0; i < 10; ++i)
{
if(cmSystemTools::RemoveADirectory(dir))
{
return true;
}
cmSystemTools::Delay(100);
}
return false;
}

View File

@ -436,6 +436,9 @@ public:
static bool CheckRPath(std::string const& file,
std::string const& newRPath);
/** Remove a directory; repeat a few times in case of locked files. */
static bool RepeatedRemoveDirectory(const char* dir);
private:
static bool s_ForceUnixPaths;
static bool s_RunCommandHideConsole;