MCPcopy Create free account
hub / github.com/Kitware/CMake / CleanupFiles

Method CleanupFiles

Source/cmCoreTryCompile.cxx:1353–1412  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1351}
1352
1353void cmCoreTryCompile::CleanupFiles(std::string const& binDir)
1354{
1355 if (binDir.empty()) {
1356 return;
1357 }
1358
1359 if (!IsTemporary(binDir)) {
1360 cmSystemTools::Error(cmStrCat(
1361 "TRY_COMPILE attempt to remove -rf directory that does not contain "
1362 "CMakeTmp or CMakeScratch: \"",
1363 binDir, '"'));
1364 return;
1365 }
1366
1367 cmsys::Directory dir;
1368 dir.Load(binDir);
1369 std::set<std::string> deletedFiles;
1370 for (unsigned long i = 0; i < dir.GetNumberOfFiles(); ++i) {
1371 char const* fileName = dir.GetFile(i);
1372 if (strcmp(fileName, ".") != 0 && strcmp(fileName, "..") != 0 &&
1373 // Do not delete NFS temporary files.
1374 !cmHasPrefix(fileName, ".nfs")) {
1375 if (deletedFiles.insert(fileName).second) {
1376 std::string const fullPath = cmStrCat(binDir, '/', fileName);
1377 if (cmSystemTools::FileIsSymlink(fullPath)) {
1378 cmSystemTools::RemoveFile(fullPath);
1379 } else if (cmSystemTools::FileIsDirectory(fullPath)) {
1380 this->CleanupFiles(fullPath);
1381 cmSystemTools::RemoveADirectory(fullPath);
1382 } else {
1383#ifdef _WIN32
1384 // Sometimes anti-virus software hangs on to new files so we
1385 // cannot delete them immediately. Try a few times.
1386 cmSystemTools::WindowsFileRetry retry =
1387 cmSystemTools::GetWindowsFileRetry();
1388 cmsys::Status status;
1389 while (!((status = cmSystemTools::RemoveFile(fullPath))) &&
1390 --retry.Count && cmSystemTools::FileExists(fullPath)) {
1391 cmSystemTools::Delay(retry.Delay);
1392 }
1393 if (retry.Count == 0)
1394#else
1395 cmsys::Status status = cmSystemTools::RemoveFile(fullPath);
1396 if (!status)
1397#endif
1398 {
1399 this->Makefile->IssueMessage(
1400 MessageType::FATAL_ERROR,
1401 cmStrCat("The file:\n ", fullPath,
1402 "\ncould not be removed:\n ", status.GetString()));
1403 }
1404 }
1405 }
1406 }
1407 }
1408
1409 if (binDir.find("CMakeScratch") != std::string::npos) {
1410 cmSystemTools::RemoveADirectory(binDir);

Callers 2

cmTryCompileCommandFunction · 0.80
TryRunCodeMethod · 0.80

Calls 10

cmHasPrefixFunction · 0.85
ErrorClass · 0.70
cmStrCatFunction · 0.70
FileExistsFunction · 0.50
emptyMethod · 0.45
LoadMethod · 0.45
insertMethod · 0.45
IssueMessageMethod · 0.45
GetStringMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected