VirtualBox

Changeset 93548 in vbox


Ignore:
Timestamp:
Feb 2, 2022 6:08:28 PM (3 years ago)
Author:
vboxsync
Message:

Main/Machine: When saving the settings fails when creating a new file, delete the file because it usually does not contain anything (or something invalid). Leaving behind such files in the failure case sabotages retrying, since it will then fail with VERR_ALREADY_EXISTS.

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

Legend:

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

    r93190 r93548  
    682682    };
    683683
    684     HRESULT i_prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
     684    HRESULT i_prepareSaveSettings(bool *pfNeedsGlobalSaveSettings,
     685                                  bool *pfSettingsFileIsNew);
    685686    HRESULT i_saveSettings(bool *pfNeedsGlobalSaveSettings, AutoWriteLock &alock, int aFlags = 0);
    686687
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r93410 r93548  
    96139613 *  @note Must be never called directly but only from #saveSettings().
    96149614 */
    9615 HRESULT Machine::i_prepareSaveSettings(bool *pfNeedsGlobalSaveSettings)
     9615HRESULT Machine::i_prepareSaveSettings(bool *pfNeedsGlobalSaveSettings,
     9616                                       bool *pfSettingsFileIsNew)
    96169617{
    96179618    AssertReturn(isWriteLockOnCurrentThread(), E_FAIL);
     
    96209621
    96219622    bool fSettingsFileIsNew = !mData->pMachineConfigFile->fileExists();
    9622 
    96239623    /// @todo need to handle primary group change, too
    96249624
     
    98349834
    98359835        /* Note: open flags must correlate with RTFileOpen() in lockConfig() */
    9836         path = Utf8Str(mData->m_strConfigFileFull);
     9836        path = mData->m_strConfigFileFull;
    98379837        RTFILE f = NIL_RTFILE;
    98389838        vrc = RTFileOpen(&f, path.c_str(),
     
    98459845        RTFileClose(f);
    98469846    }
     9847    if (pfSettingsFileIsNew)
     9848        *pfSettingsFileIsNew = fSettingsFileIsNew;
    98479849
    98489850    return rc;
     
    98779879HRESULT Machine::i_saveSettings(bool *pfNeedsGlobalSaveSettings,
    98789880                                AutoWriteLock &alock,
    9879                                 int  aFlags /*= 0*/)
     9881                                int aFlags /*= 0*/)
    98809882{
    98819883    LogFlowThisFuncEnter();
     
    98969898    HRESULT rc = S_OK;
    98979899    bool fNeedsWrite = false;
     9900    bool fSettingsFileIsNew = false;
    98989901
    98999902    /* First, prepare to save settings. It will care about renaming the
    99009903     * settings directory and file if the machine name was changed and about
    99019904     * creating a new settings file if this is a new machine. */
    9902     rc = i_prepareSaveSettings(pfNeedsGlobalSaveSettings);
     9905    rc = i_prepareSaveSettings(pfNeedsGlobalSaveSettings,
     9906                               &fSettingsFileIsNew);
    99039907    if (FAILED(rc)) return rc;
    99049908
     
    99639967        // we assume that error info is set by the thrower
    99649968        rc = err;
     9969
     9970        // delete any newly created settings file
     9971        if (fSettingsFileIsNew)
     9972            RTFileDelete(mData->m_strConfigFileFull.c_str());
    99659973
    99669974        // restore old config
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