VirtualBox

Changeset 78747 in vbox


Ignore:
Timestamp:
May 25, 2019 4:26:09 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
130834
Message:

Main/Appliance::i_readImpl: Fixes for regressions introduced by r130427 (bugref:130427) and cleaning up the code, getting rid of the very silly way of returning status codes by exception. Untested.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/ApplianceImpl.h

    r78428 r78747  
    161161     * @{
    162162     */
    163     void    i_readImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
     163    HRESULT i_readImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
    164164
    165165    HRESULT i_readFS(TaskOVF *pTask);
  • trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp

    r78630 r78747  
    8989    }
    9090
     91    /* Parse all necessary info out of the URI (please not how stupid utterly wasteful
     92       this status & allocation error throwing is): */
     93    try
     94    {
     95        i_parseURI(aFile, m->locInfo); /* may trhow rc. */
     96    }
     97    catch (HRESULT aRC)
     98    {
     99        return aRC;
     100    }
     101    catch (std::bad_alloc &)
     102    {
     103        return E_OUTOFMEMORY;
     104    }
     105
     106    // see if we can handle this file; for now we insist it has an ovf/ova extension
     107    if (   m->locInfo.storageType == VFSType_File
     108        && !aFile.endsWith(".ovf", Utf8Str::CaseInsensitive)
     109        && !aFile.endsWith(".ova", Utf8Str::CaseInsensitive))
     110        return setError(VBOX_E_FILE_ERROR, tr("Appliance file must have .ovf or .ova extension"));
     111
    91112    ComObjPtr<Progress> progress;
    92     try
    93     {
    94         /* Parse all necessary info out of the URI */
    95         i_parseURI(aFile, m->locInfo);
    96 
    97         // see if we can handle this file; for now we insist it has an ovf/ova extension
    98         if (   m->locInfo.storageType == VFSType_File
    99             && !aFile.endsWith(".ovf", Utf8Str::CaseInsensitive)
    100             && !aFile.endsWith(".ova", Utf8Str::CaseInsensitive))
    101             return setError(VBOX_E_FILE_ERROR, tr("Appliance file must have .ovf or .ova extension"));
    102 
    103         i_readImpl(m->locInfo, progress);
    104     }
    105     catch (HRESULT aRC)
    106     {
    107         return aRC;
    108     }
    109 
    110     /* Return progress to the caller */
    111     progress.queryInterfaceTo(aProgress.asOutParam());
    112     return S_OK;
     113    HRESULT hrc = i_readImpl(m->locInfo, progress);
     114    if (SUCCEEDED(hrc))
     115        progress.queryInterfaceTo(aProgress.asOutParam());
     116    return hrc;
    113117}
    114118
     
    11091113 *    called Appliance::readFSOVA(), which called Appliance::i_importImpl(), which then called this again.
    11101114 *
     1115 * @returns COM status with error info set.
    11111116 * @param   aLocInfo    The OVF location.
    11121117 * @param   aProgress   Where to return the progress object.
    1113  * @throws  COM error codes will be thrown.
    11141118 */
    1115 void Appliance::i_readImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress)
     1119HRESULT Appliance::i_readImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress)
    11161120{
    1117     BstrFmt bstrDesc = BstrFmt(tr("Reading appliance '%s'"),
    1118                                aLocInfo.strPath.c_str());
    1119     HRESULT rc;
    1120     /* Create the progress object */
     1121    /*
     1122     * Create the progress object.
     1123     */
     1124    HRESULT hrc;
    11211125    aProgress.createObject();
    1122     if (aLocInfo.storageType == VFSType_File)
    1123         /* 1 operation only */
    1124         rc = aProgress->init(mVirtualBox, static_cast<IAppliance*>(this),
    1125                              bstrDesc.raw(),
    1126                              TRUE /* aCancelable */);
    1127 
    1128     else if (aLocInfo.storageType == VFSType_Cloud)
    1129         /* 1 operation only for now */
    1130         rc = aProgress->init(mVirtualBox, static_cast<IAppliance*>(this),
    1131                              "Getting cloud instance information...",
    1132                              TRUE /* aCancelable */);
    1133     else
    1134         /* 4/5 is downloading, 1/5 is reading */
    1135         rc = aProgress->init(mVirtualBox, static_cast<IAppliance*>(this),
    1136                              bstrDesc.raw(),
    1137                              TRUE /* aCancelable */,
    1138                              2, // ULONG cOperations,
    1139                              5, // ULONG ulTotalOperationsWeight,
    1140                              BstrFmt(tr("Download appliance '%s'"),
    1141                                      aLocInfo.strPath.c_str()).raw(), // CBSTR bstrFirstOperationDescription,
    1142                              4); // ULONG ulFirstOperationWeight,
    1143     if (FAILED(rc)) throw rc;
    1144 
    1145     /* Initialize our worker task */
    1146     TaskOVF *ovfTask = NULL;
    1147     TaskCloud *cloudTask = NULL;
    11481126    try
    11491127    {
    1150         if (aLocInfo.storageType == VFSType_File)
    1151         {
    1152             ovfTask = new TaskOVF(this, TaskOVF::Read, aLocInfo, aProgress);
    1153             rc = ovfTask->createThread();
    1154             if (FAILED(rc)) throw rc;
    1155         }
    1156         else if (aLocInfo.storageType == VFSType_Cloud)
    1157         {
    1158             cloudTask = new TaskCloud(this, TaskCloud::ReadData, aLocInfo, aProgress);
    1159             rc = cloudTask->createThread();
    1160             if (FAILED(rc)) throw rc;
    1161         }
    1162     }
    1163     catch (HRESULT aRc)
    1164     {
    1165         rc = aRc;
    1166     }
    1167     catch (...)
    1168     {
    1169         rc = setError(VBOX_E_OBJECT_NOT_FOUND,
    1170                       tr("Could not create a task object for reading the Appliance data"));
    1171     }
    1172 
    1173     if (FAILED(rc))
    1174     {
    1175         if (ovfTask)
    1176             delete ovfTask;
    1177         if (cloudTask)
    1178             delete cloudTask;
    1179         throw rc;
    1180     }
     1128        if (aLocInfo.storageType == VFSType_Cloud)
     1129            /* 1 operation only */
     1130            hrc = aProgress->init(mVirtualBox, static_cast<IAppliance*>(this),
     1131                                  Utf8Str(tr("Getting cloud instance information...")), TRUE /* aCancelable */);
     1132        else
     1133        {
     1134            Utf8StrFmt strDesc(tr("Reading appliance '%s'"), aLocInfo.strPath.c_str());
     1135            if (aLocInfo.storageType == VFSType_File)
     1136                /* 1 operation only */
     1137                hrc = aProgress->init(mVirtualBox, static_cast<IAppliance*>(this), strDesc, TRUE /* aCancelable */);
     1138            else
     1139                /* 4/5 is downloading, 1/5 is reading */
     1140                hrc = aProgress->init(mVirtualBox, static_cast<IAppliance*>(this), strDesc, TRUE /* aCancelable */,
     1141                                      2, // ULONG cOperations,
     1142                                      5, // ULONG ulTotalOperationsWeight,
     1143                                      Utf8StrFmt(tr("Download appliance '%s'"),
     1144                                                 aLocInfo.strPath.c_str()).raw(), // CBSTR bstrFirstOperationDescription,
     1145                                      4); // ULONG ulFirstOperationWeight,
     1146        }
     1147    }
     1148    catch (std::bad_alloc &) /* Utf8Str/Utf8StrFmt */
     1149    {
     1150        return E_OUTOFMEMORY;
     1151    }
     1152    if (FAILED(hrc))
     1153        return hrc;
     1154
     1155    /*
     1156     * Initialize the worker task.
     1157     */
     1158    ThreadTask *pTask;
     1159    try
     1160    {
     1161        if (aLocInfo.storageType == VFSType_Cloud)
     1162            pTask = new TaskCloud(this, TaskCloud::ReadData, aLocInfo, aProgress);
     1163        else
     1164            pTask = new TaskOVF(this, TaskOVF::Read, aLocInfo, aProgress);
     1165    }
     1166    catch (std::bad_alloc &)
     1167    {
     1168        return E_OUTOFMEMORY;
     1169    }
     1170
     1171    /*
     1172     * Kick off the worker thread.
     1173     */
     1174    hrc = pTask->createThread();
     1175    pTask = NULL; /* Note! createThread has consumed the task.*/
     1176    if (SUCCEEDED(hrc))
     1177        return hrc;
     1178    return setError(hrc, tr("Failed to create thread for reading appliance data"));
    11811179}
    11821180
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