VirtualBox

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


Ignore:
Timestamp:
Sep 16, 2010 3:26:13 PM (14 years ago)
Author:
vboxsync
Message:

OVA: parse ovf in memory on ova import (no need for a temporary ovf anymore)

File:
1 edited

Legend:

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

    r31676 r32568  
    691691        /* Create the SHA1 sum of the OVF file for later validation */
    692692        char *pszDigest;
    693         int vrc = RTSha1Digest(locInfo.strPath.c_str(), &pszDigest, NULL, NULL);
     693        int vrc = RTSha1DigestFromFile(locInfo.strPath.c_str(), &pszDigest, NULL, NULL);
    694694        if (RT_FAILURE(vrc))
    695695            DebugBreakThrow(setError(VBOX_E_FILE_ERROR,
     
    724724
    725725    AutoWriteLock appLock(this COMMA_LOCKVAL_SRC_POS);
    726 
    727726    HRESULT rc = S_OK;
    728     int vrc = VINF_SUCCESS;
    729     char szOSTmpDir[RTPATH_MAX];
    730     RTPathTemp(szOSTmpDir, sizeof(szOSTmpDir));
    731     /* The template for the temporary directory created below */
    732     char *pszTmpDir;
    733     RTStrAPrintf(&pszTmpDir, "%s"RTPATH_SLASH_STR"vbox-ovf-XXXXXX", szOSTmpDir);
    734     list< pair<Utf8Str, ULONG> > filesList;
    735     Utf8Str strTmpOvf;
     727    void *pvBuf = 0;
    736728
    737729    try
    738730    {
    739         /* Extract the path */
    740731        Utf8Str tmpPath = locInfo.strPath;
    741732        /* Remove the ova extension */
    742733        tmpPath.stripExt();
     734        /* add the ovf extension. */
    743735        tmpPath += ".ovf";
    744 
    745         /* We need a temporary directory which we can put the OVF file & all
    746          * disk images in */
    747         vrc = RTDirCreateTemp(pszTmpDir);
     736        char* pcszOVFName = RTPathFilename(tmpPath.c_str());
     737
     738        /* Read the OVF into a memory buffer */
     739        uint64_t cbSize;
     740        int vrc = RTTarExtractFileToBuf(locInfo.strPath.c_str(), &pvBuf, &cbSize, pcszOVFName, 0, 0);
    748741        if (RT_FAILURE(vrc))
    749             DebugBreakThrow(setError(VBOX_E_FILE_ERROR,
    750                            tr("Cannot create temporary directory '%s' (%Rrc)"), pszTmpDir, vrc));
    751 
    752         /* The temporary name of the target OVF file */
    753         strTmpOvf = Utf8StrFmt("%s/%s", pszTmpDir, RTPathFilename(tmpPath.c_str()));
    754 
    755         /* Next we have to download the OVF */
    756         char *papszFile = RTPathFilename(strTmpOvf.c_str());
    757         vrc = RTTarExtractFiles(locInfo.strPath.c_str(), pszTmpDir, &papszFile, 1, 0, 0);
     742        {
     743            if (vrc == VERR_FILE_NOT_FOUND)
     744                throw setError(VBOX_E_IPRT_ERROR,
     745                               tr("Can't find ovf file '%s' in archive '%s' (%Rrc)"), pcszOVFName, locInfo.strPath.c_str(), vrc);
     746            else
     747                throw setError(VBOX_E_IPRT_ERROR,
     748                               tr("Can't unpack the archive file '%s' (%Rrc)"), locInfo.strPath.c_str(), vrc);
     749        }
     750
     751        /* Read & parse the XML structure of the OVF file */
     752        m->pReader = new ovf::OVFReader(pvBuf, cbSize, locInfo.strPath);
     753        /* Create the SHA1 sum of the OVF file for later validation */
     754        char *pszDigest;
     755        vrc = RTSha1Digest(pvBuf, cbSize, &pszDigest, 0, 0);
    758756        if (RT_FAILURE(vrc))
    759         {
    760             if (vrc == VERR_FILE_NOT_FOUND)
    761                 DebugBreakThrow(setError(VBOX_E_IPRT_ERROR,
    762                                          tr("Can't find ovf file '%s' in archive '%s' (%Rrc)"), papszFile, locInfo.strPath.c_str(), vrc));
    763             else
    764                 DebugBreakThrow(setError(VBOX_E_IPRT_ERROR,
    765                                          tr("Can't unpack the archive file '%s' (%Rrc)"), locInfo.strPath.c_str(), vrc));
    766         }
    767 
    768         // todo: check this out
    769 //        pTask->pProgress->SetNextOperation(Bstr(tr("Reading")), 1);
    770 
    771         /* Prepare the temporary reading of the OVF */
    772         ComObjPtr<Progress> progress;
    773         LocationInfo li;
    774         li.strPath = strTmpOvf;
    775         /* Start the reading from the fs */
    776         rc = readImpl(li, progress);
    777         if (FAILED(rc)) DebugBreakThrow(rc);
    778 
    779         /* Unlock the appliance for the reading thread */
    780         appLock.release();
    781         /* Wait until the reading is done, but report the progress back to the
    782            caller */
    783         ComPtr<IProgress> progressInt(progress);
    784         waitForAsyncProgress(pProgress, progressInt); /* Any errors will be thrown */
    785 
    786         /* Again lock the appliance for the next steps */
    787         appLock.acquire();
    788     }
    789     catch(HRESULT aRC)
     757            throw setError(VBOX_E_FILE_ERROR,
     758                           tr("Couldn't calculate SHA1 digest for file '%s' (%Rrc)"),
     759                           RTPathFilename(locInfo.strPath.c_str()), vrc);
     760        m->strOVFSHA1Digest = pszDigest;
     761        RTStrFree(pszDigest);
     762
     763    }
     764    catch (iprt::Error &x)      // includes all XML exceptions
     765    {
     766        rc = setError(VBOX_E_FILE_ERROR,
     767                      x.what());
     768    }
     769    catch (HRESULT aRC)
    790770    {
    791771        rc = aRC;
    792772    }
    793     /* Delete all files which where temporary created */
    794     if (RTPathExists(strTmpOvf.c_str()))
    795     {
    796         vrc = RTFileDelete(strTmpOvf.c_str());
    797         if (RT_FAILURE(vrc))
    798             rc = setError(VBOX_E_FILE_ERROR,
    799                           tr("Cannot delete file '%s' (%Rrc)"), strTmpOvf.c_str(), vrc);
    800     }
    801     /* Delete the temporary directory */
    802     if (RTPathExists(pszTmpDir))
    803     {
    804         vrc = RTDirRemove(pszTmpDir);
    805         if (RT_FAILURE(vrc))
    806             rc = setError(VBOX_E_FILE_ERROR,
    807                           tr("Cannot delete temporary directory '%s' (%Rrc)"), pszTmpDir, vrc);
    808     }
    809     if (pszTmpDir)
    810         RTStrFree(pszTmpDir);
     773
     774    /* Cleanup the OVF memory buffer */
     775    if (pvBuf)
     776        RTMemFree(pvBuf);
    811777
    812778    LogFlowFunc(("rc=%Rhrc\n", rc));
     
    11571123        {
    11581124            char* pszDigest;
    1159             vrc = RTSha1Digest((*it1).c_str(), &pszDigest, NULL, NULL);
     1125            vrc = RTSha1DigestFromFile((*it1).c_str(), &pszDigest, NULL, NULL);
    11601126            pTestList[i].pszTestFile = (char*)(*it1).c_str();
    11611127            pTestList[i].pszTestDigest = pszDigest;
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