VirtualBox

Ignore:
Timestamp:
Mar 27, 2015 6:56:06 AM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
99240
Message:

OVF: pr7721. Import images in other formats. Added option "importtovdi" for command "VBoxManage import". Fixed several issues related to compressed disks images inside OVF package.

File:
1 edited

Legend:

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

    r54438 r54979  
    649649                        Utf8Str strTargetPath = Utf8Str(strMachineFolder);
    650650                        strTargetPath.append(RTPATH_DELIMITER).append(di.strHref);
     651                        /*
     652                         * Remove last extension from the file name if the file is compressed
     653                        */
     654                        if(di.strCompression.compare("gzip", Utf8Str::CaseInsensitive)==0)
     655                        {
     656                            strTargetPath.stripSuffix();
     657                        }
     658
    651659                        i_searchUniqueDiskImageFilePath(strTargetPath);
    652660
     
    682690                            .append(RTPATH_DELIMITER)
    683691                            .append(di.strHref);
     692                        /*
     693                         * Remove last extension from the file name if the file is compressed
     694                        */
     695                        if(di.strCompression.compare("gzip", Utf8Str::CaseInsensitive)==0)
     696                        {
     697                            strTargetPath.stripSuffix();
     698                        }
     699
    684700                        i_searchUniqueDiskImageFilePath(strTargetPath);
    685701
     
    23812397                /* Decompress the GZIP file and save a new file in the target path */
    23822398                strTargetDir = strTargetDir.stripFilename();
    2383                 strTargetDir.append("/temp_");
    2384 
    2385                 Utf8Str strTempTargetFilename(*strTargetPath);
     2399                strTargetDir.append(RTPATH_SLASH_STR);
     2400                strTargetDir.append("temp_");
     2401
     2402                Utf8Str strTempTargetFilename(strSrcFilePath);
    23862403                strTempTargetFilename = strTempTargetFilename.stripPath();
    2387                 strTempTargetFilename = strTempTargetFilename.stripSuffix();
    23882404
    23892405                strTargetDir.append(strTempTargetFilename);
     
    24122428                /* Correct the source and the target with the actual values */
    24132429                strSrcFilePath = strTargetDir;
    2414                 strTargetDir = strTargetDir.stripFilename();
    2415                 strTargetDir.append(RTPATH_SLASH_STR);
    2416                 strTargetDir.append(strTempTargetFilename.c_str());
    2417                 *strTargetPath = strTargetDir.c_str();
    24182430
    24192431                pRealUsedStorage = &finalStorage;
     
    24212433
    24222434            Utf8Str strTrgFormat = "VMDK";
     2435            ComObjPtr<MediumFormat> trgFormat;
     2436            Bstr bstrFormatName;
    24232437            ULONG lCabs = 0;
    24242438
    2425             if (RTPathHasSuffix(strTargetPath->c_str()))
    2426             {
    2427                 const char *pszSuff = RTPathSuffix(strTargetPath->c_str());
    2428                 /* Figure out which format the user like to have. Default is VMDK. */
    2429                 ComObjPtr<MediumFormat> trgFormat = pSysProps->i_mediumFormatFromExtension(&pszSuff[1]);
     2439            //check existence of option "ImportToVDI", in this case all imported disks will be converted to VDI images
     2440            bool chExt = m->optListImport.contains(ImportOptions_ImportToVDI);
     2441
     2442            char *pszSuff = NULL;
     2443
     2444            if ((pszSuff = RTPathSuffix(strTargetPath->c_str()))!=NULL)
     2445            {
     2446                /*
     2447                 * Figure out which format the user like to have. Default is VMDK
     2448                 * or it can be VDI if according command-line option is set
     2449                 */
     2450
     2451                /*
     2452                 * We need a proper target format
     2453                 * if target format has been changed by user via GUI import wizard
     2454                 * or via VBoxManage import command (option --importtovdi)
     2455                 * then we need properly process such format like ISO
     2456                 * Because there is no conversion ISO to VDI
     2457                 */
     2458
     2459                pszSuff++;
     2460                trgFormat = pSysProps->i_mediumFormatFromExtension(pszSuff);
    24302461                if (trgFormat.isNull())
    2431                     throw setError(VBOX_E_NOT_SUPPORTED,
    2432                                    tr("Could not find a valid medium format for the target disk '%s'"),
    2433                                    strTargetPath->c_str());
     2462                {
     2463                    rc = setError(E_FAIL,
     2464                           tr("Internal inconsistency looking up medium format for the disk image '%s'"),
     2465                           di.strHref.c_str());
     2466                }
     2467
     2468                rc = trgFormat->COMGETTER(Name)(bstrFormatName.asOutParam());
     2469                if (FAILED(rc)) throw rc;
     2470
     2471                strTrgFormat = Utf8Str(bstrFormatName);
     2472
     2473                if(chExt && strTrgFormat.compare("RAW", Utf8Str::CaseInsensitive) != 0)
     2474                {
     2475                    /* change the target extension */
     2476                    strTrgFormat = "vdi";
     2477                    trgFormat = pSysProps->i_mediumFormatFromExtension(strTrgFormat);
     2478                    *strTargetPath = strTargetPath->stripSuffix();
     2479                    *strTargetPath = strTargetPath->append(".");
     2480                    *strTargetPath = strTargetPath->append(strTrgFormat.c_str());
     2481                }
     2482
    24342483                /* Check the capabilities. We need create capabilities. */
    24352484                lCabs = 0;
     
    24502499                                   tr("Could not find a valid medium format for the target disk '%s'"),
    24512500                                   strTargetPath->c_str());
    2452                 Bstr bstrFormatName;
    2453                 rc = trgFormat->COMGETTER(Name)(bstrFormatName.asOutParam());
    2454                 if (FAILED(rc)) throw rc;
    2455                 strTrgFormat = Utf8Str(bstrFormatName);
    24562501            }
    24572502            else
     
    38083853                Utf8Str savedVBoxCurrent = vsdeTargetHD->strVBoxCurrent;
    38093854                ComObjPtr<Medium> pTargetHD;
     3855
    38103856                i_importOneDiskImage(diCurrent,
    38113857                                     &vsdeTargetHD->strVBoxCurrent,
Note: See TracChangeset for help on using the changeset viewer.

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