VirtualBox

Changeset 46971 in vbox for trunk


Ignore:
Timestamp:
Jul 4, 2013 7:46:39 AM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
86979
Message:

pr6022. Support handling directories in the TAR has been added. Added several useful checks during import OVA package.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/err.h

    r46403 r46971  
    16961696/** Too long name or link string. */
    16971697#define VERR_TAR_NAME_TOO_LONG                  (-947)
     1698/** A directory entry in the archive. */
     1699#define VINF_TAR_DIR_PATH                        (925)
    16981700/** @} */
    16991701
  • trunk/src/VBox/Main/src-server/ApplianceImplIO.cpp

    r46611 r46971  
    304304            if (RT_SUCCESS(rc))
    305305            {
    306                 fFound = !strcmp(pszFilename, RTPathFilename(pszLocation));
     306                if (rc == VINF_TAR_DIR_PATH)
     307                {
     308                    break;
     309                }
     310
     311                fFound = !RTStrICmp(pszFilename, pszLocation);
     312
    307313                RTStrFree(pszFilename);
    308314                if (fFound)
  • trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp

    r46754 r46971  
    809809    {
    810810        throw setError(VBOX_E_FILE_ERROR,
    811                tr("Could not open the current file in the archive (%Rrc)"), vrc);
     811               tr("Could not open the current file in the OVA package (%Rrc)"), vrc);
     812    }
     813    else
     814    {
     815        if (vrc == VINF_TAR_DIR_PATH)
     816        {
     817            throw setError(VBOX_E_FILE_ERROR,
     818                   tr("Empty directory folder (%s) isn't allowed in the OVA package (%Rrc)"),
     819                      pszFilename,
     820                      vrc);
     821        }
    812822    }
    813823
     
    10771087                break;
    10781088            }
     1089
     1090            Utf8Str extension(RTPathExt(pszFilename));
     1091
     1092            if (!extension.endsWith(".ovf",Utf8Str::CaseInsensitive))
     1093            {
     1094                vrc = VERR_FILE_NOT_FOUND;
     1095                rc = setError(VBOX_E_FILE_ERROR,
     1096                              tr("First file in the OVA package must have the extension 'ovf'. "
     1097                                 "But the file '%s' has the different extension (%Rrc)"),
     1098                                 pszFilename,
     1099                                 vrc);
     1100                break;
     1101            }
     1102
    10791103            pTarIo = TarCreateInterface();
    10801104            if (!pTarIo)
     
    11411165        size_t cbSize = 0;
    11421166        int vrc = ShaReadBuf(strFilename.c_str(), &pvTmpBuf, &cbSize, pIfIo, pStorage);
    1143         if (   RT_FAILURE(vrc)
     1167        if (RT_FAILURE(vrc)
    11441168            || !pvTmpBuf)
    11451169            throw setError(VBOX_E_FILE_ERROR,
     
    15871611            throw setError(VBOX_E_IPRT_ERROR,
    15881612                           tr("Getting the current file within the archive failed (%Rrc)"), vrc);
     1613        else
     1614        {
     1615            if (vrc == VINF_TAR_DIR_PATH)
     1616            {
     1617                throw setError(VBOX_E_FILE_ERROR,
     1618                       tr("Empty directory folder (%s) isn't allowed in the OVA package (%Rrc)"),
     1619                          pszFilename,
     1620                          vrc);
     1621            }
     1622        }
    15891623        /* Skip the OVF file, cause this was read in IAppliance::Read already. */
    15901624        vrc = RTTarSeekNextFile(tar);
     
    15931627            throw setError(VBOX_E_IPRT_ERROR,
    15941628                           tr("Seeking within the archive failed (%Rrc)"), vrc);
     1629        else
     1630        {
     1631            if (vrc == VINF_TAR_DIR_PATH)
     1632            {
     1633                RTTarCurrentFile(tar, &pszFilename);
     1634                throw setError(VBOX_E_FILE_ERROR,
     1635                       tr("Empty directory folder (%s) isn't allowed in the OVA package (%Rrc)"),
     1636                          pszFilename,
     1637                          vrc);
     1638            }
     1639        }
    15951640
    15961641        PVDINTERFACEIO pCallbacks = pShaIo;
     
    18781923    if (RT_SUCCESS(vrc))
    18791924    {
    1880         if (!strcmp(pszCurFile, RTPathFilename(strFile.c_str())))
    1881             rc = readManifestFile(strFile, ppvBuf, pcbSize, pCallbacks, pStorage);
    1882         RTStrFree(pszCurFile);
     1925        if (vrc == VINF_TAR_DIR_PATH)
     1926        {
     1927            rc = setError(VBOX_E_FILE_ERROR,
     1928                          tr("Empty directory folder (%s) isn't allowed in the OVA package (%Rrc)"),
     1929                             pszCurFile,
     1930                             vrc);
     1931        }
     1932        else
     1933        {
     1934            if (!strcmp(pszCurFile, RTPathFilename(strFile.c_str())))
     1935                rc = readManifestFile(strFile, ppvBuf, pcbSize, pCallbacks, pStorage);
     1936            RTStrFree(pszCurFile);
     1937        }
    18831938    }
    18841939    else if (vrc != VERR_TAR_END_OF_FILE)
     
    27712826                                {
    27722827                                    throw setError(E_FAIL,
    2773                                                    tr("Internal inconsistency looking up disk image '%s'"),
     2828                                                   tr("Internal inconsistency looking up disk image '%s'. "
     2829                                                      "Check compliance OVA package structure and file names "
     2830                                                      "references in the section <References> in the OVF file."),
    27742831                                                   availableImage.c_str());
    27752832                                }
     
    32033260                    {
    32043261                        throw setError(E_FAIL,
    3205                                        tr("Internal inconsistency looking up disk image '%s'"),
     3262                                       tr("Internal inconsistency looking up disk image '%s'. "
     3263                                          "Check compliance OVA package structure and file names "
     3264                                          "references in the section <References> in the OVF file."),
    32063265                                       availableImage.c_str());
    32073266                    }
  • trunk/src/VBox/Runtime/common/zip/tar.cpp

    r46518 r46971  
    136136    /** The open mode. */
    137137    uint32_t        fOpenMode;
     138    /** The link flag. */
     139    char            linkflag;
    138140} RTTARFILEINTERNAL;
    139141/** Pointer to the internal data of a tar file.  */
     
    16211623    uint64_t offCur = RTFileTell(pInt->hTarFile);
    16221624    if (!(   pInt->pFileCache->offStart <= offCur
    1623           && offCur < pInt->pFileCache->offStart + sizeof(RTTARRECORD) + pInt->pFileCache->cbSize))
     1625          && offCur <= pInt->pFileCache->offStart + sizeof(RTTARRECORD) + pInt->pFileCache->cbSize))
    16241626        return VERR_INVALID_STATE;
    16251627
    16261628    /* Seek to the next file header. */
    16271629    uint64_t offNext = RT_ALIGN(pInt->pFileCache->offStart + sizeof(RTTARRECORD) + pInt->pFileCache->cbSize, sizeof(RTTARRECORD));
    1628     rc = RTFileSeek(pInt->hTarFile, offNext - offCur, RTFILE_SEEK_CURRENT, NULL);
    1629     if (RT_FAILURE(rc))
    1630         return rc;
     1630    if (pInt->pFileCache->cbSize != 0)
     1631    {
     1632        rc = RTFileSeek(pInt->hTarFile, offNext - offCur, RTFILE_SEEK_CURRENT, NULL);
     1633        if (RT_FAILURE(rc))
     1634            return rc;
     1635    }
     1636    else
     1637    {
     1638        /* Else delete the last open file cache. Might be recreated below. */
     1639        rtDeleteTarFileInternal(pInt->pFileCache);
     1640        pInt->pFileCache = NULL;
     1641    }
    16311642
    16321643    /* Again check the current filename to fill the cache with the new value. */
     
    16521663    if (pInt->pFileCache)
    16531664    {
    1654         /* Are we still direct behind that header? */
    1655         if (pInt->pFileCache->offStart + sizeof(RTTARRECORD) == RTFileTell(pInt->hTarFile))
     1665        if (pInt->pFileCache->offStart + sizeof(RTTARRECORD) < RTFileTell(pInt->hTarFile))
     1666        {
     1667            /* Else delete the last open file cache. Might be recreated below. */
     1668            rtDeleteTarFileInternal(pInt->pFileCache);
     1669            pInt->pFileCache = NULL;
     1670        }
     1671        else/* Are we still direct behind that header? */
    16561672        {
    16571673            /* Yes, so the streaming can start. Just return the cached file
     
    16601676            if (ppszFilename)
    16611677                *ppszFilename = RTStrDup(pInt->pFileCache->pszFilename);
    1662             return VINF_SUCCESS;
    1663         }
    1664 
    1665         /* Else delete the last open file cache. Might be recreated below. */
    1666         rtDeleteTarFileInternal(pInt->pFileCache);
    1667         pInt->pFileCache = NULL;
     1678            if (pInt->pFileCache->linkflag == LF_DIR)
     1679                return VINF_TAR_DIR_PATH;
     1680            else
     1681                return VINF_SUCCESS;
     1682        }
     1683
    16681684    }
    16691685
     
    16831699        /* We support normal files only */
    16841700        if (   record.h.linkflag == LF_OLDNORMAL
    1685             || record.h.linkflag == LF_NORMAL)
     1701            || record.h.linkflag == LF_NORMAL
     1702            || record.h.linkflag == LF_DIR)
    16861703        {
    16871704            pFileInt = rtCreateTarFileInternal(pInt, record.h.name, fOpen);
     
    16961713            /* The start is -512 from here. */
    16971714            pFileInt->offStart = RTFileTell(pInt->hTarFile) - sizeof(RTTARRECORD);
     1715            /* remember the type of a file */
     1716            pFileInt->linkflag = record.h.linkflag;
    16981717
    16991718            /* Copy the new file structure to our cache. */
     
    17011720            if (ppszFilename)
    17021721                *ppszFilename = RTStrDup(pFileInt->pszFilename);
     1722
     1723            if (pFileInt->linkflag == LF_DIR)
     1724            {
     1725                rc = VINF_TAR_DIR_PATH;
     1726            }
    17031727        }
    17041728    } while (0);
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