VirtualBox

Changeset 81415 in vbox for trunk/src/VBox/Main/src-server


Ignore:
Timestamp:
Oct 21, 2019 3:06:34 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
134129
Message:

Main/MachineImplMoveVM: simplify updatePathsToStateFiles (which is still very wrong, because it uses a method which is used for renaming VMs), because it used the method to update the snapshots too often (for each snapshot, when one call updates them all)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/MachineImplMoveVM.cpp

    r81397 r81415  
    687687         * Update state file path
    688688         * very important step!
    689          * Not obvious how to do it correctly.
    690689         */
    691         {
    692             Log2(("Update state file path\n"));
    693             hrc = taskMoveVM->updatePathsToStateFiles(taskMoveVM->m_finalSaveStateFilesMap,
    694                                                       taskMoveVM->m_vmFolders[VBox_SettingFolder],
    695                                                       strTargetFolder);
    696             if (FAILED(hrc))
    697                 throw hrc;
    698         }
     690        Log2(("Update state file path\n"));
     691        /** @todo r=klaus: this update is not necessarily matching what the
     692         * above code has set as the new folders, so it needs reimplementing */
     693        taskMoveVM->updatePathsToStateFiles(taskMoveVM->m_vmFolders[VBox_SettingFolder],
     694                                            strTargetFolder);
    699695
    700696        /*
     
    922918
    923919            /* Revert original paths to the state files */
    924             {
    925                 hrc = taskMoveVM->updatePathsToStateFiles(taskMoveVM->m_finalSaveStateFilesMap,
    926                                                           strTargetFolder,
    927                                                           taskMoveVM->m_vmFolders[VBox_SettingFolder]);
    928                 if (FAILED(hrc))
    929                 {
    930                     Log2(("Rollback scenario: can't restore the original paths to the state files. Machine settings %s can be corrupted.\n",
    931                           machineData->m_strConfigFileFull.c_str()));
    932                     throw hrc;
    933                 }
    934             }
     920            taskMoveVM->updatePathsToStateFiles(strTargetFolder,
     921                                                taskMoveVM->m_vmFolders[VBox_SettingFolder]);
    935922
    936923            /* Delete all created files. Here we update progress object */
     
    11411128}
    11421129
    1143 HRESULT MachineMoveVM::updatePathsToStateFiles(const std::map<Utf8Str, SAVESTATETASKMOVE> &listOfFiles,
    1144                                                const Utf8Str &sourcePath, const Utf8Str &targetPath)
    1145 {
    1146     HRESULT rc = S_OK;
    1147 
    1148     std::map<Utf8Str, SAVESTATETASKMOVE>::const_iterator itState = listOfFiles.begin();
    1149     while (itState != listOfFiles.end())
    1150     {
    1151         const SAVESTATETASKMOVE &sst = itState->second;
    1152 
    1153         if (sst.snapshotUuid != Guid::Empty)
    1154         {
    1155             Utf8Str strGuidMachine = sst.snapshotUuid.toString();
    1156             ComObjPtr<Snapshot> snapshotMachineObj;
    1157 
    1158             rc = m_pMachine->i_findSnapshotById(sst.snapshotUuid, snapshotMachineObj, true);
    1159             if (SUCCEEDED(rc) && !snapshotMachineObj.isNull())
    1160                 snapshotMachineObj->i_updateSavedStatePaths(sourcePath.c_str(),
    1161                                                             targetPath.c_str());
    1162 
    1163         }
    1164         else
    1165         {
    1166             const Utf8Str &path = m_pMachine->mSSData->strStateFilePath;
    1167             /*
    1168              * This check for the case when a new value is equal to the old one.
    1169              * Maybe the more clever check is needed in the some corner cases.
    1170              */
    1171             if (!RTPathStartsWith(path.c_str(), targetPath.c_str()))
    1172                 m_pMachine->mSSData->strStateFilePath = Utf8StrFmt("%s%s",
    1173                                                                    targetPath.c_str(),
    1174                                                                    path.c_str() + sourcePath.length());
    1175         }
    1176 
    1177         ++itState;
    1178     }
    1179 
    1180     return rc;
     1130void MachineMoveVM::updatePathsToStateFiles(const Utf8Str &sourcePath, const Utf8Str &targetPath)
     1131{
     1132    ComObjPtr<Snapshot> pSnapshot;
     1133    HRESULT rc = m_pMachine->i_findSnapshotById(Guid() /* zero */, pSnapshot, true);
     1134    if (SUCCEEDED(rc) && !pSnapshot.isNull())
     1135        pSnapshot->i_updateSavedStatePaths(sourcePath.c_str(),
     1136                                           targetPath.c_str());
     1137    if (RTPathStartsWith(m_pMachine->mSSData->strStateFilePath.c_str(), sourcePath.c_str()))
     1138        m_pMachine->mSSData->strStateFilePath = Utf8StrFmt("%s%s",
     1139                                                           targetPath.c_str(),
     1140                                                           m_pMachine->mSSData->strStateFilePath.c_str() + sourcePath.length());
     1141    else
     1142        m_pMachine->mSSData->strStateFilePath = Utf8StrFmt("%s%c%s",
     1143                                                           targetPath.c_str(),
     1144                                                           RTPATH_DELIMITER,
     1145                                                           RTPathFilename(m_pMachine->mSSData->strStateFilePath.c_str()));
    11811146}
    11821147
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