VirtualBox

Changeset 18814 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Apr 7, 2009 12:31:20 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
45810
Message:

Frontends/VBoxManage: when opening media try it with the client's idea of the current directory too. Helps with unexpected behavior of the API. Also separate iprt/com error variables.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp

    r18759 r18814  
    3333#include <iprt/asm.h>
    3434#include <iprt/file.h>
     35#include <iprt/path.h>
     36#include <iprt/param.h>
    3537#include <iprt/stream.h>
    3638#include <iprt/string.h>
     
    172174{
    173175    HRESULT rc;
     176    int vrc;
    174177    Bstr filename;
    175178    uint64_t sizeMB = 0;
     
    210213
    211214            case 'm':   // --variant
    212                 rc = parseDiskVariant(ValueUnion.psz, &DiskVariant);
    213                 if (RT_FAILURE(rc))
     215                vrc = parseDiskVariant(ValueUnion.psz, &DiskVariant);
     216                if (RT_FAILURE(vrc))
    214217                    return errorArgument("Invalid hard disk variant '%s'", ValueUnion.psz);
    215218                break;
     
    224227
    225228            case 't':   // --type
    226                 rc = parseDiskType(ValueUnion.psz, &DiskType);
    227                 if (    RT_FAILURE(rc)
     229                vrc = parseDiskType(ValueUnion.psz, &DiskType);
     230                if (    RT_FAILURE(vrc)
    228231                    ||  (DiskType != HardDiskType_Normal && DiskType != HardDiskType_Writethrough))
    229232                    return errorArgument("Invalid hard disk type '%s'", ValueUnion.psz);
     
    340343{
    341344    HRESULT rc;
     345    int vrc;
    342346    ComPtr<IHardDisk> hardDisk;
    343347    HardDiskType_T DiskType;
     
    356360        {
    357361            case 't':   // --type
    358                 rc = parseDiskType(ValueUnion.psz, &DiskType);
    359                 if (RT_FAILURE(rc))
     362                vrc = parseDiskType(ValueUnion.psz, &DiskType);
     363                if (RT_FAILURE(vrc))
    360364                    return errorArgument("Invalid hard disk type '%s'", ValueUnion.psz);
    361365                fModifyDiskType = true;
     
    363367
    364368            case 'z':   // --autoreset
    365                 rc = parseBool(ValueUnion.psz, &AutoReset);
    366                 if (RT_FAILURE(rc))
     369                vrc = parseBool(ValueUnion.psz, &AutoReset);
     370                if (RT_FAILURE(vrc))
    367371                    return errorArgument("Invalid autoreset parameter '%s'", ValueUnion.psz);
    368372                fModifyAutoReset = true;
     
    474478int handleCloneHardDisk(HandlerArg *a)
    475479{
     480    HRESULT rc;
     481    int vrc;
    476482    Bstr src, dst;
    477483    Bstr format;
     
    479485    bool fRemember = false;
    480486    HardDiskType_T DiskType = HardDiskType_Normal;
    481 
    482     HRESULT rc;
    483487
    484488    int c;
     
    496500
    497501            case 'm':   // --variant
    498                 rc = parseDiskVariant(ValueUnion.psz, &DiskVariant);
    499                 if (RT_FAILURE(rc))
     502                vrc = parseDiskVariant(ValueUnion.psz, &DiskVariant);
     503                if (RT_FAILURE(vrc))
    500504                    return errorArgument("Invalid hard disk variant '%s'", ValueUnion.psz);
    501505                break;
     
    506510
    507511            case 't':   // --type
    508                 rc = parseDiskType(ValueUnion.psz, &DiskType);
    509                 if (RT_FAILURE(rc))
     512                vrc = parseDiskType(ValueUnion.psz, &DiskType);
     513                if (RT_FAILURE(vrc))
    510514                    return errorArgument("Invalid hard disk type '%s'", ValueUnion.psz);
    511515                break;
     
    829833{
    830834    HRESULT rc;
     835    int vrc;
    831836    Bstr server;
    832837    Bstr target;
     
    877882
    878883            case 't':   // --type
    879                 rc = parseDiskType(ValueUnion.psz, &DiskType);
    880                 if (RT_FAILURE(rc))
     884                vrc = parseDiskType(ValueUnion.psz, &DiskType);
     885                if (RT_FAILURE(vrc))
    881886                    return errorArgument("Invalid hard disk type '%s'", ValueUnion.psz);
    882887                break;
     
    11711176{
    11721177    HRESULT rc = S_OK;
     1178    int vrc;
    11731179    enum {
    11741180        CMD_NONE,
     
    12091215
    12101216            case 't':   // --type
    1211                 rc = parseDiskType(ValueUnion.psz, &DiskType);
    1212                 if (RT_FAILURE(rc))
     1217                vrc = parseDiskType(ValueUnion.psz, &DiskType);
     1218                if (RT_FAILURE(vrc))
    12131219                    return errorArgument("Invalid hard disk type '%s'", ValueUnion.psz);
    12141220                fDiskType = true;
     
    12451251        return errorSyntax(USAGE_OPENMEDIUM, "Disk name required");
    12461252
     1253    /** @todo remove this hack!
     1254     * First try opening the image as is (using the regular API semantics for
     1255     * images with relative path or without path), and if that fails with a
     1256     * file related error then try it again with what the client thinks the
     1257     * relative path would mean. Requires doing the command twice in certain
     1258     * cases. This is an ugly hack and needs to be removed whevever we have a
     1259     * chance to clean up the API semantics. */
    12471260    if (cmd == CMD_DISK)
    12481261    {
    12491262        ComPtr<IHardDisk> hardDisk;
    1250         CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(Filename), AccessMode_ReadWrite, hardDisk.asOutParam()));
     1263        rc = a->virtualBox->OpenHardDisk(Bstr(Filename), AccessMode_ReadWrite, hardDisk.asOutParam());
     1264        if (rc == VBOX_E_FILE_ERROR)
     1265        {
     1266            char szFilenameAbs[RTPATH_MAX] = "";
     1267            int vrc = RTPathAbs(Filename, szFilenameAbs, sizeof(szFilenameAbs));
     1268            if (RT_FAILURE(vrc))
     1269            {
     1270                RTPrintf("Cannot convert filename \"%s\" to absolute path\n", Filename);
     1271                return 1;
     1272            }
     1273            CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(szFilenameAbs), AccessMode_ReadWrite, hardDisk.asOutParam()));
     1274        }
     1275        else
     1276            CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(Filename), AccessMode_ReadWrite, hardDisk.asOutParam()));
    12511277        if (SUCCEEDED(rc) && hardDisk)
    12521278        {
     
    12631289            return errorSyntax(USAGE_OPENMEDIUM, "Invalid option for DVD images");
    12641290        ComPtr<IDVDImage> dvdImage;
    1265         CHECK_ERROR(a->virtualBox, OpenDVDImage(Bstr(Filename), Guid(), dvdImage.asOutParam()));
     1291        rc = a->virtualBox->OpenDVDImage(Bstr(Filename), Guid(), dvdImage.asOutParam());
     1292        if (rc == VBOX_E_FILE_ERROR)
     1293        {
     1294            char szFilenameAbs[RTPATH_MAX] = "";
     1295            int vrc = RTPathAbs(Filename, szFilenameAbs, sizeof(szFilenameAbs));
     1296            if (RT_FAILURE(vrc))
     1297            {
     1298                RTPrintf("Cannot convert filename \"%s\" to absolute path\n", Filename);
     1299                return 1;
     1300            }
     1301            CHECK_ERROR(a->virtualBox, OpenDVDImage(Bstr(szFilenameAbs), Guid(), dvdImage.asOutParam()));
     1302        }
     1303        else
     1304            CHECK_ERROR(a->virtualBox, OpenDVDImage(Bstr(Filename), Guid(), dvdImage.asOutParam()));
    12661305    }
    12671306    else if (cmd == CMD_FLOPPY)
     
    12701309            return errorSyntax(USAGE_OPENMEDIUM, "Invalid option for DVD images");
    12711310        ComPtr<IFloppyImage> floppyImage;
    1272         CHECK_ERROR(a->virtualBox, OpenFloppyImage(Bstr(Filename), Guid(), floppyImage.asOutParam()));
     1311         rc = a->virtualBox->OpenFloppyImage(Bstr(Filename), Guid(), floppyImage.asOutParam());
     1312        if (rc == VBOX_E_FILE_ERROR)
     1313        {
     1314            char szFilenameAbs[RTPATH_MAX] = "";
     1315            int vrc = RTPathAbs(Filename, szFilenameAbs, sizeof(szFilenameAbs));
     1316            if (RT_FAILURE(vrc))
     1317            {
     1318                RTPrintf("Cannot convert filename \"%s\" to absolute path\n", Filename);
     1319                return 1;
     1320            }
     1321            CHECK_ERROR(a->virtualBox, OpenFloppyImage(Bstr(szFilenameAbs), Guid(), floppyImage.asOutParam()));
     1322        }
     1323        else
     1324            CHECK_ERROR(a->virtualBox, OpenFloppyImage(Bstr(Filename), Guid(), floppyImage.asOutParam()));
    12731325    }
    12741326
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