VirtualBox

Changeset 95450 in vbox


Ignore:
Timestamp:
Jun 30, 2022 8:58:34 AM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
152057
Message:

Main/MachineImpl: Cleaned up all the RTFileDelete() calls to only use the new Machine::i_deleteFile() method. This should make it a lot easier to track / debug stuff.

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/MachineImpl.h

    r95423 r95450  
    725725
    726726    void i_addMediumToRegistry(ComObjPtr<Medium> &pMedium);
     727
     728    HRESULT i_deleteFile(const Utf8Str &strFile, bool fIgnoreFailures = false, const Utf8Str &strWhat = "", int *prc = NULL);
    727729
    728730    HRESULT i_createImplicitDiffs(IProgress *aProgress,
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r95423 r95450  
    909909            /* try to delete the config file, as otherwise the creation
    910910             * 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"));
    916912        }
    917913    }
     
    55125508            rc = task.m_pProgress->SetNextOperation(BstrFmt(tr("Deleting '%s'"), it->c_str()).raw(), 1);
    55135509            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);
    55195511        }
    55205512
     
    55295521            /** @todo Find a way to avoid referring directly to iprt/xml.h here. */
    55305522            Utf8StrFmt otherXml("%s%s", mData->m_strConfigFileFull.c_str(), xml::XmlFileWriter::s_pszTmpSuff);
    5531             RTFileDelete(otherXml.c_str());
     5523            i_deleteFile(otherXml, true /* fIgnoreFailures */);
    55325524            otherXml.printf("%s%s", mData->m_strConfigFileFull.c_str(), xml::XmlFileWriter::s_pszPrevSuff);
    5533             RTFileDelete(otherXml.c_str());
     5525            i_deleteFile(otherXml, true /* fIgnoreFailures */);
    55345526
    55355527            /* delete the Logs folder, nothing important should be left
     
    55465538                 * files that may have been created by the GUI. */
    55475539                Utf8StrFmt log("%s%cVBox.log", logFolder.c_str(), RTPATH_DELIMITER);
    5548                 RTFileDelete(log.c_str());
     5540                i_deleteFile(log, true /* fIgnoreFailures */);
    55495541                log.printf("%s%cVBox.png", logFolder.c_str(), RTPATH_DELIMITER);
    5550                 RTFileDelete(log.c_str());
     5542                i_deleteFile(log, true /* fIgnoreFailures */);
    55515543                for (ULONG i = uLogHistoryCount; i > 0; i--)
    55525544                {
    55535545                    log.printf("%s%cVBox.log.%u", logFolder.c_str(), RTPATH_DELIMITER, i);
    5554                     RTFileDelete(log.c_str());
     5546                    i_deleteFile(log, true /* fIgnoreFailures */);
    55555547                    log.printf("%s%cVBox.png.%u", logFolder.c_str(), RTPATH_DELIMITER, i);
    5556                     RTFileDelete(log.c_str());
     5548                    i_deleteFile(log, true /* fIgnoreFailures */);
    55575549                }
    55585550                log.printf("%s%cVBoxUI.log", logFolder.c_str(), RTPATH_DELIMITER);
    5559                 RTFileDelete(log.c_str());
     5551                i_deleteFile(log, true /* fIgnoreFailures */);
    55605552#if defined(RT_OS_WINDOWS)
    55615553                log.printf("%s%cVBoxStartup.log", logFolder.c_str(), RTPATH_DELIMITER);
    5562                 RTFileDelete(log.c_str());
     5554                i_deleteFile(log, true /* fIgnoreFailures */);
    55635555                log.printf("%s%cVBoxHardening.log", logFolder.c_str(), RTPATH_DELIMITER);
    5564                 RTFileDelete(log.c_str());
     5556                i_deleteFile(log, true /* fIgnoreFailures */);
    55655557#endif
    55665558
     
    78687860    {
    78697861        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);
    78717864        if (vrc2 == VERR_PATH_NOT_FOUND || vrc2 == VERR_FILE_NOT_FOUND)
    78727865        {
     
    78827875        getLogFolder(strOldStartupLogFile);
    78837876        strOldStartupLogFile.append(RTPATH_SLASH_STR "VBoxStartup.log");
    7884         RTFileDelete(strOldStartupLogFile.c_str());
     7877        i_deleteFile(strOldStartupLogFile, true /* fIgnoreFailures */);
    78857878    }
    78867879#else
     
    1045110444            pNewConfig->write(mData->m_strConfigFileFull, pCryptoIf, pszPassword);
    1045210445            if (aFlags & SaveS_RemoveBackup)
    10453                 RTFileDelete((mData->m_strConfigFileFull + "-prev").c_str());
     10446                i_deleteFile(mData->m_strConfigFileFull + "-prev", true /* fIgnoreFailures */);
    1045410447        }
    1045510448
     
    1046810461        // delete any newly created settings file
    1046910462        if (fSettingsFileIsNew)
    10470             RTFileDelete(mData->m_strConfigFileFull.c_str());
     10463            i_deleteFile(mData->m_strConfigFileFull, true /* fIgnoreFailures */);
    1047110464
    1047210465        // restore old config
     
    1116711160        }
    1116811161    }
     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 */
     11175HRESULT 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;
    1116911207}
    1117011208
     
    1354713585            // No need to check whether this is shared with a snapshot here
    1354813586            // 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 */);
    1355013588        }
    1355113589    }
     
    1507515113                                // this checks the SnapshotMachine's state file paths
    1507615114           )
    15077             RTFileDelete(strStateFile.c_str());
     15115            i_deleteFile(strStateFile, true /* fIgnoreFailures */);
    1507815116}
    1507915117
     
    1532915367                                                // ... none of the snapshots share the saved state file
    1533015368               )
    15331                 RTFileDelete(mSSData->strStateFilePath.c_str());
     15369                i_deleteFile(mSSData->strStateFilePath, true /* fIgnoreFailures */);
    1533215370        }
    1533315371
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette