- Timestamp:
- Apr 24, 2018 6:48:25 AM (7 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/MachineImplMoveVM.h
r71581 r71990 63 63 class MachineMoveVM : public ThreadTask 64 64 { 65 struct ErrorInfoItem 66 { 67 ErrorInfoItem(unsigned int aCode, const char* aDescription): 68 m_code(aCode), 69 m_description(aDescription == NULL ? "There is no description" : aDescription) 70 { 71 } 72 73 void printItem(bool fLog) const; 74 75 HRESULT m_code; 76 Utf8Str m_description; 77 }; 78 79 RTCList<MEDIUMTASKCHAINMOVE> llMedias; 80 RTCList<SAVESTATETASKMOVE> llSaveStateFiles; 81 std::map<Utf8Str, MEDIUMTASKMOVE> finalMediumsMap; 82 std::map<Utf8Str, SAVESTATETASKMOVE> finalSaveStateFilesMap; 83 std::map<VBoxFolder_t, Utf8Str> vmFolders; 84 std::list<ErrorInfoItem> errorsList; 85 86 ComObjPtr<Machine> m_pMachine; 87 ComObjPtr<Progress> m_pProgress; 88 ComObjPtr<Progress> m_pRollBackProgress; 89 ComPtr<ISession> m_pSession; 90 ComPtr<IMachine> m_pSessionMachine; 91 Utf8Str m_targetPath; 92 Utf8Str m_type; 93 HRESULT result; 94 65 95 public: 66 67 96 MachineMoveVM(ComObjPtr<Machine> aMachine, 68 97 const com::Utf8Str &aTargetPath, … … 73 102 m_pProgress(aProgress), 74 103 m_targetPath(aTargetPath), 75 m_type (aType),104 m_type (aType), 76 105 result(S_OK) 77 106 { … … 86 115 static DECLCALLBACK(int) copyFileProgress(unsigned uPercentage, void *pvUser); 87 116 static void i_MoveVMThreadTask(MachineMoveVM* task); 88 89 RTCList<MEDIUMTASKCHAINMOVE> llMedias;90 RTCList<SAVESTATETASKMOVE> llSaveStateFiles;91 std::map<Utf8Str, MEDIUMTASKMOVE> finalMediumsMap;92 std::map<Utf8Str, SAVESTATETASKMOVE> finalSaveStateFilesMap;93 std::map<VBoxFolder_t, Utf8Str> vmFolders;94 95 ComObjPtr<Machine> m_pMachine;96 ComObjPtr<Progress> m_pProgress;97 ComObjPtr<Progress> m_pRollBackProgress;98 ComPtr<ISession> m_pSession;99 ComPtr<IMachine> m_pSessionMachine;100 Utf8Str m_targetPath;101 Utf8Str m_type;102 HRESULT result;103 117 104 118 void handler() -
trunk/src/VBox/Main/src-server/MachineImplMoveVM.cpp
r71728 r71990 111 111 }; 112 112 113 114 void MachineMoveVM::ErrorInfoItem::printItem(bool fLog) const 115 { 116 if (fLog) 117 { 118 LogRelFunc(("(The error code is %Rrc): %s\n",m_code, m_description.c_str())); 119 } 120 else 121 RTPrintf("(The error code is %Rrc): %s\n",m_code, m_description.c_str()); 122 } 123 113 124 HRESULT MachineMoveVM::init() 114 125 { 115 126 HRESULT rc = S_OK; 127 128 errorsList.clear(); 116 129 117 130 Utf8Str strTargetFolder; … … 121 134 if (len >=RTPATH_MAX) 122 135 { 123 throw m_pMachine->setError(VBOX_E_IPRT_ERROR,124 m_pMachine->tr(" The destination path isn't correct. "125 "The length of path exceeded the maximum value."));136 Utf8Str errorDesc(" The destination path isn't correct. The length of path exceeded the maximum value."); 137 errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str())); 138 throw m_pMachine->setError(VBOX_E_IPRT_ERROR, m_pMachine->tr(errorDesc.c_str())); 126 139 } 127 140 … … 156 169 { 157 170 RTPrintf("strTargetFolder is %s\n", strTargetFolder.c_str()); 158 rc = m_pMachine->setError(E_FAIL, 159 m_pMachine->tr("Unable to move machine. Can't get the destination storage size (%s)"), 160 strTargetFolder.c_str()); 171 Utf8StrFmt errorDesc("Unable to move machine. Can't get the destination storage size (%s)", 172 strTargetFolder.c_str()); 173 errorsList.push_back(ErrorInfoItem(E_FAIL, errorDesc.c_str())); 174 rc = m_pMachine->setError(E_FAIL, m_pMachine->tr(errorDesc.c_str())); 161 175 throw rc; 162 176 } … … 174 188 { 175 189 LogRelFunc(("Can't create a test file %s (The error is %Rrc)\n", strTempFile.c_str(), vrc)); 176 rc = m_pMachine->setError(vrc, 177 m_pMachine->tr("Can't create a test file test.txt in the %s. Check the access rights of " 178 "the destination folder."), 179 strTargetFolder.c_str()); 180 throw rc; 181 } 190 Utf8StrFmt errorDesc("Can't create a test file test.txt in the %s. Check the access rights of " 191 "the destination folder.", strTargetFolder.c_str()); 192 errorsList.push_back(ErrorInfoItem(vrc, errorDesc.c_str())); 193 rc = m_pMachine->setError(vrc, m_pMachine->tr(errorDesc.c_str())); 194 195 } 196 182 197 RTFileClose(hFile); 183 198 RTFileDelete(strTempFile.c_str()); … … 462 477 if (FAILED(rc)) 463 478 { 464 throw m_pMachine->setError(VBOX_E_IPRT_ERROR,465 m_pMachine->tr("Couldn't correctly setup the progress object "466 "for moving VM operation (%Rrc)"), 467 rc);479 Utf8StrFmt errorDesc("Couldn't correctly setup the progress object for moving VM operation (%Rrc)", rc); 480 errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str())); 481 482 throw m_pMachine->setError(VBOX_E_IPRT_ERROR,m_pMachine->tr(errorDesc.c_str())); 468 483 } 469 484 } … … 626 641 int vrc = RTDirCreateFullPath(strTrgSnapshotFolder.c_str(), 0700); 627 642 if (RT_FAILURE(vrc)) 628 throw machine->setError(VBOX_E_IPRT_ERROR, 629 machine->tr("Could not create snapshots folder '%s' (%Rrc)"), 630 strTrgSnapshotFolder.c_str(), vrc); 643 { 644 Utf8StrFmt errorDesc("Could not create snapshots folder '%s' (%Rrc)", strTrgSnapshotFolder.c_str(), vrc); 645 taskMoveVM->errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str())); 646 647 throw machine->setError(VBOX_E_IPRT_ERROR,machine->tr(errorDesc.c_str())); 648 } 631 649 } 632 650 … … 646 664 MachineMoveVM::copyFileProgress, &taskMoveVM->m_pProgress); 647 665 if (RT_FAILURE(vrc)) 648 throw machine->setError(VBOX_E_IPRT_ERROR, 649 machine->tr("Could not copy state file '%s' to '%s' (%Rrc)"), 650 sst.strSaveStateFile.c_str(), strTrgSaveState.c_str(), vrc); 666 { 667 Utf8StrFmt errorDesc("Could not copy state file '%s' to '%s' (%Rrc)", 668 sst.strSaveStateFile.c_str(), strTrgSaveState.c_str(), vrc); 669 taskMoveVM->errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str())); 670 671 throw machine->setError(VBOX_E_IPRT_ERROR,machine->tr(errorDesc.c_str())); 672 } 651 673 652 674 /* save new file in case of restoring */ … … 691 713 int vrc = RTDirCreateFullPath(strTargetSettingsFilePath.c_str(), 0700); 692 714 if (RT_FAILURE(vrc)) 693 throw machine->setError(VBOX_E_IPRT_ERROR, 694 machine->tr("Could not create a home machine folder '%s' (%Rrc)"), 695 strTargetSettingsFilePath.c_str(), vrc); 715 { 716 Utf8StrFmt errorDesc("Could not create a home machine folder '%s' (%Rrc)", 717 strTargetSettingsFilePath.c_str(), vrc); 718 taskMoveVM->errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str())); 719 720 throw machine->setError(VBOX_E_IPRT_ERROR,machine->tr(errorDesc.c_str())); 721 } 696 722 LogRelFunc(("Created a home machine folder %s\n", strTargetSettingsFilePath.c_str())); 697 723 } … … 711 737 MachineMoveVM::copyFileProgress, &taskMoveVM->m_pProgress); 712 738 if (RT_FAILURE(vrc)) 713 throw machine->setError(VBOX_E_IPRT_ERROR, 714 machine->tr("Could not copy the setting file '%s' to '%s' (%Rrc)"), 715 strSettingsFilePath.c_str(), strTargetSettingsFilePath.stripFilename().c_str(), vrc); 739 { 740 Utf8StrFmt errorDesc("Could not copy the setting file '%s' to '%s' (%Rrc)", 741 strSettingsFilePath.c_str(), strTargetSettingsFilePath.stripFilename().c_str(), vrc); 742 taskMoveVM->errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str())); 743 744 throw machine->setError(VBOX_E_IPRT_ERROR, machine->tr(errorDesc.c_str())); 745 } 716 746 717 747 LogRelFunc(("The setting file %s has been copied into the folder %s\n", strSettingsFilePath.c_str(), … … 741 771 int vrc = RTDirCreateFullPath(strTargetLogFolderPath.c_str(), 0700); 742 772 if (RT_FAILURE(vrc)) 743 throw machine->setError(VBOX_E_IPRT_ERROR, 744 machine->tr("Could not create log folder '%s' (%Rrc)"), 745 strTargetLogFolderPath.c_str(), vrc); 773 { 774 Utf8StrFmt errorDesc("Could not create log folder '%s' (%Rrc)", 775 strTargetLogFolderPath.c_str(), vrc); 776 taskMoveVM->errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str())); 777 778 throw machine->setError(VBOX_E_IPRT_ERROR,machine->tr(errorDesc.c_str())); 779 } 746 780 LogRelFunc(("Created a log machine folder %s\n", strTargetLogFolderPath.c_str())); 747 781 } … … 766 800 MachineMoveVM::copyFileProgress, &taskMoveVM->m_pProgress); 767 801 if (RT_FAILURE(vrc)) 768 throw machine->setError(VBOX_E_IPRT_ERROR, 769 machine->tr("Could not copy the log file '%s' to '%s' (%Rrc)"), 770 strFullSourceFilePath.c_str(), strFullTargetFilePath.stripFilename().c_str(), vrc); 802 { 803 Utf8StrFmt errorDesc("Could not copy the log file '%s' to '%s' (%Rrc)", 804 strFullSourceFilePath.c_str(), 805 strFullTargetFilePath.stripFilename().c_str(), 806 vrc); 807 taskMoveVM->errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str())); 808 809 throw machine->setError(VBOX_E_IPRT_ERROR,machine->tr(errorDesc.c_str())); 810 } 771 811 772 812 LogRelFunc(("The log file %s has been copied into the folder %s\n", strFullSourceFilePath.c_str(), … … 924 964 // save the global settings; for that we should hold only the VirtualBox lock 925 965 AutoWriteLock vboxLock(machine->mParent COMMA_LOCKVAL_SRC_POS); 926 927 966 rc = machine->mParent->i_saveSettings(); 928 967 } … … 958 997 959 998 if (!taskMoveVM->m_pProgress.isNull()) 999 { 1000 /* Set the first error happened */ 1001 if (!taskMoveVM->errorsList.empty()) 1002 { 1003 ErrorInfoItem ei = taskMoveVM->errorsList.front(); 1004 machine->setError(ei.m_code, machine->tr(ei.m_description.c_str())); 1005 } 1006 960 1007 taskMoveVM->m_pProgress->i_notifyComplete(taskMoveVM->result); 1008 } 961 1009 962 1010 LogFlowFuncLeave(); … … 1053 1101 * retrieve the error info from there, or it'll be lost. */ 1054 1102 if (FAILED(iRc)) 1103 { 1104 ProgressErrorInfo pie(moveDiskProgress); 1105 Utf8Str errorDesc(pie.getText().raw()); 1106 errorsList.push_back(ErrorInfoItem(pie.getResultCode(), errorDesc.c_str())); 1107 1055 1108 throw machine->setError(ProgressErrorInfo(moveDiskProgress)); 1109 } 1056 1110 1057 1111 ++itMedium; … … 1071 1125 rc = VirtualBoxBase::handleUnexpectedExceptions(m_pMachine, RT_SRC_POS); 1072 1126 machineLock.release(); 1127 } 1128 1129 if (FAILED(rc)) 1130 { 1131 Utf8StrFmt errorDesc("Exception during moving the disk %s\n", strLocation.c_str()); 1132 errorsList.push_back(ErrorInfoItem(rc, errorDesc.c_str())); 1073 1133 } 1074 1134 … … 1144 1204 else if (vrc == VERR_FILE_NOT_FOUND) 1145 1205 { 1146 m_pMachine->setError(VBOX_E_IPRT_ERROR, 1147 m_pMachine->tr("Folder '%s' doesn't exist (%Rrc)"), 1148 strRootFolder.c_str(), vrc); 1206 Utf8StrFmt errorDesc("Folder '%s' doesn't exist (%Rrc)", strRootFolder.c_str(), vrc); 1207 errorsList.push_back(ErrorInfoItem(VERR_FILE_NOT_FOUND, errorDesc.c_str())); 1208 1209 m_pMachine->setError(VBOX_E_IPRT_ERROR, m_pMachine->tr(errorDesc.c_str())); 1149 1210 rc = vrc; 1150 1211 } 1151 1212 else 1152 throw m_pMachine->setError(VBOX_E_IPRT_ERROR, 1153 m_pMachine->tr("Could not open folder '%s' (%Rrc)"), 1154 strRootFolder.c_str(), vrc); 1213 { 1214 Utf8StrFmt errorDesc("Could not open folder '%s' (%Rrc)", strRootFolder.c_str(), vrc); 1215 errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str())); 1216 1217 throw m_pMachine->setError(VBOX_E_IPRT_ERROR, m_pMachine->tr(errorDesc.c_str())); 1218 } 1219 1155 1220 return rc; 1156 1221 } … … 1170 1235 int vrc = RTFileDelete(listOfFiles.at(i).c_str()); 1171 1236 if (RT_FAILURE(vrc)) 1172 rc = m_pMachine->setError(VBOX_E_IPRT_ERROR, 1173 m_pMachine->tr("Could not delete file '%s' (%Rrc)"), 1174 listOfFiles.at(i).c_str(), rc); 1237 { 1238 Utf8StrFmt errorDesc("Could not delete file '%s' (%Rrc)", listOfFiles.at(i).c_str(), rc); 1239 errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str())); 1240 1241 rc = m_pMachine->setError(VBOX_E_IPRT_ERROR, m_pMachine->tr(errorDesc.c_str())); 1242 } 1175 1243 else 1176 1244 LogRelFunc(("File %s has been deleted\n", listOfFiles.at(i).c_str())); … … 1214 1282 } 1215 1283 else 1216 throw m_pMachine->setError(VBOX_E_IPRT_ERROR, 1217 m_pMachine->tr("Could not get the size of file '%s' (%Rrc)"), 1218 fullPath.c_str(), vrc); 1284 { 1285 Utf8StrFmt errorDesc("Could not get the size of file '%s' (%Rrc)", fullPath.c_str(), vrc); 1286 errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str())); 1287 1288 throw m_pMachine->setError(VBOX_E_IPRT_ERROR, m_pMachine->tr(errorDesc.c_str())); 1289 } 1219 1290 ++it; 1220 1291 } … … 1223 1294 } 1224 1295 else 1225 m_pMachine->setError(VBOX_E_IPRT_ERROR, 1226 m_pMachine->tr("Could not calculate the size of folder '%s' (%Rrc)"), 1227 strRootFolder.c_str(), vrc); 1296 { 1297 Utf8StrFmt errorDesc("Could not calculate the size of folder '%s' (%Rrc)", strRootFolder.c_str(), vrc); 1298 errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str())); 1299 1300 m_pMachine->setError(VBOX_E_IPRT_ERROR, m_pMachine->tr(errorDesc.c_str())); 1301 } 1228 1302 } 1229 1303 else … … 1393 1467 int vrc = RTFileQuerySize(sst.strSaveStateFile.c_str(), &cbSize); 1394 1468 if (RT_FAILURE(vrc)) 1395 return m_pMachine->setError(VBOX_E_IPRT_ERROR, m_pMachine->tr("Could not query file size of '%s' (%Rrc)"), 1396 sst.strSaveStateFile.c_str(), vrc); 1469 { 1470 Utf8StrFmt errorDesc("Could not get file size of '%s' (%Rrc)", sst.strSaveStateFile.c_str(), vrc); 1471 errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str())); 1472 1473 return m_pMachine->setError(VBOX_E_IPRT_ERROR, m_pMachine->tr(errorDesc.c_str())); 1474 } 1397 1475 /* same rule as above: count both the data which needs to 1398 1476 * be read and written */
Note:
See TracChangeset
for help on using the changeset viewer.