VirtualBox

Changeset 3411 in vbox for trunk


Ignore:
Timestamp:
Jul 4, 2007 11:11:28 AM (17 years ago)
Author:
vboxsync
Message:

Main: Do not delete target hard disk images when the "clone/create VDI" operation fails because the target file already exists.

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

Legend:

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

    r3320 r3411  
    139139HRESULT HardDisk::protectedInit (VirtualBox *aVirtualBox, HardDisk *aParent)
    140140{
    141     LogFlowMember (("HardDisk::protectedInit (aParent=%p)\n", aParent));
     141    LogFlowThisFunc (("aParent=%p\n", aParent));
    142142
    143143    ComAssertRet (aVirtualBox, E_INVALIDARG);
     
    168168void HardDisk::protectedUninit (AutoLock &alock)
    169169{
    170     LogFlowMember (("HardDisk::protectedUninit()\n"));
     170    LogFlowThisFunc (("\n"));
    171171
    172172    Assert (alock.belongsTo (this));
     
    13551355                                 CFGNODE aHDNode, CFGNODE aVDINode)
    13561356{
    1357     LogFlowMember (("HVirtualDiskImage::init (load)\n"));
     1357    LogFlowThisFunc (("aHDNode=%p, aVDINode=%p\n", aHDNode, aVDINode));
    13581358
    13591359    AssertReturn (aHDNode && aVDINode, E_FAIL);
     
    13811381        CheckComRCBreakRC (rc);
    13821382
    1383         LogFlowMember ((" '%ls'\n", mFilePathFull.raw()));
     1383        LogFlowThisFunc (("'%ls'\n", mFilePathFull.raw()));
    13841384
    13851385        /* load basic settings and children */
     
    14171417                                const BSTR aFilePath, BOOL aRegistered /* = FALSE */)
    14181418{
    1419     LogFlowMember (("HVirtualDiskImage::init (aFilePath='%ls', aRegistered=%d)\n",
    1420                    aFilePath, aRegistered));
     1419    LogFlowThisFunc (("aFilePath='%ls', aRegistered=%d\n",
     1420                      aFilePath, aRegistered));
    14211421
    14221422    AutoLock alock (this);
     
    14841484void HVirtualDiskImage::uninit()
    14851485{
    1486     LogFlowMember (("HVirtualDiskImage::uninit()\n"));
     1486    LogFlowThisFunc (("\n"));
    14871487
    14881488    AutoLock alock (this);
     
    18341834/**
    18351835 *  Creates a clone of this hard disk by storing hard disk data in the given
    1836  *  VDI file name.
    1837  *
    1838  *  @param aId          UUID to assign to the created image
    1839  *  @param aTargetPath  VDI file where the cloned image is to be to stored
    1840  *  @param aProgress    progress object to run during operation
     1836 *  VDI file.
     1837 *
     1838 *  If the operation fails, @a aDeleteTarget will be set to @c true unless the
     1839 *  failure happened because the target file already existed.
     1840 *
     1841 *  @param aId              UUID to assign to the created image.
     1842 *  @param aTargetPath      VDI file where the cloned image is to be to stored.
     1843 *  @param aProgress        progress object to run during operation.
     1844 *  @param aDeleteTarget    Whether it is recommended to delete target on
     1845 *                          failure or not.
    18411846 */
    18421847HRESULT
    18431848HVirtualDiskImage::cloneToImage (const Guid &aId, const Utf8Str &aTargetPath,
    1844                                  Progress *aProgress)
    1845 {
     1849                                 Progress *aProgress, bool &aDeleteTarget)
     1850{
     1851    /* normally, the target file should be deleted on error */
     1852    aDeleteTarget = true;
     1853
    18461854    AssertReturn (!aId.isEmpty(), E_FAIL);
    18471855    AssertReturn (!aTargetPath.isNull(), E_FAIL);
     
    18721880    alock.enter();
    18731881    releaseReader();
     1882
     1883    /* We don't want to delete existing user files */
     1884    if (vrc == VERR_ALREADY_EXISTS)
     1885        aDeleteTarget = false;
    18741886
    18751887    if (VBOX_SUCCESS (vrc))
     
    20682080HRESULT HVirtualDiskImage::mergeImageToParent (Progress *aProgress)
    20692081{
    2070     LogFlowMember (("HVirtualDiskImage::mergeImageToParent(): image='%ls'\n",
    2071                     mFilePathFull.raw()));
     2082    LogFlowThisFunc (("mFilePathFull='%ls'\n", mFilePathFull.raw()));
    20722083
    20732084    AutoLock alock (this);
     
    21832194HRESULT HVirtualDiskImage::mergeImageToChildren (Progress *aProgress)
    21842195{
    2185     LogFlowMember (("HVirtualDiskImage::mergeImageToChildren(): image='%ls'\n",
    2186                     mFilePathFull.raw()));
     2196    LogFlowThisFunc (("mFilePathFull='%ls'\n", mFilePathFull.raw()));
    21872197
    21882198    AutoLock alock (this);
     
    26712681    Utf8Str errorMsg;
    26722682
     2683    bool deleteTarget = true;
     2684
    26732685    if (task->operation == VDITask::CloneToImage)
    26742686    {
     
    26782690        rc = task->source->cloneToImage (task->vdi->id(),
    26792691                                         Utf8Str (task->vdi->filePathFull()),
    2680                                          task->progress);
     2692                                         task->progress, deleteTarget);
    26812693
    26822694        /* release reader added in HardDisk::CloneToImage() */
     
    26902702                                      progressCallback,
    26912703                                      static_cast <Progress *> (task->progress));
     2704
     2705        /* We don't want to delete existing user files */
     2706        if (vrc == VERR_ALREADY_EXISTS)
     2707            deleteTarget = false;
    26922708
    26932709        if (VBOX_SUCCESS (vrc) && task->vdi->id())
     
    27332749    {
    27342750        /* delete the target file so we don't have orphaned files */
    2735         RTFileDelete(Utf8Str (task->vdi->filePathFull()));
     2751        if (deleteTarget)
     2752            RTFileDelete(Utf8Str (task->vdi->filePathFull()));
    27362753
    27372754        task->vdi->mState = HVirtualDiskImage::NotCreated;
     
    27942811                              CFGNODE aHDNode, CFGNODE aISCSINode)
    27952812{
    2796     LogFlowMember (("HISCSIHardDisk::init (load)\n"));
     2813    LogFlowThisFunc (("aHDNode=%p, aISCSINode=%p\n", aHDNode, aISCSINode));
    27972814
    27982815    AssertReturn (aHDNode && aISCSINode, E_FAIL);
     
    28272844        CFGLDRQueryBSTR (aISCSINode, "password", mPassword.asOutParam());
    28282845
    2829         LogFlowMember ((" 'iscsi:%ls:%hu@%ls/%ls:%llu'\n",
    2830                         mServer.raw(), mPort, mUserName.raw(), mTarget.raw(),
    2831                         mLun));
     2846        LogFlowThisFunc (("'iscsi:%ls:%hu@%ls/%ls:%llu'\n",
     2847                          mServer.raw(), mPort, mUserName.raw(), mTarget.raw(),
     2848                          mLun));
    28322849
    28332850        /* load basic settings and children */
     
    28602877HRESULT HISCSIHardDisk::init (VirtualBox *aVirtualBox)
    28612878{
    2862     LogFlowMember (("HISCSIHardDisk::init()\n"));
     2879    LogFlowThisFunc (("\n"));
    28632880
    28642881    AutoLock alock (this);
     
    28982915void HISCSIHardDisk::uninit()
    28992916{
    2900     LogFlowMember (("HISCSIHardDisk::uninit()\n"));
     2917    LogFlowThisFunc (("\n"));
    29012918
    29022919    AutoLock alock (this);
     
    32653282/**
    32663283 *  Creates a clone of this hard disk by storing hard disk data in the given
    3267  *  VDI file name.
    3268  *
    3269  *  @param aId          UUID to assign to the created image
    3270  *  @param aTargetPath  VDI file where the cloned image is to be to stored
    3271  *  @param aProgress    progress object to run during operation
     3284 *  VDI file.
     3285 *
     3286 *  If the operation fails, @a aDeleteTarget will be set to @c true unless the
     3287 *  failure happened because the target file already existed.
     3288 *
     3289 *  @param aId              UUID to assign to the created image.
     3290 *  @param aTargetPath      VDI file where the cloned image is to be to stored.
     3291 *  @param aProgress        progress object to run during operation.
     3292 *  @param aDeleteTarget    Whether it is recommended to delete target on
     3293 *                          failure or not.
    32723294 */
    32733295HRESULT
    32743296HISCSIHardDisk::cloneToImage (const Guid &aId, const Utf8Str &aTargetPath,
    3275                               Progress *aProgress)
     3297                              Progress *aProgress, bool &aDeleteTarget)
    32763298{
    32773299    ComAssertMsgFailed (("Not implemented"));
     
    33773399                          CFGNODE aHDNode, CFGNODE aVMDKNode)
    33783400{
    3379     LogFlowMember (("HVMDKImage::init (load)\n"));
     3401    LogFlowThisFunc (("aHDNode=%p, aVMDKNode=%p\n", aHDNode, aVMDKNode));
    33803402
    33813403    AssertReturn (aHDNode && aVMDKNode, E_FAIL);
     
    34033425        CheckComRCBreakRC (rc);
    34043426
    3405         LogFlowMember ((" '%ls'\n", mFilePathFull.raw()));
     3427        LogFlowThisFunc (("'%ls'\n", mFilePathFull.raw()));
    34063428
    34073429        /* load basic settings and children */
     
    34483470                          const BSTR aFilePath, BOOL aRegistered /* = FALSE */)
    34493471{
    3450     LogFlowMember (("HVMDKImage::init (aFilePath='%ls', aRegistered=%d)\n",
    3451                     aFilePath, aRegistered));
     3472    LogFlowThisFunc (("aFilePath='%ls', aRegistered=%d\n", aFilePath, aRegistered));
    34523473
    34533474    AssertReturn (aParent == NULL, E_FAIL);
     
    35203541void HVMDKImage::uninit()
    35213542{
    3522     LogFlowMember (("HVMDKImage::uninit()\n"));
     3543    LogFlowThisFunc (("\n"));
    35233544
    35243545    AutoLock alock (this);
     
    38863907/**
    38873908 *  Creates a clone of this hard disk by storing hard disk data in the given
    3888  *  VDI file name.
    3889  *
    3890  *  @param aId          UUID to assign to the created image
    3891  *  @param aTargetPath  VDI file where the cloned image is to be to stored
    3892  *  @param aProgress    progress object to run during operation
     3909 *  VDI file.
     3910 *
     3911 *  If the operation fails, @a aDeleteTarget will be set to @c true unless the
     3912 *  failure happened because the target file already existed.
     3913 *
     3914 *  @param aId              UUID to assign to the created image.
     3915 *  @param aTargetPath      VDI file where the cloned image is to be to stored.
     3916 *  @param aProgress        progress object to run during operation.
     3917 *  @param aDeleteTarget    Whether it is recommended to delete target on
     3918 *                          failure or not.
    38933919 */
    38943920HRESULT
    38953921HVMDKImage::cloneToImage (const Guid &aId, const Utf8Str &aTargetPath,
    3896                           Progress *aProgress)
     3922                          Progress *aProgress, bool &aDeleteTarget)
    38973923{
    38983924    ComAssertMsgFailed (("Not implemented"));
  • trunk/src/VBox/Main/include/HardDiskImpl.h

    r3317 r3411  
    146146
    147147    virtual HRESULT cloneToImage (const Guid &aId, const Utf8Str &aTargetPath,
    148                                   Progress *aProgress) = 0;
     148                                  Progress *aProgress, bool &aDeleteTarget) = 0;
    149149    virtual HRESULT createDiffImage (const Guid &aId, const Utf8Str &aTargetPath,
    150150                                     Progress *aProgress) = 0;
     
    274274
    275275    HRESULT cloneToImage (const Guid &aId, const Utf8Str &aTargetPath,
    276                           Progress *aProgress);
     276                          Progress *aProgress, bool &aDeleteTarget);
    277277    HRESULT createDiffImage (const Guid &aId, const Utf8Str &aTargetPath,
    278278                             Progress *aProgress);
     
    403403
    404404    HRESULT cloneToImage (const Guid &aId, const Utf8Str &aTargetPath,
    405                           Progress *aProgress);
     405                          Progress *aProgress, bool &aDeleteTarget);
    406406    HRESULT createDiffImage (const Guid &aId, const Utf8Str &aTargetPath,
    407407                             Progress *aProgress);
     
    495495
    496496    HRESULT cloneToImage (const Guid &aId, const Utf8Str &aTargetPath,
    497                           Progress *aProgress);
     497                          Progress *aProgress, bool &aDeleteTarget);
    498498    HRESULT createDiffImage (const Guid &aId, const Utf8Str &aTargetPath,
    499499                             Progress *aProgress);
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