Changeset 70823 in vbox
- Timestamp:
- Jan 31, 2018 11:35:09 AM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 120628
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/MachineImplMoveVM.h
r70675 r70823 113 113 void updateProgressStats(MEDIUMTASKCHAIN &mtc, ULONG &uCount, ULONG &uTotalWeight) const; 114 114 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);117 115 void printStateFile(settings::SnapshotsList &snl); 118 116 HRESULT getFilesList(const Utf8Str& strRootFolder, fileList_t &filesList); 119 117 HRESULT getFolderSize(const Utf8Str& strRootFolder, uint64_t& size); 120 118 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); 122 121 HRESULT moveAllDisks(const std::map<Utf8Str, MEDIUMTASK>& listOfDisks, const Utf8Str* strTargetFolder = NULL); 123 122 HRESULT restoreAllDisks(const std::map<Utf8Str, MEDIUMTASK>& listOfDisks); -
trunk/src/VBox/Main/src-server/MachineImplMoveVM.cpp
r70806 r70823 182 182 m_pMachine->COMGETTER(LogFolder)(bstr_logFolder.asOutParam()); 183 183 strLogFolder = bstr_logFolder; 184 if ( m_type.equals(" full")184 if ( m_type.equals("basic") 185 185 && strLogFolder.contains(strSettingsFilePath)) 186 186 { … … 198 198 strStateFilePath = bstr_stateFilePath; 199 199 strStateFilePath.stripFilename(); 200 if ( m_type.equals(" full")200 if ( m_type.equals("basic") 201 201 && strStateFilePath.contains(strSettingsFilePath)) 202 202 vmFolders.insert(std::make_pair(VBox_StateFolder, strStateFilePath));//Utf8Str(bstr_stateFilePath))); … … 207 207 m_pMachine->COMGETTER(SnapshotFolder)(bstr_snapshotFolder.asOutParam()); 208 208 strSnapshotFolder = bstr_snapshotFolder; 209 if ( m_type.equals(" full")209 if ( m_type.equals("basic") 210 210 && strSnapshotFolder.contains(strSettingsFilePath)) 211 211 vmFolders.insert(std::make_pair(VBox_SnapshotFolder, strSnapshotFolder)); … … 230 230 fileList_t actualFileList; 231 231 Utf8Str strTargetImageName; 232 233 // if (m_pMachine->i_isSnapshotMachine())234 // Guid snapshotId = m_pMachine->i_getSnapshotId();235 232 236 233 /* Global variable (defined at the beginning of file), so clear it before usage */ … … 418 415 419 416 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 }460 417 } 461 418 … … 630 587 } 631 588 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); 634 593 if (FAILED(rc)) 635 594 throw rc; … … 755 714 machineData->m_strConfigFileFull = strTargetSettingsFilePath; 756 715 taskMoveVM->m_pMachine->mParent->i_copyPathRelativeToConfig(strTargetSettingsFilePath, machineData->m_strConfigFile); 757 // machineData->m_strConfigFile = strTargetSettingsFilePath; 716 758 717 RTPrintf("\nmachineData->m_strConfigFileFull = %s\n", machineData->m_strConfigFileFull.c_str()); 759 718 RTPrintf("\nmachineData->m_strConfigFile = %s\n", machineData->m_strConfigFile.c_str()); … … 796 755 /* ! Apparently we should update the Progress object !*/ 797 756 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]); 801 780 if (FAILED(rc)) 802 781 throw rc; … … 816 795 817 796 RTDirRemove(strTargetFolder.c_str()); 818 819 /* Restoring the original mediums */820 try821 {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 }837 797 838 798 /* save all VM data */ … … 981 941 throw machine->setError(ProgressErrorInfo(moveDiskProgress)); 982 942 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 else995 {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 1032 943 ++itMedium; 1033 944 } … … 1051 962 } 1052 963 1053 HRESULT MachineMoveVM::update StateFilesXMLSettings(const std::map<Utf8Str, SAVESTATETASK>& listOfFiles,1054 964 HRESULT MachineMoveVM::updatePathsToStateFiles(const std::map<Utf8Str, SAVESTATETASK>& listOfFiles, 965 const Utf8Str& sourcePath, const Utf8Str& targetPath) 1055 966 { 1056 967 HRESULT rc = S_OK; 1057 Machine::Data *machineData = m_pMachine->mData.data();1058 settings::MachineConfigFile *machineConfFile = machineData->pMachineConfigFile;1059 968 1060 969 std::map<Utf8Str, SAVESTATETASK>::const_iterator itState = listOfFiles.begin(); … … 1066 975 RTPathFilename(sst.strSaveStateFile.c_str())); 1067 976 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()); 1078 985 } 1079 986 … … 1183 1090 ++it; 1184 1091 } 1185 // RTPrintf("Total folder %s size %llu\n", strRootFolder.c_str(), totalFolderSize); 1092 1186 1093 size = totalFolderSize; 1187 1094 }
Note:
See TracChangeset
for help on using the changeset viewer.