VirtualBox

Changeset 50193 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Jan 23, 2014 5:50:07 PM (11 years ago)
Author:
vboxsync
Message:

ApplianceImplImport.cpp,ApplianceImplIO.cpp: Logging, tiny memory leaks, readability.

Location:
trunk/src/VBox/Main/src-server
Files:
2 edited

Legend:

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

    r48955 r50193  
    305305        for (;;)
    306306        {
    307             char *pszFilename = 0;
     307            char *pszFilename;
    308308            rc = RTTarCurrentFile(tar, &pszFilename);
    309309            if (RT_SUCCESS(rc))
     
    311311                if (rc == VINF_TAR_DIR_PATH)
    312312                {
     313                    RTStrFree(pszFilename);
    313314                    break;
    314315                }
     
    319320                if (fFound)
    320321                    break;
    321                 else
    322                 {
    323                     rc = RTTarSeekNextFile(tar);
    324                     if (RT_FAILURE(rc))
    325                     {
    326                         break;
    327                     }
    328                 }
     322                rc = RTTarSeekNextFile(tar);
     323                if (RT_FAILURE(rc))
     324                    break;
    329325            }
    330326            else
  • trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp

    r50182 r50193  
    792792
    793793    int vrc = RTTarCurrentFile(tar, &pszFilename);
    794 
    795794    if (RT_FAILURE(vrc))
    796     {
    797795        throw setError(VBOX_E_FILE_ERROR,
    798                tr("Could not open the current file in the OVA package (%Rrc)"), vrc);
    799     }
    800     else
    801     {
    802         if (vrc == VINF_TAR_DIR_PATH)
    803         {
    804             throw setError(VBOX_E_FILE_ERROR,
    805                    tr("Empty directory folder (%s) isn't allowed in the OVA package (%Rrc)"),
    806                       pszFilename,
    807                       vrc);
    808         }
     796                       tr("Could not open the current file in the OVA package (%Rrc)"), vrc);
     797    if (vrc == VINF_TAR_DIR_PATH)
     798    {
     799        HRESULT hrc = setError(VBOX_E_FILE_ERROR,
     800                               tr("Empty directory folder (%s) isn't allowed in the OVA package (%Rrc)"),
     801                               pszFilename, vrc);
     802        RTStrFree(pszFilename);
     803        throw hrc;
    809804    }
    810805
     
    11271122    /* Cleanup */
    11281123    if (pszFilename)
    1129         RTMemFree(pszFilename);
     1124        RTStrFree(pszFilename);
    11301125    if (pShaIo)
    11311126        RTMemFree(pShaIo);
     
    16661661        pShaIo->Core.pNext            = NULL;
    16671662
    1668         /* Read the file name of the first file (need to be the ovf file). This
    1669          * is how all internal files are named. */
     1663        /*
     1664         * File #1 - the .ova file.
     1665         *
     1666         * Read the name of the first file. This is how all internal files
     1667         * are named.
     1668         */
    16701669        vrc = RTTarCurrentFile(tar, &pszFilename);
    16711670        if (RT_FAILURE(vrc))
    16721671            throw setError(VBOX_E_IPRT_ERROR,
    16731672                           tr("Getting the OVF file within the archive failed (%Rrc)"), vrc);
    1674         else
    1675         {
    1676             if (vrc == VINF_TAR_DIR_PATH)
    1677             {
    1678                 throw setError(VBOX_E_FILE_ERROR,
    1679                        tr("Empty directory folder (%s) isn't allowed in the OVA package (%Rrc)"),
    1680                           pszFilename,
    1681                           vrc);
    1682             }
    1683         }
     1673        if (vrc == VINF_TAR_DIR_PATH)
     1674            throw setError(VBOX_E_FILE_ERROR,
     1675                           tr("Empty directory folder (%s) isn't allowed in the OVA package (%Rrc)"),
     1676                           pszFilename, vrc);
    16841677
    16851678        /* save original OVF filename */
     
    16961689            throw setError(VBOX_E_IPRT_ERROR,
    16971690                           tr("Seeking within the archive failed (%Rrc)"), vrc);
    1698         else
    1699         {
    1700             RTTarCurrentFile(tar, &pszFilename);
    1701             if (vrc == VINF_TAR_DIR_PATH)
    1702             {
    1703                 throw setError(VBOX_E_FILE_ERROR,
    1704                        tr("Empty directory folder (%s) isn't allowed in the OVA package (%Rrc)"),
    1705                           pszFilename,
    1706                           vrc);
    1707             }
    1708         }
     1691        RTStrFree(pszFilename);
     1692        pszFilename = NULL;
     1693        RTTarCurrentFile(tar, &pszFilename);
     1694        if (vrc == VINF_TAR_DIR_PATH)
     1695            throw setError(VBOX_E_FILE_ERROR,
     1696                           tr("Empty directory folder (%s) isn't allowed in the OVA package (%Rrc)"),
     1697                           pszFilename, vrc);
    17091698
    17101699        PVDINTERFACEIO pCallbacks = pShaIo;
    17111700        PSHASTORAGE pStorage = &storage;
    17121701
    1713         /* We always need to create the digest, cause we didn't know if there
     1702        /* We always need to create the digest, cause we don't know if there
    17141703         * is a manifest file in the stream. */
    17151704        pStorage->fCreateDigest = true;
    17161705
    17171706        /*
    1718          * Try to read the manifest file. First try.
     1707         * File #2 - the manifest file (.mf), optional.
    17191708         *
    17201709         * Note: This isn't fatal if the file is not found. The standard
    1721          * defines 3 cases.
    1722          * 1. no manifest file
    1723          * 2. manifest file after the OVF file
    1724          * 3. manifest file after all disk files
     1710         * defines 3 cases:
     1711         *  1. no manifest file
     1712         *  2. manifest file after the OVF file
     1713         *  3. manifest file after all disk files
     1714         *
    17251715         * If we want streaming capabilities, we can't check if it is there by
    17261716         * searching for it. We have to try to open it on all possible places.
     
    17281718         */
    17291719        rc = i_readTarFileToBuf(tar, strMfFile, &pvMfBuf, &cbMfSize, true, pCallbacks, pStorage);
    1730         if (FAILED(rc)) throw rc;
     1720        if (FAILED(rc))
     1721            throw rc;
    17311722
    17321723        /*
    1733          * Try to read the certificate file. First try.
    1734          * Logic is the same as with manifest file
    1735          * Only if the manifest file had been read successfully before
     1724         * File #3 - certificate file (.cer), optional.
     1725         *
     1726         * Logic is the same as with manifest file.  This only makes sense if
     1727         * there is a manifest file.
    17361728         */
    17371729        vrc = RTTarCurrentFile(tar, &pszFilename);
     
    17531745        }
    17541746
    1755         /* Now import the appliance. */
     1747        /*
     1748         * Now import the appliance.
     1749         */
    17561750        i_importMachines(stack, pCallbacks, pStorage);
    1757         /* Try to read the manifest file. Second try. */
     1751
     1752        /*
     1753         * The certificate and mainifest files may alternatively be stored
     1754         * after the disk files, so look again if we didn't find them already.
     1755         */
    17581756        if (!pvMfBuf)
    17591757        {
     1758            /*
     1759             * File #N-1 - The manifest file, optional.
     1760             */
    17601761            rc = i_readTarFileToBuf(tar, strMfFile, &pvMfBuf, &cbMfSize, true, pCallbacks, pStorage);
    17611762            if (FAILED(rc)) throw rc;
     
    17701771
    17711772                /*
    1772                  * Try to read the certificate file. Second try.
    1773                  * Only if the manifest file had been read successfully before
     1773                 * File #N - The certificate file, optional.
     1774                 * (Requires mainfest, as mention before.)
    17741775                 */
    1775 
     1776                RTStrFree(pszFilename);
     1777                pszFilename = NULL;
    17761778                vrc = RTTarCurrentFile(tar, &pszFilename);
    17771779                if (RT_SUCCESS(vrc))
     
    18231825    /* Cleanup */
    18241826    if (pszFilename)
    1825         RTMemFree(pszFilename);
     1827        RTStrFree(pszFilename);
    18261828    if (pvMfBuf)
    18271829        RTMemFree(pvMfBuf);
     
    20712073    if (RT_SUCCESS(vrc))
    20722074    {
    2073         if (vrc == VINF_TAR_DIR_PATH)
    2074         {
    2075             rc = setError(VBOX_E_FILE_ERROR,
    2076                           tr("Empty directory folder (%s) isn't allowed in the OVA package (%Rrc)"),
    2077                              pszCurFile,
    2078                              vrc);
    2079         }
    2080         else
     2075        if (vrc != VINF_TAR_DIR_PATH)
    20812076        {
    20822077            if (!strcmp(pszCurFile, RTPathFilename(strFile.c_str())))
    20832078                rc = i_readFileToBuf(strFile, ppvBuf, pcbSize, fCreateDigest, pCallbacks, pStorage);
    2084             RTStrFree(pszCurFile);
    20852079        }
     2080        else
     2081            rc = setError(VBOX_E_FILE_ERROR,
     2082                          tr("Empty directory folder (%s) isn't allowed in the OVA package (%Rrc)"),
     2083                          pszCurFile, vrc);
     2084        RTStrFree(pszCurFile);
    20862085    }
    20872086    else if (vrc != VERR_TAR_END_OF_FILE)
     
    30123011                size_t i = 0;
    30133012                for (list<VirtualSystemDescriptionEntry*>::const_iterator itHD = avsdeHDs.begin(); itHD != avsdeHDs.end(); ++itHD, i++)
    3014                     Log(("avsdeHDs[%zu]: strRef=%s\n", i, (*itHD)->strRef.c_str()));
     3013                    Log(("avsdeHDs[%zu]: strRef=%s strOvf=%s\n", i, (*itHD)->strRef.c_str(), (*itHD)->strOvf.c_str()));
     3014                i = 0;
     3015                for (ovf::DiskImagesMap::const_iterator itDisk = stack.mapDisks.begin(); itDisk != stack.mapDisks.end(); ++itDisk)
     3016                    Log(("mapDisks[%zu]: strDiskId=%s strHref=%s\n", i, itDisk->second.strDiskId.c_str(), itDisk->second.strHref.c_str()));
     3017
    30153018            }
    30163019#endif
     
    30383041
    30393042                VirtualSystemDescriptionEntry *vsdeTargetHD = 0;
    3040                 Log(("diCurrent.strDiskId=%s\n", diCurrent.strDiskId.c_str()));
     3043                Log(("diCurrent.strDiskId=%s diCurrent.strHref=%s\n", diCurrent.strDiskId.c_str(), diCurrent.strHref.c_str()));
    30413044
    30423045                /*
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