VirtualBox

Changeset 46971 in vbox for trunk/src/VBox/Runtime


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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