VirtualBox

Changeset 32850 in vbox for trunk/src


Ignore:
Timestamp:
Sep 30, 2010 2:48:42 PM (14 years ago)
Author:
vboxsync
Message:

Main: utilize Medium::exportFile on Appliance export

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/ApplianceImplExport.cpp

    r32837 r32850  
    3232#include "ProgressImpl.h"
    3333#include "MachineImpl.h"
     34#include "MediumImpl.h"
     35#include "MediumFormatImpl.h"
     36#include "SystemPropertiesImpl.h"
    3437
    3538#include "AutoCaller.h"
     
    16151618        }
    16161619
     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
    16171632        // Finally, write out the disks!
    16181633        list<Utf8Str> diskList;
     
    16341649
    16351650            // clone the disk:
    1636             ComPtr<IMedium> pSourceDisk;
    1637             ComPtr<IMedium> pTargetDisk;
    1638             ComPtr<IProgress> pProgress2;
     1651            ComObjPtr<Medium> pSourceDisk;
    16391652
    16401653            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);
    16421655            if (FAILED(rc)) throw rc;
    16431656
     
    16551668            strTargetFilePath.append(strTargetFileNameOnly);
    16561669
    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.
    16681671            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!
    16711672            try
    16721673            {
     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;
    16731678                // 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);
    16751680                if (FAILED(rc)) throw rc;
    16761681
     
    16791684                                                   pDiskEntry->ulSizeMB);     // operation's weight, as set up with the IProgress originally);
    16801685
     1686                ComPtr<IProgress> pProgress3(pProgress2);
    16811687                // now wait for the background disk operation to complete; this throws HRESULTs on error
    1682                 waitForAsyncProgress(pTask->pProgress, pProgress2);
     1688                waitForAsyncProgress(pTask->pProgress, pProgress3);
    16831689            }
    16841690            catch (HRESULT rc3)
    16851691            {
    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.
    16891693                throw rc3;
    16901694            }
     
    16931697            multiLock.acquire();
    16941698            diskList.push_back(strTargetFilePath);
    1695 
    1696             // we need the following for the XML
    1697             LONG64 cbFile = 0;        // actual file size
    1698             rc = pTargetDisk->COMGETTER(Size)(&cbFile);
    1699             if (FAILED(rc)) throw rc;
    1700 
    1701             LONG64 cbCapacity = 0;     // size reported to guest
    1702             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 well
    1713             rc = pTargetDisk->Close();
    1714             if (FAILED(rc)) throw rc;
    17151699        }
    17161700
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette