third_party/virtualbox/src/VBox/Main/src-server/MachineImpl.cpp
/**
 * Tries to create a machine settings file in the path stored in the machine
 * instance data. Used when a new machine is created to fail gracefully if
 * the settings file could not be written (e.g. because machine dir is read-only).
 * @return
 */
Tries to create a machine settings file in the path stored in the machine
instance data. Used when a new machine is created to fail gracefully if
the settings file could not be written .
@return
Tries to create a machine settings file in the path stored in the machine instance data . Used when a new machine is created to fail gracefully if the settings file could not be written . @return
HRESULT Machine::i_tryCreateMachineConfigFile(bool fForceOverwrite)
{
    HRESULT rc = S_OK;
    RTFILE f = NIL_RTFILE;
    int vrc = RTFileOpen(&f, mData->m_strConfigFileFull.c_str(), RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
    if (    RT_SUCCESS(vrc)
         || vrc == VERR_SHARING_VIOLATION
       )
    {
        if (RT_SUCCESS(vrc))
            RTFileClose(f);
        if (!fForceOverwrite)
            rc = setError(VBOX_E_FILE_ERROR,
                          tr("Machine settings file '%s' already exists"),
                          mData->m_strConfigFileFull.c_str());
        else
        {
            int vrc2 = RTFileDelete(mData->m_strConfigFileFull.c_str());
            if (RT_FAILURE(vrc2))
                rc = setError(VBOX_E_FILE_ERROR,
                              tr("Could not delete the existing settings file '%s' (%Rrc)"),
                              mData->m_strConfigFileFull.c_str(), vrc2);
        }
    }
    else if (    vrc != VERR_FILE_NOT_FOUND
              && vrc != VERR_PATH_NOT_FOUND
            )
        rc = setError(VBOX_E_FILE_ERROR,
                      tr("Invalid machine settings file name '%s' (%Rrc)"),
                      mData->m_strConfigFileFull.c_str(),
                      vrc);
    return rc;
}
HRESULT Machine :: i_tryCreateMachineConfigFile ( bool fForceOverwrite ) { HRESULT rc = S_OK ; RTFILE f = NIL_RTFILE ; int vrc = RTFileOpen ( & f , mData -> m_strConfigFileFull . c_str ( ) , RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE ) ; if ( RT_SUCCESS ( vrc ) || vrc == VERR_SHARING_VIOLATION ) { if ( RT_SUCCESS ( vrc ) ) RTFileClose ( f ) ; if ( ! fForceOverwrite ) rc = setError ( VBOX_E_FILE_ERROR , tr ( " " ) , mData -> m_strConfigFileFull . c_str ( ) ) ; else { int vrc2 = RTFileDelete ( mData -> m_strConfigFileFull . c_str ( ) ) ; if ( RT_FAILURE ( vrc2 ) ) rc = setError ( VBOX_E_FILE_ERROR , tr ( " " ) , mData -> m_strConfigFileFull . c_str ( ) , vrc2 ) ; } } else if ( vrc != VERR_FILE_NOT_FOUND && vrc != VERR_PATH_NOT_FOUND ) rc = setError ( VBOX_E_FILE_ERROR , tr ( " " ) , mData -> m_strConfigFileFull . c_str ( ) , vrc ) ; return rc ; }
Tries to create a machine settings file in the path stored in the machine
 instance data.
Tries to create a machine settings file in the path stored in the machine instance data .
// when we create a new machine, we must be able to create the settings file /* try to delete the config file, as otherwise the creation
             * of a new settings file will fail. */