Changeset 95450 in vbox
- Timestamp:
- Jun 30, 2022 8:58:34 AM (3 years ago)
- svn:sync-xref-src-repo-rev:
- 152057
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/MachineImpl.h
r95423 r95450 725 725 726 726 void i_addMediumToRegistry(ComObjPtr<Medium> &pMedium); 727 728 HRESULT i_deleteFile(const Utf8Str &strFile, bool fIgnoreFailures = false, const Utf8Str &strWhat = "", int *prc = NULL); 727 729 728 730 HRESULT i_createImplicitDiffs(IProgress *aProgress, -
trunk/src/VBox/Main/src-server/MachineImpl.cpp
r95423 r95450 909 909 /* try to delete the config file, as otherwise the creation 910 910 * of a new settings file will fail. */ 911 int vrc2 = RTFileDelete(mData->m_strConfigFileFull.c_str()); 912 if (RT_FAILURE(vrc2)) 913 rc = setErrorBoth(VBOX_E_FILE_ERROR, vrc2, 914 tr("Could not delete the existing settings file '%s' (%Rrc)"), 915 mData->m_strConfigFileFull.c_str(), vrc2); 911 i_deleteFile(mData->m_strConfigFileFull.c_str(), false /* fIgnoreFailures */, tr("existing settings file")); 916 912 } 917 913 } … … 5512 5508 rc = task.m_pProgress->SetNextOperation(BstrFmt(tr("Deleting '%s'"), it->c_str()).raw(), 1); 5513 5509 if (FAILED(rc)) throw rc; 5514 5515 int vrc = RTFileDelete(strFile.c_str()); 5516 if (RT_FAILURE(vrc)) 5517 throw setErrorBoth(VBOX_E_IPRT_ERROR, vrc, 5518 tr("Could not delete file '%s' (%Rrc)"), strFile.c_str(), vrc); 5510 i_deleteFile(strFile); 5519 5511 } 5520 5512 … … 5529 5521 /** @todo Find a way to avoid referring directly to iprt/xml.h here. */ 5530 5522 Utf8StrFmt otherXml("%s%s", mData->m_strConfigFileFull.c_str(), xml::XmlFileWriter::s_pszTmpSuff); 5531 RTFileDelete(otherXml.c_str());5523 i_deleteFile(otherXml, true /* fIgnoreFailures */); 5532 5524 otherXml.printf("%s%s", mData->m_strConfigFileFull.c_str(), xml::XmlFileWriter::s_pszPrevSuff); 5533 RTFileDelete(otherXml.c_str());5525 i_deleteFile(otherXml, true /* fIgnoreFailures */); 5534 5526 5535 5527 /* delete the Logs folder, nothing important should be left … … 5546 5538 * files that may have been created by the GUI. */ 5547 5539 Utf8StrFmt log("%s%cVBox.log", logFolder.c_str(), RTPATH_DELIMITER); 5548 RTFileDelete(log.c_str());5540 i_deleteFile(log, true /* fIgnoreFailures */); 5549 5541 log.printf("%s%cVBox.png", logFolder.c_str(), RTPATH_DELIMITER); 5550 RTFileDelete(log.c_str());5542 i_deleteFile(log, true /* fIgnoreFailures */); 5551 5543 for (ULONG i = uLogHistoryCount; i > 0; i--) 5552 5544 { 5553 5545 log.printf("%s%cVBox.log.%u", logFolder.c_str(), RTPATH_DELIMITER, i); 5554 RTFileDelete(log.c_str());5546 i_deleteFile(log, true /* fIgnoreFailures */); 5555 5547 log.printf("%s%cVBox.png.%u", logFolder.c_str(), RTPATH_DELIMITER, i); 5556 RTFileDelete(log.c_str());5548 i_deleteFile(log, true /* fIgnoreFailures */); 5557 5549 } 5558 5550 log.printf("%s%cVBoxUI.log", logFolder.c_str(), RTPATH_DELIMITER); 5559 RTFileDelete(log.c_str());5551 i_deleteFile(log, true /* fIgnoreFailures */); 5560 5552 #if defined(RT_OS_WINDOWS) 5561 5553 log.printf("%s%cVBoxStartup.log", logFolder.c_str(), RTPATH_DELIMITER); 5562 RTFileDelete(log.c_str());5554 i_deleteFile(log, true /* fIgnoreFailures */); 5563 5555 log.printf("%s%cVBoxHardening.log", logFolder.c_str(), RTPATH_DELIMITER); 5564 RTFileDelete(log.c_str());5556 i_deleteFile(log, true /* fIgnoreFailures */); 5565 5557 #endif 5566 5558 … … 7868 7860 { 7869 7861 Utf8Str strHardeningLogFile = i_getHardeningLogFilename(); 7870 int vrc2 = RTFileDelete(strHardeningLogFile.c_str()); 7862 int vrc2; 7863 /* ignore rc */ i_deleteFile(strHardeningLogFile, false /* fIgnoreFailures */, tr("hardening log file"), &vrc2); 7871 7864 if (vrc2 == VERR_PATH_NOT_FOUND || vrc2 == VERR_FILE_NOT_FOUND) 7872 7865 { … … 7882 7875 getLogFolder(strOldStartupLogFile); 7883 7876 strOldStartupLogFile.append(RTPATH_SLASH_STR "VBoxStartup.log"); 7884 RTFileDelete(strOldStartupLogFile.c_str());7877 i_deleteFile(strOldStartupLogFile, true /* fIgnoreFailures */); 7885 7878 } 7886 7879 #else … … 10451 10444 pNewConfig->write(mData->m_strConfigFileFull, pCryptoIf, pszPassword); 10452 10445 if (aFlags & SaveS_RemoveBackup) 10453 RTFileDelete((mData->m_strConfigFileFull + "-prev").c_str());10446 i_deleteFile(mData->m_strConfigFileFull + "-prev", true /* fIgnoreFailures */); 10454 10447 } 10455 10448 … … 10468 10461 // delete any newly created settings file 10469 10462 if (fSettingsFileIsNew) 10470 RTFileDelete(mData->m_strConfigFileFull.c_str());10463 i_deleteFile(mData->m_strConfigFileFull, true /* fIgnoreFailures */); 10471 10464 10472 10465 // restore old config … … 11167 11160 } 11168 11161 } 11162 } 11163 11164 /** 11165 * Physically deletes a file belonging to a machine. 11166 * 11167 * @returns HRESULT 11168 * @retval VBOX_E_FILE_ERROR on failure. 11169 * @param strFile File to delete. 11170 * @param fIgnoreFailures Whether to ignore deletion failures. Defaults to \c false. 11171 * VERR_FILE_NOT_FOUND and VERR_PATH_NOT_FOUND always will be ignored. 11172 * @param strWhat File hint which will be used when setting an error. Optional. 11173 * @param prc Where to return IPRT's error code on failure. Optional and can be NULL. 11174 */ 11175 HRESULT Machine::i_deleteFile(const Utf8Str &strFile, bool fIgnoreFailures /* = false */, 11176 const Utf8Str &strWhat /* = "" */, int *prc /* = NULL */) 11177 { 11178 AssertReturn(strFile.isNotEmpty(), E_INVALIDARG); 11179 11180 HRESULT hrc = S_OK; 11181 11182 LogFunc(("Deleting file '%s'\n", strFile.c_str())); 11183 11184 int vrc = RTFileDelete(strFile.c_str()); 11185 if (RT_FAILURE(vrc)) 11186 { 11187 if ( !fIgnoreFailures 11188 /* Don't (externally) bitch about stuff which doesn't exist. */ 11189 && ( vrc != VERR_FILE_NOT_FOUND 11190 && vrc != VERR_PATH_NOT_FOUND 11191 ) 11192 ) 11193 { 11194 LogRel(("Deleting file '%s' failed: %Rrc\n", strFile.c_str(), vrc)); 11195 11196 Utf8StrFmt strError("Error deleting %s '%s' (%Rrc)", 11197 strWhat.isEmpty() ? tr("file") : strWhat.c_str(), strFile.c_str(), vrc); 11198 hrc = setErrorBoth(VBOX_E_FILE_ERROR, vrc, strError.c_str(), 11199 strFile.c_str(), vrc); 11200 } 11201 11202 if (prc) 11203 *prc = vrc; 11204 } 11205 11206 return hrc; 11169 11207 } 11170 11208 … … 13547 13585 // No need to check whether this is shared with a snapshot here 13548 13586 // because we certainly created a fresh saved state file here. 13549 RTFileDelete(task.m_strStateFilePath.c_str());13587 i_deleteFile(task.m_strStateFilePath, true /* fIgnoreFailures */); 13550 13588 } 13551 13589 } … … 15075 15113 // this checks the SnapshotMachine's state file paths 15076 15114 ) 15077 RTFileDelete(strStateFile.c_str());15115 i_deleteFile(strStateFile, true /* fIgnoreFailures */); 15078 15116 } 15079 15117 … … 15329 15367 // ... none of the snapshots share the saved state file 15330 15368 ) 15331 RTFileDelete(mSSData->strStateFilePath.c_str());15369 i_deleteFile(mSSData->strStateFilePath, true /* fIgnoreFailures */); 15332 15370 } 15333 15371
Note:
See TracChangeset
for help on using the changeset viewer.