Changeset 98289 in vbox for trunk/src/VBox/Main/src-server/MachineImplMoveVM.cpp
- Timestamp:
- Jan 24, 2023 4:02:15 PM (23 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/MachineImplMoveVM.cpp
r98262 r98289 50 50 HRESULT add(const Utf8Str &folder, const Utf8Str &file) 51 51 { 52 HRESULT rc = S_OK;53 52 m_list.insert(std::make_pair(folder, file)); 54 return rc;53 return S_OK; 55 54 } 56 55 57 56 HRESULT add(const Utf8Str &fullPath) 58 57 { 59 HRESULT rc = S_OK;60 58 Utf8Str folder = fullPath; 61 59 folder.stripFilename(); … … 63 61 filename.stripPath(); 64 62 m_list.insert(std::make_pair(folder, filename)); 65 return rc;63 return S_OK; 66 64 } 67 65 68 66 HRESULT removeFileFromList(const Utf8Str &fullPath) 69 67 { 70 HRESULT rc = S_OK;71 68 Utf8Str folder = fullPath; 72 69 folder.stripFilename(); … … 86 83 } 87 84 88 return rc;85 return S_OK; 89 86 } 90 87 91 88 HRESULT removeFileFromList(const Utf8Str &path, const Utf8Str &fileName) 92 89 { 93 HRESULT rc = S_OK;94 90 rangeRes_t res = m_list.equal_range(path); 95 91 for (it_t it=res.first; it!=res.second;) … … 104 100 ++it; 105 101 } 106 return rc;102 return S_OK; 107 103 } 108 104 109 105 HRESULT removeFolderFromList(const Utf8Str &path) 110 106 { 111 HRESULT rc = S_OK;112 107 m_list.erase(path); 113 return rc;108 return S_OK; 114 109 } 115 110 … … 590 585 591 586 BOOL fCanceled = false; 592 HRESULT rc = pProgress->COMGETTER(Canceled)(&fCanceled);593 if (FAILED( rc)) return VERR_GENERAL_FAILURE;587 HRESULT hrc = pProgress->COMGETTER(Canceled)(&fCanceled); 588 if (FAILED(hrc)) return VERR_GENERAL_FAILURE; 594 589 /* If canceled by the user tell it to the copy operation. */ 595 590 if (fCanceled) return VERR_CANCELLED; 596 591 /* Set the new process. */ 597 rc = pProgress->SetCurrentOperationProgress(uPercentage);598 if (FAILED( rc)) return VERR_GENERAL_FAILURE;592 hrc = pProgress->SetCurrentOperationProgress(uPercentage); 593 if (FAILED(hrc)) return VERR_GENERAL_FAILURE; 599 594 600 595 return VINF_SUCCESS; … … 1141 1136 const Utf8Str &strTargetFolder) 1142 1137 { 1143 HRESULT rc = S_OK;1138 HRESULT hrc = S_OK; 1144 1139 ComObjPtr<Machine> &machine = m_pMachine; 1145 1140 Utf8Str strLocation; … … 1158 1153 Bstr bstrSrcName; 1159 1154 1160 rc = pMedium->COMGETTER(Name)(bstrSrcName.asOutParam());1161 if (FAILED( rc)) throwrc;1155 hrc = pMedium->COMGETTER(Name)(bstrSrcName.asOutParam()); 1156 if (FAILED(hrc)) throw hrc; 1162 1157 1163 1158 if (strTargetFolder.isNotEmpty()) 1164 1159 { 1165 1160 strTargetImageName = strTargetFolder; 1166 rc = pMedium->COMGETTER(Location)(bstrLocation.asOutParam());1167 if (FAILED( rc)) throwrc;1161 hrc = pMedium->COMGETTER(Location)(bstrLocation.asOutParam()); 1162 if (FAILED(hrc)) throw hrc; 1168 1163 strLocation = bstrLocation; 1169 1164 … … 1174 1169 1175 1170 strTargetImageName.append(RTPATH_DELIMITER).append(strLocation); 1176 rc = m_pProgress->SetNextOperation(BstrFmt(tr("Moving medium '%ls' ..."), 1177 bstrSrcName.raw()).raw(), 1178 mt.uWeight); 1179 if (FAILED(rc)) throw rc; 1171 hrc = m_pProgress->SetNextOperation(BstrFmt(tr("Moving medium '%ls' ..."), bstrSrcName.raw()).raw(), mt.uWeight); 1172 if (FAILED(hrc)) throw hrc; 1180 1173 } 1181 1174 else 1182 1175 { 1183 1176 strTargetImageName = mt.strBaseName;//Should contain full path to the image 1184 rc = m_pProgress->SetNextOperation(BstrFmt(tr("Moving medium '%ls' back..."), 1185 bstrSrcName.raw()).raw(), 1186 mt.uWeight); 1187 if (FAILED(rc)) throw rc; 1177 hrc = m_pProgress->SetNextOperation(BstrFmt(tr("Moving medium '%ls' back..."), bstrSrcName.raw()).raw(), mt.uWeight); 1178 if (FAILED(hrc)) throw hrc; 1188 1179 } 1189 1180 … … 1196 1187 1197 1188 MediumType_T mediumType;//immutable, shared, passthrough 1198 rc = pMedium->COMGETTER(Type)(&mediumType);1199 if (FAILED( rc)) throwrc;1189 hrc = pMedium->COMGETTER(Type)(&mediumType); 1190 if (FAILED(hrc)) throw hrc; 1200 1191 1201 1192 DeviceType_T deviceType;//floppy, hard, DVD 1202 rc = pMedium->COMGETTER(DeviceType)(&deviceType);1203 if (FAILED( rc)) throwrc;1193 hrc = pMedium->COMGETTER(DeviceType)(&deviceType); 1194 if (FAILED(hrc)) throw hrc; 1204 1195 1205 1196 /* Drop lock early because IMedium::MoveTo needs to get the VirtualBox one. */ … … 1207 1198 1208 1199 ComPtr<IProgress> moveDiskProgress; 1209 rc = pMedium->MoveTo(bstrLocation.raw(), moveDiskProgress.asOutParam());1210 if (SUCCEEDED( rc))1200 hrc = pMedium->MoveTo(bstrLocation.raw(), moveDiskProgress.asOutParam()); 1201 if (SUCCEEDED(hrc)) 1211 1202 { 1212 1203 /* In case of failure moveDiskProgress would be in the invalid state or not initialized at all … … 1214 1205 */ 1215 1206 /* Wait until the other process has finished. */ 1216 rc = m_pProgress->WaitForOtherProgressCompletion(moveDiskProgress, 0 /* indefinite wait */);1207 hrc = m_pProgress->WaitForOtherProgressCompletion(moveDiskProgress, 0 /* indefinite wait */); 1217 1208 } 1218 1209 … … 1220 1211 machineLock.acquire(); 1221 1212 1222 if (FAILED( rc)) throwrc;1213 if (FAILED(hrc)) throw hrc; 1223 1214 1224 1215 Log2(("Moving %s has been finished\n", strTargetImageName.c_str())); … … 1229 1220 machineLock.release(); 1230 1221 } 1231 catch(HRESULT hrc) 1222 catch (HRESULT hrcXcpt) 1223 { 1224 Log2(("Exception during moving the disk %s: %Rhrc\n", strLocation.c_str(), hrcXcpt)); 1225 hrc = hrcXcpt; 1226 machineLock.release(); 1227 } 1228 catch (...) 1232 1229 { 1233 1230 Log2(("Exception during moving the disk %s\n", strLocation.c_str())); 1234 rc = hrc;1231 hrc = VirtualBoxBase::handleUnexpectedExceptions(m_pMachine, RT_SRC_POS); 1235 1232 machineLock.release(); 1236 1233 } 1237 catch (...) 1238 { 1239 Log2(("Exception during moving the disk %s\n", strLocation.c_str())); 1240 rc = VirtualBoxBase::handleUnexpectedExceptions(m_pMachine, RT_SRC_POS); 1241 machineLock.release(); 1242 } 1243 1244 return rc; 1234 1235 return hrc; 1245 1236 } 1246 1237 … … 1248 1239 { 1249 1240 ComObjPtr<Snapshot> pSnapshot; 1250 HRESULT rc = m_pMachine->i_findSnapshotById(Guid() /* zero */, pSnapshot, true);1251 if (SUCCEEDED( rc) && !pSnapshot.isNull())1241 HRESULT hrc = m_pMachine->i_findSnapshotById(Guid() /* zero */, pSnapshot, true); 1242 if (SUCCEEDED(hrc) && !pSnapshot.isNull()) 1252 1243 pSnapshot->i_updateSavedStatePaths(sourcePath.c_str(), 1253 1244 targetPath.c_str()); … … 1269 1260 { 1270 1261 ComObjPtr<Snapshot> pSnapshot; 1271 HRESULT rc = m_pMachine->i_findSnapshotById(Guid() /* zero */, pSnapshot, true);1272 if (SUCCEEDED( rc) && !pSnapshot.isNull())1262 HRESULT hrc = m_pMachine->i_findSnapshotById(Guid() /* zero */, pSnapshot, true); 1263 if (SUCCEEDED(hrc) && !pSnapshot.isNull()) 1273 1264 pSnapshot->i_updateNVRAMPaths(sourcePath.c_str(), 1274 1265 targetPath.c_str()); … … 1413 1404 { 1414 1405 ComPtr<IMedium> pBaseMedium; 1415 HRESULT rc = pMedium->COMGETTER(Base)(pBaseMedium.asOutParam());1416 if (FAILED( rc)) returnrc;1406 HRESULT hrc = pMedium->COMGETTER(Base)(pBaseMedium.asOutParam()); 1407 if (FAILED(hrc)) return hrc; 1417 1408 Bstr bstrBaseName; 1418 rc = pBaseMedium->COMGETTER(Name)(bstrBaseName.asOutParam());1419 if (FAILED( rc)) returnrc;1409 hrc = pBaseMedium->COMGETTER(Name)(bstrBaseName.asOutParam()); 1410 if (FAILED(hrc)) return hrc; 1420 1411 strBaseName = bstrBaseName; 1421 return rc;1412 return hrc; 1422 1413 } 1423 1414 … … 1425 1416 { 1426 1417 Bstr name; 1427 HRESULT rc = pSnapshot->COMGETTER(Name)(name.asOutParam());1428 if (FAILED( rc)) returnrc;1418 HRESULT hrc = pSnapshot->COMGETTER(Name)(name.asOutParam()); 1419 if (FAILED(hrc)) return hrc; 1429 1420 1430 1421 ComPtr<IMachine> l_pMachine; 1431 rc = pSnapshot->COMGETTER(Machine)(l_pMachine.asOutParam());1432 if (FAILED( rc)) returnrc;1422 hrc = pSnapshot->COMGETTER(Machine)(l_pMachine.asOutParam()); 1423 if (FAILED(hrc)) return hrc; 1433 1424 machineList.push_back((Machine*)(IMachine*)l_pMachine); 1434 1425 1435 1426 SafeIfaceArray<ISnapshot> sfaChilds; 1436 rc = pSnapshot->COMGETTER(Children)(ComSafeArrayAsOutParam(sfaChilds));1437 if (FAILED( rc)) returnrc;1427 hrc = pSnapshot->COMGETTER(Children)(ComSafeArrayAsOutParam(sfaChilds)); 1428 if (FAILED(hrc)) return hrc; 1438 1429 for (size_t i = 0; i < sfaChilds.size(); ++i) 1439 1430 { 1440 rc = createMachineList(sfaChilds[i]);1441 if (FAILED( rc)) returnrc;1442 } 1443 1444 return rc;1431 hrc = createMachineList(sfaChilds[i]); 1432 if (FAILED(hrc)) return hrc; 1433 } 1434 1435 return hrc; 1445 1436 } 1446 1437 … … 1450 1441 * adding all directly and indirectly attached disk images to the worker 1451 1442 * list. */ 1452 HRESULT rc = S_OK;1443 HRESULT hrc = S_OK; 1453 1444 for (size_t i = 0; i < machineList.size(); ++i) 1454 1445 { … … 1458 1449 * machines to a worker list. */ 1459 1450 SafeIfaceArray<IMediumAttachment> sfaAttachments; 1460 rc = machine->COMGETTER(MediumAttachments)(ComSafeArrayAsOutParam(sfaAttachments));1461 if (FAILED( rc)) returnrc;1451 hrc = machine->COMGETTER(MediumAttachments)(ComSafeArrayAsOutParam(sfaAttachments)); 1452 if (FAILED(hrc)) return hrc; 1462 1453 for (size_t a = 0; a < sfaAttachments.size(); ++a) 1463 1454 { 1464 1455 const ComPtr<IMediumAttachment> &pAtt = sfaAttachments[a]; 1465 1456 DeviceType_T deviceType;//floppy, hard, DVD 1466 rc = pAtt->COMGETTER(Type)(&deviceType);1467 if (FAILED( rc)) returnrc;1457 hrc = pAtt->COMGETTER(Type)(&deviceType); 1458 if (FAILED(hrc)) return hrc; 1468 1459 1469 1460 /* Valid medium attached? */ 1470 1461 ComPtr<IMedium> pMedium; 1471 rc = pAtt->COMGETTER(Medium)(pMedium.asOutParam());1472 if (FAILED( rc)) returnrc;1462 hrc = pAtt->COMGETTER(Medium)(pMedium.asOutParam()); 1463 if (FAILED(hrc)) return hrc; 1473 1464 1474 1465 if (pMedium.isNull()) … … 1476 1467 1477 1468 Bstr bstrLocation; 1478 rc = pMedium->COMGETTER(Location)(bstrLocation.asOutParam());1479 if (FAILED( rc)) returnrc;1469 hrc = pMedium->COMGETTER(Location)(bstrLocation.asOutParam()); 1470 if (FAILED(hrc)) return hrc; 1480 1471 1481 1472 /* Cast to ComObjPtr<Medium> */ … … 1483 1474 1484 1475 /* Check for "read-only" medium in terms that VBox can't create this one */ 1485 rc = isMediumTypeSupportedForMoving(pMedium); 1486 if (FAILED(rc)) 1487 { 1488 if (rc == S_FALSE) 1489 { 1490 Log2(("Skipping file %ls because of this medium type hasn't been supported for moving.\n", 1491 bstrLocation.raw())); 1492 continue; 1493 } 1494 else 1495 return rc; 1476 hrc = isMediumTypeSupportedForMoving(pMedium); 1477 if (FAILED(hrc)) 1478 { 1479 if (hrc != S_FALSE) 1480 return hrc; 1481 Log2(("Skipping file %ls because of this medium type hasn't been supported for moving.\n", bstrLocation.raw())); 1482 continue; 1496 1483 } 1497 1484 … … 1505 1492 /* Refresh the state so that the file size get read. */ 1506 1493 MediumState_T e; 1507 rc = pMedium->RefreshState(&e);1508 if (FAILED( rc)) returnrc;1494 hrc = pMedium->RefreshState(&e); 1495 if (FAILED(hrc)) return hrc; 1509 1496 1510 1497 LONG64 lSize; 1511 rc = pMedium->COMGETTER(Size)(&lSize);1512 if (FAILED( rc)) returnrc;1498 hrc = pMedium->COMGETTER(Size)(&lSize); 1499 if (FAILED(hrc)) return hrc; 1513 1500 1514 1501 MediumType_T mediumType;//immutable, shared, passthrough 1515 rc = pMedium->COMGETTER(Type)(&mediumType);1516 if (FAILED( rc)) returnrc;1517 1518 rc = pMedium->COMGETTER(Location)(bstrLocation.asOutParam());1519 if (FAILED( rc)) returnrc;1502 hrc = pMedium->COMGETTER(Type)(&mediumType); 1503 if (FAILED(hrc)) return hrc; 1504 1505 hrc = pMedium->COMGETTER(Location)(bstrLocation.asOutParam()); 1506 if (FAILED(hrc)) return hrc; 1520 1507 1521 1508 MEDIUMTASKMOVE mt;// = {false, "basename", NULL, 0, 0}; … … 1534 1521 1535 1522 /* Query next parent. */ 1536 rc = pMedium->COMGETTER(Parent)(pMedium.asOutParam());1537 if (FAILED( rc)) returnrc;1523 hrc = pMedium->COMGETTER(Parent)(pMedium.asOutParam()); 1524 if (FAILED(hrc)) return hrc; 1538 1525 } 1539 1526 … … 1542 1529 1543 1530 /* Add the save state files of this machine if there is one. */ 1544 rc = addSaveState(machine);1545 if (FAILED( rc)) returnrc;1531 hrc = addSaveState(machine); 1532 if (FAILED(hrc)) return hrc; 1546 1533 1547 1534 /* Add the NVRAM files of this machine if there is one. */ 1548 rc = addNVRAM(machine);1549 if (FAILED( rc)) returnrc;1535 hrc = addNVRAM(machine); 1536 if (FAILED(hrc)) return hrc; 1550 1537 } 1551 1538 … … 1561 1548 } 1562 1549 1563 return rc;1550 return hrc; 1564 1551 } 1565 1552 … … 1567 1554 { 1568 1555 Bstr bstrSrcSaveStatePath; 1569 HRESULT rc = machine->COMGETTER(StateFilePath)(bstrSrcSaveStatePath.asOutParam());1570 if (FAILED( rc)) returnrc;1556 HRESULT hrc = machine->COMGETTER(StateFilePath)(bstrSrcSaveStatePath.asOutParam()); 1557 if (FAILED(hrc)) return hrc; 1571 1558 if (!bstrSrcSaveStatePath.isEmpty()) 1572 1559 { … … 1595 1582 { 1596 1583 ComPtr<INvramStore> pNvramStore; 1597 HRESULT rc = machine->COMGETTER(NonVolatileStore)(pNvramStore.asOutParam());1598 if (FAILED( rc)) returnrc;1584 HRESULT hrc = machine->COMGETTER(NonVolatileStore)(pNvramStore.asOutParam()); 1585 if (FAILED(hrc)) return hrc; 1599 1586 Bstr bstrSrcNVRAMPath; 1600 rc = pNvramStore->COMGETTER(NonVolatileStorageFile)(bstrSrcNVRAMPath.asOutParam());1601 if (FAILED( rc)) returnrc;1587 hrc = pNvramStore->COMGETTER(NonVolatileStorageFile)(bstrSrcNVRAMPath.asOutParam()); 1588 if (FAILED(hrc)) return hrc; 1602 1589 Utf8Str strSrcNVRAMPath(bstrSrcNVRAMPath); 1603 1590 if (!strSrcNVRAMPath.isEmpty() && RTFileExists(strSrcNVRAMPath.c_str())) … … 1652 1639 { 1653 1640 Bstr bstrLocation; 1654 HRESULT rc = pMedium->COMGETTER(Location)(bstrLocation.asOutParam());1655 if (FAILED( rc))1656 return rc;1641 HRESULT hrc = pMedium->COMGETTER(Location)(bstrLocation.asOutParam()); 1642 if (FAILED(hrc)) 1643 return hrc; 1657 1644 1658 1645 DeviceType_T deviceType; 1659 rc = pMedium->COMGETTER(DeviceType)(&deviceType);1660 if (FAILED( rc))1661 return rc;1646 hrc = pMedium->COMGETTER(DeviceType)(&deviceType); 1647 if (FAILED(hrc)) 1648 return hrc; 1662 1649 1663 1650 ComPtr<IMediumFormat> mediumFormat; 1664 rc = pMedium->COMGETTER(MediumFormat)(mediumFormat.asOutParam());1665 if (FAILED( rc))1666 return rc;1651 hrc = pMedium->COMGETTER(MediumFormat)(mediumFormat.asOutParam()); 1652 if (FAILED(hrc)) 1653 return hrc; 1667 1654 1668 1655 /* Check whether VBox is able to create this medium format or not, i.e. medium can be "read-only" */ 1669 1656 Bstr bstrFormatName; 1670 rc = mediumFormat->COMGETTER(Name)(bstrFormatName.asOutParam());1671 if (FAILED( rc))1672 return rc;1657 hrc = mediumFormat->COMGETTER(Name)(bstrFormatName.asOutParam()); 1658 if (FAILED(hrc)) 1659 return hrc; 1673 1660 1674 1661 Utf8Str formatName = Utf8Str(bstrFormatName);
Note:
See TracChangeset
for help on using the changeset viewer.