VirtualBox

Changeset 78754 in vbox


Ignore:
Timestamp:
May 26, 2019 2:20:10 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
130841
Message:

Main/Appliance: Some cleanups of i_writeImpl and i_writeOPCImpl. Don't use BstrFmt when i_setupProgress takes a Utf8Str. Don't catch exceptions other than bad_alloc as there aren't supposed to be any other thrown. that's just misleading and confusing.

File:
1 edited

Legend:

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

    r78428 r78754  
    792792HRESULT Appliance::i_writeImpl(ovf::OVFVersion_T aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress)
    793793{
    794     HRESULT rc;
    795 
    796     rc = i_setUpProgress(aProgress,
    797                          BstrFmt(tr("Export appliance '%s'"), aLocInfo.strPath.c_str()),
    798                          (aLocInfo.storageType == VFSType_File) ? WriteFile : WriteS3);
    799     if (FAILED(rc))
    800         return rc;
    801 
    802     /* Initialize our worker task */
    803     TaskOVF* task = NULL;
     794    /* Prepare progress object: */
     795    HRESULT hrc;
    804796    try
    805797    {
    806         task = new TaskOVF(this, TaskOVF::Write, aLocInfo, aProgress);
    807     }
    808     catch(...)
    809     {
    810         return setError(VBOX_E_OBJECT_NOT_FOUND,
    811                         tr("Could not create TaskOVF object for for writing out the OVF to disk"));
    812     }
    813 
    814     /* The OVF version to write */
    815     task->enFormat = aFormat;
    816 
    817     rc = task->createThread();
    818 
    819     return rc;
     798        hrc = i_setUpProgress(aProgress,
     799                              Utf8StrFmt(tr("Export appliance '%s'"), aLocInfo.strPath.c_str()),
     800                              aLocInfo.storageType == VFSType_File ? WriteFile : WriteS3);
     801    }
     802    catch (std::bad_alloc &) /* only Utf8StrFmt */
     803    {
     804        hrc = E_OUTOFMEMORY;
     805    }
     806    if (SUCCEEDED(hrc))
     807    {
     808        /* Create our worker task: */
     809        TaskOVF *pTask = NULL;
     810        try
     811        {
     812            pTask = new TaskOVF(this, TaskOVF::Write, aLocInfo, aProgress);
     813        }
     814        catch (std::bad_alloc &)
     815        {
     816            return E_OUTOFMEMORY;
     817        }
     818
     819        /* The OVF version to produce: */
     820        pTask->enFormat = aFormat;
     821
     822        /* Start the thread: */
     823        hrc = pTask->createThread();
     824        pTask = NULL;
     825    }
     826    return hrc;
    820827}
    821828
     
    916923HRESULT Appliance::i_writeOPCImpl(ovf::OVFVersion_T aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress)
    917924{
    918     HRESULT rc;
    919925    RT_NOREF(aFormat);
    920926
    921     rc = i_setUpProgress(aProgress,
    922                          BstrFmt(tr("Export appliance '%s'"), aLocInfo.strPath.c_str()),
    923                          (aLocInfo.storageType == VFSType_File) ? WriteFile : WriteS3);
    924     if (FAILED(rc))
    925         return rc;
    926 
    927     /* Initialize our worker task */
    928     TaskOPC* task = NULL;
     927    /* Prepare progress object: */
     928    HRESULT hrc;
    929929    try
    930930    {
    931         task = new Appliance::TaskOPC(this, TaskOPC::Export, aLocInfo, aProgress);
    932     }
    933     catch(...)
    934     {
    935         return setError(VBOX_E_OBJECT_NOT_FOUND,
    936                         tr("Could not create TaskOPC object for for writing out the OPC to disk"));
    937     }
    938 
    939     rc = task->createThread();
    940 
    941     return rc;
     931        hrc = i_setUpProgress(aProgress,
     932                              Utf8StrFmt(tr("Export appliance '%s'"), aLocInfo.strPath.c_str()),
     933                              aLocInfo.storageType == VFSType_File ? WriteFile : WriteS3);
     934    }
     935    catch (std::bad_alloc &) /* only Utf8StrFmt */
     936    {
     937        hrc = E_OUTOFMEMORY;
     938    }
     939    if (SUCCEEDED(hrc))
     940    {
     941        /* Create our worker task: */
     942        TaskOPC *pTask = NULL;
     943        try
     944        {
     945            pTask = new Appliance::TaskOPC(this, TaskOPC::Export, aLocInfo, aProgress);
     946        }
     947        catch (std::bad_alloc &)
     948        {
     949            return E_OUTOFMEMORY;
     950        }
     951
     952        /* Kick it off: */
     953        hrc = pTask->createThread();
     954        pTask = NULL;
     955    }
     956    return hrc;
    942957}
    943958
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