VirtualBox

Changeset 70823 in vbox


Ignore:
Timestamp:
Jan 31, 2018 11:35:09 AM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
120628
Message:

bugref:8345. removed changeset r120593 as useless for now. The function updateStateFilesXMLSettings() was reworked and renamed into updatePathsToStateFiles(). The code is more lighter now.

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

Legend:

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

    r70675 r70823  
    113113    void updateProgressStats(MEDIUMTASKCHAIN &mtc, ULONG &uCount, ULONG &uTotalWeight) const;
    114114    HRESULT addSaveState(const ComObjPtr<Machine> &machine, ULONG &uCount, ULONG &uTotalWeight);
    115     void updateStateFile(settings::MachineConfigFile *snl, const Guid &id, const Utf8Str &strFile);
    116     void updateStateFile(settings::SnapshotsList &snl, const Guid &id, const Utf8Str &strFile);
    117115    void printStateFile(settings::SnapshotsList &snl);
    118116    HRESULT getFilesList(const Utf8Str& strRootFolder, fileList_t &filesList);
    119117    HRESULT getFolderSize(const Utf8Str& strRootFolder, uint64_t& size);
    120118    HRESULT deleteFiles(const RTCList<Utf8Str>& listOfFiles);
    121     HRESULT updateStateFilesXMLSettings(const std::map<Utf8Str, SAVESTATETASK>& listOfFiles, const Utf8Str& targetPath);
     119    HRESULT updatePathsToStateFiles(const std::map<Utf8Str, SAVESTATETASK>& listOfFiles,
     120                                    const Utf8Str& sourcePath, const Utf8Str& targetPath);
    122121    HRESULT moveAllDisks(const std::map<Utf8Str, MEDIUMTASK>& listOfDisks, const Utf8Str* strTargetFolder = NULL);
    123122    HRESULT restoreAllDisks(const std::map<Utf8Str, MEDIUMTASK>& listOfDisks);
  • trunk/src/VBox/Main/src-server/MachineImplMoveVM.cpp

    r70806 r70823  
    182182        m_pMachine->COMGETTER(LogFolder)(bstr_logFolder.asOutParam());
    183183        strLogFolder = bstr_logFolder;
    184         if (   m_type.equals("full")
     184        if (   m_type.equals("basic")
    185185            && strLogFolder.contains(strSettingsFilePath))
    186186        {
     
    198198            strStateFilePath = bstr_stateFilePath;
    199199            strStateFilePath.stripFilename();
    200             if (   m_type.equals("full")
     200            if (   m_type.equals("basic")
    201201                && strStateFilePath.contains(strSettingsFilePath))
    202202                vmFolders.insert(std::make_pair(VBox_StateFolder, strStateFilePath));//Utf8Str(bstr_stateFilePath)));
     
    207207        m_pMachine->COMGETTER(SnapshotFolder)(bstr_snapshotFolder.asOutParam());
    208208        strSnapshotFolder = bstr_snapshotFolder;
    209         if (   m_type.equals("full")
     209        if (   m_type.equals("basic")
    210210            && strSnapshotFolder.contains(strSettingsFilePath))
    211211            vmFolders.insert(std::make_pair(VBox_SnapshotFolder, strSnapshotFolder));
     
    230230        fileList_t actualFileList;
    231231        Utf8Str strTargetImageName;
    232 
    233 //      if (m_pMachine->i_isSnapshotMachine())
    234 //          Guid snapshotId = m_pMachine->i_getSnapshotId();
    235232
    236233        /* Global variable (defined at the beginning of file), so clear it before usage */
     
    418415
    419416    return rc;
    420 }
    421 
    422 void MachineMoveVM::updateStateFile(settings::MachineConfigFile *snl, const Guid &id, const Utf8Str &strFile)
    423 {
    424     settings::SnapshotsList::iterator it;
    425     for (it = (*snl).llFirstSnapshot.begin(); it != (*snl).llFirstSnapshot.end(); ++it)
    426     {
    427         settings::Snapshot snap = (settings::Snapshot)(*it);
    428         RTPrintf("it->uuid = %s , id = %s\n", snap.uuid.toStringCurly().c_str(), id.toStringCurly().c_str());
    429         RTPrintf("it->strStateFile = %s , strFile = %s\n", it->strStateFile.c_str(), strFile.c_str());
    430         if (it->uuid == id)
    431         {
    432             it->strStateFile = strFile;
    433             RTPrintf("Modified it->strStateFile = %s\n", it->strStateFile.c_str());
    434         }
    435         else if (!it->llChildSnapshots.empty())
    436             updateStateFile(it->llChildSnapshots, id, strFile);
    437     }
    438 }
    439 
    440 void MachineMoveVM::updateStateFile(settings::SnapshotsList &snl, const Guid &id, const Utf8Str &strFile)
    441 {
    442     settings::SnapshotsList::iterator it;
    443     for (it = snl.begin(); it != snl.end(); ++it)
    444     {
    445         if (it->uuid == id)
    446         {
    447             settings::Snapshot snap = (settings::Snapshot)(*it);
    448             RTPrintf("it->uuid = %s , id = %s\n", snap.uuid.toStringCurly().c_str(), id.toStringCurly().c_str());
    449             RTPrintf("it->strStateFile = %s , strFile = %s\n", snap.strStateFile.c_str(), strFile.c_str());
    450             it->strStateFile = strFile;
    451 
    452             RTPrintf("Modified it->strStateFile = %s\n", it->strStateFile.c_str());
    453             m_pMachine->mSSData->strStateFilePath = strFile;
    454             RTPrintf("Modified m_pMachine->mSSData->strStateFilePath = %s\n",
    455                    m_pMachine->mSSData->strStateFilePath.c_str());
    456         }
    457         else if (!it->llChildSnapshots.empty())
    458             updateStateFile(it->llChildSnapshots, id, strFile);
    459     }
    460417}
    461418
     
    630587        }
    631588
    632         /* Update XML settings. */
    633         rc = taskMoveVM->updateStateFilesXMLSettings(taskMoveVM->finalSaveStateFilesMap, strTrgSnapshotFolder);
     589        /* Update state file path */
     590        rc = taskMoveVM->updatePathsToStateFiles(taskMoveVM->finalSaveStateFilesMap,
     591                                                 taskMoveVM->vmFolders[VBox_SettingFolder],
     592                                                 strTargetFolder);
    634593        if (FAILED(rc))
    635594            throw rc;
     
    755714            machineData->m_strConfigFileFull = strTargetSettingsFilePath;
    756715            taskMoveVM->m_pMachine->mParent->i_copyPathRelativeToConfig(strTargetSettingsFilePath, machineData->m_strConfigFile);
    757 //          machineData->m_strConfigFile = strTargetSettingsFilePath;
     716
    758717            RTPrintf("\nmachineData->m_strConfigFileFull = %s\n", machineData->m_strConfigFileFull.c_str());
    759718            RTPrintf("\nmachineData->m_strConfigFile = %s\n", machineData->m_strConfigFile.c_str());
     
    796755        /* ! Apparently we should update the Progress object !*/
    797756
    798         /* Restore the original XML settings. */
    799         rc = taskMoveVM->updateStateFilesXMLSettings(taskMoveVM->finalSaveStateFilesMap,
    800                                                      taskMoveVM->vmFolders[VBox_StateFolder]);
     757        /* Restoring the original mediums */
     758        try
     759        {
     760            rc = taskMoveVM->moveAllDisks(taskMoveVM->finalMediumsMap);
     761            if (FAILED(rc))
     762                throw rc;
     763        }
     764        catch(HRESULT hrc)
     765        {
     766            RTPrintf("\nFailed: HRESULT exception\n");
     767            taskMoveVM->result = hrc;
     768        }
     769        catch (...)
     770        {
     771            RTPrintf("\nFailed: Unknown exception\n");
     772            rc = VirtualBoxBase::handleUnexpectedExceptions(taskMoveVM->m_pMachine, RT_SRC_POS);
     773            taskMoveVM->result = rc;
     774        }
     775
     776        /* Revert original paths to the state files */
     777        rc = taskMoveVM->updatePathsToStateFiles(taskMoveVM->finalSaveStateFilesMap,
     778                                                 strTargetFolder,
     779                                                 taskMoveVM->vmFolders[VBox_SettingFolder]);
    801780        if (FAILED(rc))
    802781            throw rc;
     
    816795
    817796        RTDirRemove(strTargetFolder.c_str());
    818 
    819         /* Restoring the original mediums */
    820         try
    821         {
    822             rc = taskMoveVM->moveAllDisks(taskMoveVM->finalMediumsMap);
    823             if (FAILED(rc))
    824                 throw rc;
    825         }
    826         catch(HRESULT hrc)
    827         {
    828             RTPrintf("\nFailed: HRESULT exception\n");
    829             taskMoveVM->result = hrc;
    830         }
    831         catch (...)
    832         {
    833             RTPrintf("\nFailed: Unknown exception\n");
    834             rc = VirtualBoxBase::handleUnexpectedExceptions(taskMoveVM->m_pMachine, RT_SRC_POS);
    835             taskMoveVM->result = rc;
    836         }
    837797
    838798        /* save all VM data */
     
    981941                throw machine->setError(ProgressErrorInfo(moveDiskProgress));
    982942
    983             /* Update saved state path machine->mSSData->strStateFilePath */
    984             {
    985                 Utf8Str configDir, newConfigDir;
    986                 Utf8Str strStateFileName;
    987                 Utf8Str strTargetSettingsFilePath;
    988                 if (strTargetFolder != NULL && !strTargetFolder->isEmpty())
    989                 {
    990                     /* normal logic.*/
    991                     newConfigDir = *strTargetFolder;
    992                     configDir = vmFolders[VBox_SettingFolder];
    993                 }
    994                 else
    995                 {
    996                     /* for restoration logic */
    997                     newConfigDir = vmFolders[VBox_SettingFolder];
    998                     /* Can't use strTargetFolder in this case because strTargetFolder is NULL in this case */
    999                     configDir = m_targetPath;
    1000                     com::Utf8Str mName;
    1001                     machine->getName(mName);
    1002                     configDir.append(mName);
    1003                 }
    1004 
    1005                 /* create a full state file path */
    1006                 if (RTPathStartsWith(machine->mSSData->strStateFilePath.c_str(), configDir.c_str()))
    1007                 {
    1008                     strStateFileName = machine->mSSData->strStateFilePath.c_str() + configDir.length();
    1009                     machine->mSSData->strStateFilePath = newConfigDir + strStateFileName;
    1010                 }
    1011 
    1012                 for (size_t i = 0; i < machineList.size(); ++i)
    1013                 {
    1014                     const ComObjPtr<Machine> &aMachine = machineList.at(i);
    1015 
    1016                     com::Guid guidMachine = aMachine->i_getSnapshotId();
    1017                     if (guidMachine != Guid::Empty)
    1018                     {
    1019                         Utf8Str strGuidMachine = guidMachine.toString();
    1020                         ComObjPtr<Snapshot> snapshotMachineObj;
    1021 
    1022                         rc = machine->i_findSnapshotById(guidMachine, snapshotMachineObj, true);
    1023                         if (SUCCEEDED(rc) && !snapshotMachineObj.isNull())
    1024                         {
    1025                             snapshotMachineObj->i_updateSavedStatePaths(configDir.c_str(),
    1026                                                                         newConfigDir.c_str());
    1027                         }
    1028                     }
    1029                 }
    1030             }
    1031 
    1032943            ++itMedium;
    1033944        }
     
    1051962}
    1052963
    1053 HRESULT MachineMoveVM::updateStateFilesXMLSettings(const std::map<Utf8Str, SAVESTATETASK>& listOfFiles,
    1054                                                    const Utf8Str& targetPath)
     964HRESULT MachineMoveVM::updatePathsToStateFiles(const std::map<Utf8Str, SAVESTATETASK>& listOfFiles,
     965                                               const Utf8Str& sourcePath, const Utf8Str& targetPath)
    1055966{
    1056967    HRESULT rc = S_OK;
    1057     Machine::Data *machineData = m_pMachine->mData.data();
    1058     settings::MachineConfigFile *machineConfFile = machineData->pMachineConfigFile;
    1059968
    1060969    std::map<Utf8Str, SAVESTATETASK>::const_iterator itState = listOfFiles.begin();
     
    1066975                                                           RTPathFilename(sst.strSaveStateFile.c_str()));
    1067976
    1068         /* Update the path in the configuration either for the current
    1069          * machine state or the snapshots. */
    1070         if (!sst.snapshotUuid.isValid() || sst.snapshotUuid.isZero())
    1071         {
    1072             (*machineConfFile).strStateFile = strTargetSaveStateFilePath;
    1073         }
    1074         else
    1075         {
    1076             updateStateFile(m_pMachine->mData->pMachineConfigFile->llFirstSnapshot,
    1077                             sst.snapshotUuid, strTargetSaveStateFilePath);
     977        Utf8Str strGuidMachine = sst.snapshotUuid.toString();
     978        ComObjPtr<Snapshot> snapshotMachineObj;
     979
     980        rc = m_pMachine->i_findSnapshotById(sst.snapshotUuid, snapshotMachineObj, true);
     981        if (SUCCEEDED(rc) && !snapshotMachineObj.isNull())
     982        {
     983            snapshotMachineObj->i_updateSavedStatePaths(sourcePath.c_str(),
     984                                                        targetPath.c_str());
    1078985        }
    1079986
     
    11831090            ++it;
    11841091        }
    1185 //      RTPrintf("Total folder %s size %llu\n", strRootFolder.c_str(), totalFolderSize);
     1092
    11861093        size = totalFolderSize;
    11871094    }
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