VirtualBox

Changeset 33346 in vbox for trunk/src


Ignore:
Timestamp:
Oct 22, 2010 12:11:21 PM (14 years ago)
Author:
vboxsync
Message:

Main-OVF: more cleanup

File:
1 edited

Legend:

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

    r33345 r33346  
    16671667                                   PSHA1STORAGE pStorage)
    16681668{
    1669     // destination file must not exist
    1670     if (    strTargetPath.isEmpty()
    1671         || RTPathExists(strTargetPath.c_str())
    1672        )
    1673         throw setError(VBOX_E_FILE_ERROR,
    1674                        tr("Destination file '%s' exists"),
    1675                        strTargetPath.c_str());
    1676 
    16771669    ComObjPtr<Progress> pProgress;
    16781670    pProgress.createObject();
     
    16861678        char *pszExt = RTPathExt(strTargetPath.c_str());
    16871679        /* Figure out which format the user like to have. Default is VMDK. */
    1688         ComObjPtr<MediumFormat> targetFormat = pSysProps->mediumFormatFromExtension(&pszExt[1]);
    1689         if (targetFormat.isNull())
     1680        ComObjPtr<MediumFormat> trgFormat = pSysProps->mediumFormatFromExtension(&pszExt[1]);
     1681        if (trgFormat.isNull())
    16901682            throw setError(VBOX_E_NOT_SUPPORTED,
    16911683                           tr("Could not find a valid medium format for the target disk '%s'"),
    16921684                           strTargetPath.c_str());
    16931685        Bstr bstrFormatName;
    1694         rc = targetFormat->COMGETTER(Name)(bstrFormatName.asOutParam());
     1686        rc = trgFormat->COMGETTER(Name)(bstrFormatName.asOutParam());
    16951687        if (FAILED(rc)) throw rc;
    16961688        strTrgFormat = Utf8Str(bstrFormatName);
     
    17141706
    17151707    const Utf8Str &strSourceOVF = di.strHref;
    1716     // construct source file path
     1708    /* Construct source file path */
    17171709    Utf8StrFmt strSrcFilePath("%s%c%s", stack.strSourceDir.c_str(), RTPATH_DELIMITER, strSourceOVF.c_str());
    17181710
    1719     /* If strHref is empty we have to create a new file */
     1711    /* If strHref is empty we have to create a new file. */
    17201712    if (strSourceOVF.isEmpty())
    17211713    {
    1722         // create a dynamic growing disk image with the given capacity
     1714        /* Create a dynamic growing disk image with the given capacity. */
    17231715        rc = pTargetHD->CreateBaseStorage(di.iCapacity / _1M, MediumVariant_Standard, ComPtr<IProgress>(pProgress).asOutParam());
    17241716        if (FAILED(rc)) throw rc;
    17251717
    1726         // advance to the next operation
     1718        /* Advance to the next operation. */
    17271719        stack.pProgress->SetNextOperation(BstrFmt(tr("Creating disk image '%s'"), strTargetPath.c_str()).raw(),
    17281720                                          di.ulSuggestedSizeMB);     // operation's weight, as set up with the IProgress originally
     
    17301722    else
    17311723    {
    1732         // We need a proper format description
    1733         ComObjPtr<MediumFormat> format;
    1734         // Scope for the AutoReadLock
    1735         {
    1736             /* Which format to use? */
    1737             Utf8Str strSrcFormat = "VDI";
    1738             if (   di.strFormat.compare("http://www.vmware.com/specifications/vmdk.html#sparse", Utf8Str::CaseInsensitive)
    1739                 || di.strFormat.compare("http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized", Utf8Str::CaseInsensitive)
    1740                 || di.strFormat.compare("http://www.vmware.com/specifications/vmdk.html#compressed", Utf8Str::CaseInsensitive)
    1741                 || di.strFormat.compare("http://www.vmware.com/interfaces/specifications/vmdk.html#compressed", Utf8Str::CaseInsensitive)
    1742                )
    1743                 strSrcFormat = "VMDK";
    1744             format = pSysProps->mediumFormat(strSrcFormat);
    1745             if (format.isNull())
    1746                 throw setError(VBOX_E_NOT_SUPPORTED,
    1747                                tr("Could not find a valid medium format for the source disk '%s'"),
    1748                                RTPathFilename(strSrcFilePath.c_str()));
    1749         }
     1724        /* We need a proper source format description */
     1725        ComObjPtr<MediumFormat> srcFormat;
     1726        /* Which format to use? */
     1727        Utf8Str strSrcFormat = "VDI";
     1728        if (   di.strFormat.compare("http://www.vmware.com/specifications/vmdk.html#sparse", Utf8Str::CaseInsensitive)
     1729               || di.strFormat.compare("http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized", Utf8Str::CaseInsensitive)
     1730               || di.strFormat.compare("http://www.vmware.com/specifications/vmdk.html#compressed", Utf8Str::CaseInsensitive)
     1731               || di.strFormat.compare("http://www.vmware.com/interfaces/specifications/vmdk.html#compressed", Utf8Str::CaseInsensitive)
     1732           )
     1733            strSrcFormat = "VMDK";
     1734        srcFormat = pSysProps->mediumFormat(strSrcFormat);
     1735        if (srcFormat.isNull())
     1736            throw setError(VBOX_E_NOT_SUPPORTED,
     1737                           tr("Could not find a valid medium format for the source disk '%s'"),
     1738                           RTPathFilename(strSrcFilePath.c_str()));
    17501739
    17511740        /* Clone the source disk image */
    17521741        ComObjPtr<Medium> nullParent;
    17531742        rc = pTargetHD->importFile(strSrcFilePath.c_str(),
    1754                                    format,
     1743                                   srcFormat,
    17551744                                   MediumVariant_Standard,
    17561745                                   pCallbacks, pStorage,
     
    17581747                                   pProgress);
    17591748
    1760         /* Advance to the next operation */
     1749        /* Advance to the next operation. */
    17611750        stack.pProgress->SetNextOperation(BstrFmt(tr("Importing virtual disk image '%s'"), RTPathFilename(strSrcFilePath.c_str())).raw(),
    17621751                                          di.ulSuggestedSizeMB);     // operation's weight, as set up with the IProgress originally);
    17631752    }
    17641753
    1765     // now wait for the background disk operation to complete; this throws HRESULTs on error
     1754    /* Now wait for the background disk operation to complete; this throws
     1755     * HRESULTs on error. */
    17661756    ComPtr<IProgress> pp(pProgress);
    17671757    waitForAsyncProgress(stack.pProgress, pp);
    17681758
     1759    /* Add the newly create disk path + a corresponding digest the our list for
     1760     * later manifest verification. */
    17691761    stack.llSrcDisksDigest.push_back(STRPAIR(strSrcFilePath, pStorage->strDigest));
    17701762}
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