VirtualBox

Changeset 6457 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Jan 22, 2008 11:14:34 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
27438
Message:

Fix error message handling

File:
1 edited

Legend:

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

    r6367 r6457  
    48814881    mLastVDError.setNull();
    48824882
    4883     do
    4884     {
    4885         Guid id, parentId;
    4886 
    4887         vrc = VDOpen (mContainer, location, VD_OPEN_FLAGS_INFO);
     4883    Guid id, parentId;
     4884
     4885    vrc = VDOpen (mContainer, location, VD_OPEN_FLAGS_INFO);
     4886    if (VBOX_FAILURE (vrc))
     4887        goto error;
     4888
     4889    vrc = VDGetUuid (mContainer, 0, id.ptr());
     4890    if (VBOX_FAILURE (vrc))
     4891        goto error;
     4892    vrc = VDGetParentUuid (mContainer, 0, parentId.ptr());
     4893    if (VBOX_FAILURE (vrc))
     4894        goto error;
     4895
     4896    if (!mId.isEmpty())
     4897    {
     4898        /* check that the actual UUID of the image matches the stored UUID */
     4899        if (mId != id)
     4900        {
     4901            errMsg = Utf8StrFmt (
     4902                tr ("Actual UUID {%Vuuid} of the hard disk image '%s' doesn't "
     4903                    "match UUID {%Vuuid} stored in the registry"),
     4904                    id.ptr(), location.raw(), mId.ptr());
     4905            goto error;
     4906        }
     4907    }
     4908    else
     4909    {
     4910        /* assgn an UUID read from the image file */
     4911        mId = id;
     4912    }
     4913
     4914    if (mParent)
     4915    {
     4916        /* check parent UUID */
     4917        AutoLock parentLock (mParent);
     4918        if (mParent->id() != parentId)
     4919        {
     4920            errMsg = Utf8StrFmt (
     4921                tr ("UUID {%Vuuid} of the parent image '%ls' stored in "
     4922                    "the hard disk image file '%s' doesn't match "
     4923                    "UUID {%Vuuid} stored in the registry"),
     4924                parentId.raw(), mParent->toString().raw(),
     4925                location.raw(), mParent->id().raw());
     4926            goto error;
     4927        }
     4928    }
     4929    else if (!parentId.isEmpty())
     4930    {
     4931        errMsg = Utf8StrFmt (
     4932            tr ("Hard disk image '%s' is a differencing image that is linked "
     4933                "to a hard disk with UUID {%Vuuid} and cannot be used "
     4934                "directly as a base hard disk"),
     4935            location.raw(), parentId.raw());
     4936        goto error;
     4937    }
     4938
     4939    /* get actual file size */
     4940    /// @todo is there a direct method in RT?
     4941    {
     4942        RTFILE file = NIL_RTFILE;
     4943        vrc = RTFileOpen (&file, location, RTFILE_O_READ);
     4944        if (VBOX_SUCCESS (vrc))
     4945        {
     4946            uint64_t size = 0;
     4947            vrc = RTFileGetSize (file, &size);
     4948            if (VBOX_SUCCESS (vrc))
     4949                mActualSize = size;
     4950            RTFileClose (file);
     4951        }
    48884952        if (VBOX_FAILURE (vrc))
    4889             break;
    4890 
    4891         vrc = VDGetUuid (mContainer, 0, id.ptr());
    4892         if (VBOX_FAILURE (vrc))
    4893             break;
    4894         vrc = VDGetParentUuid (mContainer, 0, parentId.ptr());
    4895         if (VBOX_FAILURE (vrc))
    4896             break;
    4897 
    4898         if (!mId.isEmpty())
    4899         {
    4900             /* check that the actual UUID of the image matches the stored UUID */
    4901             if (mId != id)
    4902             {
    4903                 errMsg = Utf8StrFmt (
    4904                     tr ("Actual UUID {%Vuuid} of the hard disk image '%s' doesn't "
    4905                         "match UUID {%Vuuid} stored in the registry"),
    4906                         id.ptr(), location.raw(), mId.ptr());
    4907                 break;
    4908             }
    4909         }
    4910         else
    4911         {
    4912             /* assgn an UUID read from the image file */
    4913             mId = id;
    4914         }
    4915 
    4916         if (mParent)
    4917         {
    4918             /* check parent UUID */
    4919             AutoLock parentLock (mParent);
    4920             if (mParent->id() != parentId)
    4921             {
    4922                 errMsg = Utf8StrFmt (
    4923                     tr ("UUID {%Vuuid} of the parent image '%ls' stored in "
    4924                         "the hard disk image file '%s' doesn't match "
    4925                         "UUID {%Vuuid} stored in the registry"),
    4926                     parentId.raw(), mParent->toString().raw(),
    4927                     location.raw(), mParent->id().raw());
    4928                 break;
    4929             }
    4930         }
    4931         else if (!parentId.isEmpty())
    4932         {
    4933             errMsg = Utf8StrFmt (
    4934                 tr ("Hard disk image '%s' is a differencing image that is linked "
    4935                     "to a hard disk with UUID {%Vuuid} and cannot be used "
    4936                     "directly as a base hard disk"),
    4937                 location.raw(), parentId.raw());
    4938             break;
    4939         }
    4940 
    4941         /* get actual file size */
    4942         /// @todo is there a direct method in RT?
    4943         {
    4944             RTFILE file = NIL_RTFILE;
    4945             vrc = RTFileOpen (&file, location, RTFILE_O_READ);
    4946             if (VBOX_SUCCESS (vrc))
    4947             {
    4948                 uint64_t size = 0;
    4949                 vrc = RTFileGetSize (file, &size);
    4950                 if (VBOX_SUCCESS (vrc))
    4951                     mActualSize = size;
    4952                 RTFileClose (file);
    4953             }
    4954             if (VBOX_FAILURE (vrc))
    4955                 break;
    4956         }
    4957 
    4958         /* query logical size only for non-differencing images */
    4959         if (!mParent)
    4960         {
    4961             uint64_t size = VDGetSize (mContainer, 0);
    4962             /* convert to MBytes */
    4963             mSize = size / 1024 / 1024;
    4964         }
    4965     }
    4966     while (0);
    4967 
     4953            goto error;
     4954    }
     4955
     4956    /* query logical size only for non-differencing images */
     4957    if (!mParent)
     4958    {
     4959        uint64_t size = VDGetSize (mContainer, 0);
     4960        /* convert to MBytes */
     4961        mSize = size / 1024 / 1024;
     4962    }
     4963
     4964error:
    49684965    VDCloseAll (mContainer);
    49694966
     
    50505047
    50515048    /// @todo pass the error message to the operation initiator
    5052     Utf8Str err = Utf8StrFmt (pszFormat, va);
     5049    Utf8Str err = Utf8StrFmtVA (pszFormat, va);
    50535050    if (VBOX_FAILURE (rc))
    50545051        err = Utf8StrFmt ("%s (%Vrc)", err.raw(), rc);
     
    59205917
    59215918    /// @todo pass the error message to the operation initiator
    5922     Utf8Str err = Utf8StrFmt (pszFormat, va);
     5919    Utf8Str err = Utf8StrFmtVA (pszFormat, va);
    59235920    if (VBOX_FAILURE (rc))
    59245921        err = Utf8StrFmt ("%s (%Vrc)", err.raw(), rc);
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