VirtualBox

Ignore:
Timestamp:
Apr 1, 2008 5:50:08 PM (17 years ago)
Author:
vboxsync
Message:

Integrate contributed code to rename a VDI file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Storage/VDIHDDCore.cpp

    r7652 r7689  
    849849{
    850850    LogFlowFunc(("pBackendData=%#p pszFilename=%#p\n", pBackendData, pszFilename));
    851     int rc = VERR_NOT_IMPLEMENTED;
    852 
     851
     852    int rc = VINF_SUCCESS;
     853    PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
     854
     855    /* Check arguments. */
     856    if (   !pImage
     857        || !pszFilename
     858        || !*pszFilename)
     859    {
     860        rc = VERR_INVALID_PARAMETER;
     861        goto out;
     862    }
     863
     864    /* Close the image. */
     865    vdiFreeImage(pImage, false);
     866
     867    /* Rename the file. */
     868    rc = RTFileMove(pImage->pszFilename, pszFilename, 0);
     869    if (VBOX_FAILURE(rc))
     870    {   
     871        /* The move failed, try to reopen the original image. */
     872        int rc2 = vdiOpenImage(pImage, pImage->uOpenFlags);
     873        if (VBOX_FAILURE(rc2))
     874            rc = rc2;
     875
     876        goto out;
     877    }
     878
     879    /* Update pImage with the new information. */
     880    pImage->pszFilename = pszFilename;
     881
     882    /* Open the new image. */
     883    rc = vdiOpenImage(pImage, pImage->uOpenFlags);
     884    if (VBOX_FAILURE(rc))
     885        goto out;
     886
     887out:
    853888    LogFlowFunc(("returns %Vrc\n", rc));
    854889    return rc;
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