VirtualBox

Ignore:
Timestamp:
Oct 26, 2010 11:18:04 AM (14 years ago)
Author:
vboxsync
Message:

Main: partial revert or r67042, bring back the overwrite parameter

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/MachineImpl.cpp

    r33451 r33458  
    253253 *  @param strName      name for the machine
    254254 *  @param aId          UUID for the new machine.
    255  *  @param aOsType      Optional OS Type of this machine.
     255 *  @param aOsType      OS Type of this machine or NULL.
     256 *  @param fForceOverwrite Whether to overwrite an existing machine settings file.
    256257 *
    257258 *  @return  Success indicator. if not S_OK, the machine object is invalid
     
    260261                      const Utf8Str &strConfigFile,
    261262                      const Utf8Str &strName,
     263                      GuestOSType *aOsType,
    262264                      const Guid &aId,
    263                       GuestOSType *aOsType /* = NULL */)
     265                      bool fForceOverwrite)
    264266{
    265267    LogFlowThisFuncEnter();
     
    273275    if (FAILED(rc)) return rc;
    274276
    275     rc = tryCreateMachineConfigFile();
     277    rc = tryCreateMachineConfigFile(fForceOverwrite);
    276278    if (FAILED(rc)) return rc;
    277279
     
    473475    if (FAILED(rc)) return rc;
    474476
    475     rc = tryCreateMachineConfigFile();
     477    rc = tryCreateMachineConfigFile(false /* fForceOverwrite */);
    476478    if (FAILED(rc)) return rc;
    477479
     
    569571 * @return
    570572 */
    571 HRESULT Machine::tryCreateMachineConfigFile()
     573HRESULT Machine::tryCreateMachineConfigFile(bool fForceOverwrite)
    572574{
    573575    HRESULT rc = S_OK;
     
    582584        if (RT_SUCCESS(vrc))
    583585            RTFileClose(f);
    584         rc = setError(VBOX_E_FILE_ERROR,
    585                       tr("Machine settings file '%s' already exists"),
    586                       mData->m_strConfigFileFull.c_str());
     586        if (!fForceOverwrite)
     587            rc = setError(VBOX_E_FILE_ERROR,
     588                          tr("Machine settings file '%s' already exists"),
     589                          mData->m_strConfigFileFull.c_str());
     590        else
     591        {
     592            /* try to delete the config file, as otherwise the creation
     593             * of a new settings file will fail. */
     594            int vrc2 = RTFileDelete(mData->m_strConfigFileFull.c_str());
     595            if (RT_FAILURE(vrc2))
     596                rc = setError(VBOX_E_FILE_ERROR,
     597                              tr("Could not delete the existing settings file '%s' (%Rrc)"),
     598                              mData->m_strConfigFileFull.c_str(), vrc2);
     599        }
    587600    }
    588601    else if (    vrc != VERR_FILE_NOT_FOUND
Note: See TracChangeset for help on using the changeset viewer.

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