- Timestamp:
- Sep 30, 2010 2:48:42 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ApplianceImplExport.cpp
r32837 r32850 32 32 #include "ProgressImpl.h" 33 33 #include "MachineImpl.h" 34 #include "MediumImpl.h" 35 #include "MediumFormatImpl.h" 36 #include "SystemPropertiesImpl.h" 34 37 35 38 #include "AutoCaller.h" … … 1615 1618 } 1616 1619 1620 // We need a proper format description 1621 ComObjPtr<MediumFormat> format; 1622 { // Scope for the AutoReadLock 1623 SystemProperties *pSysProps = mVirtualBox->getSystemProperties(); 1624 AutoReadLock propsLock(pSysProps COMMA_LOCKVAL_SRC_POS); 1625 // We are always exporting to VMDK stream optimized for now 1626 format = pSysProps->mediumFormat("VMDK"); 1627 if (format.isNull()) 1628 throw setError(VBOX_E_NOT_SUPPORTED, 1629 tr("Invalid medium storage format")); 1630 } 1631 1617 1632 // Finally, write out the disks! 1618 1633 list<Utf8Str> diskList; … … 1634 1649 1635 1650 // clone the disk: 1636 ComPtr<IMedium> pSourceDisk; 1637 ComPtr<IMedium> pTargetDisk; 1638 ComPtr<IProgress> pProgress2; 1651 ComObjPtr<Medium> pSourceDisk; 1639 1652 1640 1653 Log(("Finding source disk \"%ls\"\n", bstrSrcFilePath.raw())); 1641 rc = mVirtualBox-> FindMedium(bstrSrcFilePath.raw(), DeviceType_HardDisk, pSourceDisk.asOutParam());1654 rc = mVirtualBox->findHardDisk(NULL, bstrSrcFilePath.raw(), true, &pSourceDisk); 1642 1655 if (FAILED(rc)) throw rc; 1643 1656 … … 1655 1668 strTargetFilePath.append(strTargetFileNameOnly); 1656 1669 1657 // We are always exporting to VMDK stream optimized for now 1658 Bstr bstrSrcFormat = L"VMDK"; 1659 1660 // create a new hard disk interface for the destination disk image 1661 Log(("Creating target disk \"%s\"\n", strTargetFilePath.c_str())); 1662 rc = mVirtualBox->CreateHardDisk(bstrSrcFormat.raw(), 1663 Bstr(strTargetFilePath).raw(), 1664 pTargetDisk.asOutParam()); 1665 if (FAILED(rc)) throw rc; 1666 1667 // The cloning requests a lock on the media tree. So leave our lock temporary. 1670 // The exporting requests a lock on the media tree. So leave our lock temporary. 1668 1671 multiLock.release(); 1669 // the target disk is now registered and needs to be removed again,1670 // both after successful cloning or if anything goes bad!1671 1672 try 1672 1673 { 1674 ComObjPtr<Progress> pProgress2; 1675 pProgress2.createObject(); 1676 rc = pProgress2->init(mVirtualBox, static_cast<IAppliance*>(this), BstrFmt(tr("Creating medium '%s'"), strTargetFilePath.c_str()).raw(), TRUE); 1677 if (FAILED(rc)) throw rc; 1673 1678 // create a flat copy of the source disk image 1674 rc = pSourceDisk-> CloneTo(pTargetDisk, MediumVariant_VmdkStreamOptimized, NULL, pProgress2.asOutParam());1679 rc = pSourceDisk->exportFile(strTargetFilePath.c_str(), format, MediumVariant_VmdkStreamOptimized, NULL, NULL, pProgress2); 1675 1680 if (FAILED(rc)) throw rc; 1676 1681 … … 1679 1684 pDiskEntry->ulSizeMB); // operation's weight, as set up with the IProgress originally); 1680 1685 1686 ComPtr<IProgress> pProgress3(pProgress2); 1681 1687 // now wait for the background disk operation to complete; this throws HRESULTs on error 1682 waitForAsyncProgress(pTask->pProgress, pProgress 2);1688 waitForAsyncProgress(pTask->pProgress, pProgress3); 1683 1689 } 1684 1690 catch (HRESULT rc3) 1685 1691 { 1686 // upon error after registering, close the disk or 1687 // it'll stick in the registry forever 1688 pTargetDisk->Close(); 1692 // Todo: file deletion on error? If not, we can remove that whole try/catch block. 1689 1693 throw rc3; 1690 1694 } … … 1693 1697 multiLock.acquire(); 1694 1698 diskList.push_back(strTargetFilePath); 1695 1696 // we need the following for the XML1697 LONG64 cbFile = 0; // actual file size1698 rc = pTargetDisk->COMGETTER(Size)(&cbFile);1699 if (FAILED(rc)) throw rc;1700 1701 LONG64 cbCapacity = 0; // size reported to guest1702 rc = pTargetDisk->COMGETTER(LogicalSize)(&cbCapacity);1703 if (FAILED(rc)) throw rc;1704 // capacity is reported in megabytes, so...1705 cbCapacity *= _1M;1706 1707 Bstr uuidTarget;1708 rc = pTargetDisk->COMGETTER(Id)(uuidTarget.asOutParam());1709 if (FAILED(rc)) throw rc;1710 Guid guidTarget(uuidTarget);1711 1712 // upon success, close the disk as well1713 rc = pTargetDisk->Close();1714 if (FAILED(rc)) throw rc;1715 1699 } 1716 1700
Note:
See TracChangeset
for help on using the changeset viewer.