VirtualBox

Changeset 17829 in vbox


Ignore:
Timestamp:
Mar 13, 2009 2:42:18 PM (16 years ago)
Author:
vboxsync
Message:

OVF: clean up target disk after export error

File:
1 edited

Legend:

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

    r17827 r17829  
    29052905            if (strTargetFilePath.endsWith(".vmdk", Utf8Str::CaseInsensitive))
    29062906                bstrSrcFormat = L"VMDK";
    2907             /* Create a new hard disk interface for the destination disk image */
     2907
     2908            // create a new hard disk interface for the destination disk image
    29082909            Log(("Creating target disk \"%s\"\n", strTargetFilePath.raw()));
    29092910            rc = pVirtualBox->CreateHardDisk(bstrSrcFormat, Bstr(strTargetFilePath), pTargetDisk.asOutParam());
    29102911            if (FAILED(rc)) throw rc;
    2911             // clone the source disk image
    2912             rc = pSourceDisk->CloneTo(pTargetDisk, HardDiskVariant_Standard, pProgress2.asOutParam());
    2913             if (FAILED(rc)) throw rc;
    2914 
    2915             // advance to the next operation
    2916             if (!task->progress.isNull())
    2917                 task->progress->advanceOperation(BstrFmt(tr("Exporting virtual disk image '%s'"), strSrcFilePath.c_str()));
    2918 
    2919             // now loop until the asynchronous operation completes and then
    2920             // report its result
    2921             BOOL fCompleted;
    2922             LONG currentPercent;
    2923             while (SUCCEEDED(pProgress2->COMGETTER(Completed(&fCompleted))))
     2912
     2913            // the target disk is now registered and needs to be removed again,
     2914            // both after successful cloning or if anything goes bad!
     2915            try
    29242916            {
    2925                 rc = pProgress2->COMGETTER(Percent(&currentPercent));
     2917                // clone the source disk image
     2918                rc = pSourceDisk->CloneTo(pTargetDisk, HardDiskVariant_Standard, pProgress2.asOutParam());
    29262919                if (FAILED(rc)) throw rc;
     2920
     2921                // advance to the next operation
    29272922                if (!task->progress.isNull())
    2928                     task->progress->notifyProgress(currentPercent);
    2929                 if (fCompleted)
    2930                     break;
    2931                 // make sure the loop is not too tight
    2932                 rc = pProgress2->WaitForCompletion(100);
     2923                    task->progress->advanceOperation(BstrFmt(tr("Exporting virtual disk image '%s'"), strSrcFilePath.c_str()));
     2924
     2925                // now loop until the asynchronous operation completes and then
     2926                // report its result
     2927                BOOL fCompleted;
     2928                LONG currentPercent;
     2929                while (SUCCEEDED(pProgress2->COMGETTER(Completed(&fCompleted))))
     2930                {
     2931                    rc = pProgress2->COMGETTER(Percent(&currentPercent));
     2932                    if (FAILED(rc)) throw rc;
     2933                    if (!task->progress.isNull())
     2934                        task->progress->notifyProgress(currentPercent);
     2935                    if (fCompleted)
     2936                        break;
     2937                    // make sure the loop is not too tight
     2938                    rc = pProgress2->WaitForCompletion(100);
     2939                    if (FAILED(rc)) throw rc;
     2940                }
     2941
     2942                // report result of asynchronous operation
     2943                HRESULT vrc;
     2944                rc = pProgress2->COMGETTER(ResultCode)(&vrc);
    29332945                if (FAILED(rc)) throw rc;
     2946
     2947                // if the thread of the progress object has an error, then
     2948                // retrieve the error info from there, or it'll be lost
     2949                if (FAILED(vrc))
     2950                {
     2951                    ProgressErrorInfo info(pProgress2);
     2952                    Utf8Str str(info.getText());
     2953                    const char *pcsz = str.c_str();
     2954                    HRESULT rc2 = setError(vrc, pcsz);
     2955                    throw rc2;
     2956                }
    29342957            }
    2935             // report result of asynchronous operation
    2936             HRESULT vrc;
    2937             rc = pProgress2->COMGETTER(ResultCode)(&vrc);
    2938             if (FAILED(rc)) throw rc;
    2939 
    2940             // if the thread of the progress object has an error, then
    2941             // retrieve the error info from there, or it'll be lost
    2942             if (FAILED(vrc))
     2958            catch (HRESULT rc3)
    29432959            {
    2944                 ProgressErrorInfo info(pProgress2);
    2945                 Utf8Str str(info.getText());
    2946                 const char *pcsz = str.c_str();
    2947                 HRESULT rc2 = setError(vrc, pcsz);
    2948                 throw rc2;
     2960                // upon error after registereing, close the disk or
     2961                // it'll stick in the registry forever
     2962                pTargetDisk->Close();
     2963                throw rc3;
    29492964            }
    29502965
    2951             /* Make sure the target disk get detached */
    2952             rc = pTargetDisk->Close();          // @todo  close this also if an error is thrown above
     2966            // upon success, close the disk as well
     2967            rc = pTargetDisk->Close();
    29532968            if (FAILED(rc)) throw rc;
    29542969
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