VirtualBox

Ignore:
Timestamp:
Jul 23, 2013 5:45:24 PM (11 years ago)
Author:
vboxsync
Message:

This is how I meant you should do decompression.

File:
1 edited

Legend:

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

    r47343 r47357  
    11/* $Id$ */
    22/** @file
    3  *
    43 * IO helper for IAppliance COM class implementations.
    54 */
    65
    76/*
    8  * Copyright (C) 2010-2012 Oracle Corporation
     7 * Copyright (C) 2010-2013 Oracle Corporation
    98 *
    109 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3332#include <iprt/stream.h>
    3433#include <iprt/circbuf.h>
     34#include <iprt/vfs.h>
    3535#include <VBox/vd.h>
    3636#include <zlib.h>
     37//#define VBOX_MAIN_USE_VFS /** @todo Replace as much as possible with IPRT VFS. */
    3738
    3839/******************************************************************************
     
    14061407    AssertPtrReturn(pIfIo, VERR_INVALID_POINTER);
    14071408
     1409    /*
     1410     * Open the source file.
     1411     */
    14081412    void *pvStorage;
    14091413    int rc = pIfIo->pfnOpen(pvUser, pcszFullFilenameIn,
     
    14121416    if (RT_FAILURE(rc))
    14131417        return rc;
     1418#ifdef VBOX_MAIN_USE_VFS
     1419
     1420    /* Turn the source file handle/whatever into a VFS stream. */
     1421    RTVFSIOSTREAM hVfsIosCompressedSrc;
     1422    rc = VDIfCreateVfsStream(pIfIo, pvStorage, RTFILE_O_READ, &hVfsIosCompressedSrc);
     1423    if (RT_SUCCESS(rc))
     1424    {
     1425        /* Pass the source thru gunzip. */
     1426        RTVFSIOSTREAM hVfsIosSrc;
     1427        rc = RTZipGzipDecompressIoStream(hVfsIosCompressedSrc, 0, &hVfsIosSrc);
     1428        if (RT_SUCCESS(rc))
     1429        {
     1430            /*
     1431             * Create the output file, including necessary paths.
     1432             * Any existing file will be overwritten.
     1433             */
     1434            rc = VirtualBox::ensureFilePathExists(Utf8Str(pcszFullFilenameOut), true /*fCreate*/);
     1435            if (RT_SUCCESS(rc))
     1436            {
     1437                RTVFSIOSTREAM hVfsIosDst;
     1438                rc = RTVfsIoStrmOpenNormal(pcszFullFilenameOut,
     1439                                           RTFILE_O_CREATE_REPLACE | RTFILE_O_WRITE | RTFILE_O_DENY_ALL,
     1440                                           &hVfsIosDst);
     1441                if (RT_SUCCESS(rc))
     1442                {
     1443                    /*
     1444                     * Pump the bytes thru. If we fail, delete the output file.
     1445                     */
     1446                    rc = RTVfsUtilPumpIoStreams(hVfsIosSrc, hVfsIosDst, 0);
     1447
     1448                    RTVfsIoStrmRelease(hVfsIosDst);
     1449                    RTFileDelete(pcszFullFilenameOut);
     1450                }
     1451            }
     1452
     1453            RTVfsIoStrmRelease(hVfsIosSrc);
     1454        }
     1455        RTVfsIoStrmRelease(hVfsIosCompressedSrc);
     1456    }
     1457    pIfIo->pfnClose(pvUser, pvStorage);
     1458
     1459#else
    14141460
    14151461    Bytef *decompressedBuffer = 0;
     
    14351481            if (FAILED(rc))
    14361482            {
    1437                 rc = VBOX_E_FILE_ERROR;
     1483                rc = VBOX_E_FILE_ERROR; /** @todo r=bird: You're mixing COM and VBox status codes... */
    14381484                break;
    14391485            }
     
    15321578    if (compressedBuffer)
    15331579        RTMemFree(compressedBuffer);
     1580#endif /* !VBOX_MAIN_USE_VFS */
    15341581
    15351582    return rc;
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