VirtualBox

Changeset 33232 in vbox for trunk/src


Ignore:
Timestamp:
Oct 19, 2010 2:24:46 PM (14 years ago)
Author:
vboxsync
Message:

Main: use paths relative to machine folder in machine registries

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

Legend:

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

    r33102 r33232  
    17761776            // source path: where the VBox image is
    17771777            const Utf8Str &strSrcFilePath = pDiskEntry->strVboxCurrent;
    1778             Bstr bstrSrcFilePath(strSrcFilePath);
    17791778
    17801779            // Do NOT check here whether the file exists. findHardDisk will
     
    17851784            ComObjPtr<Medium> pSourceDisk;
    17861785
    1787             Log(("Finding source disk \"%ls\"\n", bstrSrcFilePath.raw()));
    1788             rc = mVirtualBox->findHardDisk(NULL, bstrSrcFilePath.raw(), true, &pSourceDisk);
     1786            Log(("Finding source disk \"%s\"\n", strSrcFilePath.c_str()));
     1787            rc = mVirtualBox->findHardDiskByLocation(strSrcFilePath, true, &pSourceDisk);
    17891788            if (FAILED(rc)) throw rc;
    17901789
  • trunk/src/VBox/Main/HostImpl.cpp

    r32932 r33232  
    16121612            {
    16131613                Medium *pCached = *itCached;
    1614                 const Utf8Str strLocationCached = pCached->getLocation();
     1614                const Utf8Str strLocationCached = pCached->getLocationFull();
    16151615                bool fFound = false;
    16161616                for (MediaList::iterator itNew = llNew.begin();
     
    16191619                {
    16201620                    Medium *pNew = *itNew;
    1621                     const Utf8Str strLocationNew = pNew->getLocation();
     1621                    const Utf8Str strLocationNew = pNew->getLocationFull();
    16221622                    if (strLocationNew == strLocationCached)
    16231623                    {
     
    16361636            {
    16371637                Medium *pNew = *itNew;
    1638                 const Utf8Str strLocationNew = pNew->getLocation();
     1638                const Utf8Str strLocationNew = pNew->getLocationFull();
    16391639                bool fFound = false;
    16401640                for (MediaList::iterator itCached = pllCached->begin();
     
    16431643                {
    16441644                    Medium *pCached = *itCached;
    1645                     const Utf8Str strLocationCached = pCached->getLocation();
     1645                    const Utf8Str strLocationCached = pCached->getLocationFull();
    16461646                    if (strLocationNew == strLocationCached)
    16471647                    {
  • trunk/src/VBox/Main/MachineImpl.cpp

    r33140 r33232  
    69286928    if (config.canHaveOwnMediaRegistry())
    69296929    {
     6930        // determine machine folder
     6931        Utf8Str strMachineFolder = getSettingsFileFull();
     6932        strMachineFolder.stripFilename();
    69306933        rc = mParent->initMedia(getId(),         // media registry ID == machine UUID
    6931                                 config.mediaRegistry);
     6934                                config.mediaRegistry,
     6935                                strMachineFolder);
    69326936        if (FAILED(rc)) return rc;
    69336937    }
     
    74087412            {
    74097413                /* find a hard disk by UUID */
    7410                 rc = mParent->findHardDisk(&dev.uuid, Utf8Str::Empty, true /* aDoSetError */, &medium);
     7414                rc = mParent->findHardDiskById(dev.uuid, true /* aDoSetError */, &medium);
    74117415                if (FAILED(rc))
    74127416                {
     
    80538057    // save machine's media registry if this is VirtualBox 4.0 or later
    80548058    if (config.canHaveOwnMediaRegistry())
     8059    {
     8060        // determine machine folder
     8061        Utf8Str strMachineFolder = getSettingsFileFull();
     8062        strMachineFolder.stripFilename();
    80558063        mParent->saveMediaRegistry(config.mediaRegistry,
    8056                                    getId());            // only media with registry ID == machine UUID
     8064                                   getId(),             // only media with registry ID == machine UUID
     8065                                   strMachineFolder);
    80578066            // this throws HRESULT
     8067    }
    80588068
    80598069    // save snapshots
     
    84108420        {
    84118421            if (pMedium->isHostDrive())
    8412                 dev.strHostDriveSrc = pMedium->getLocation();
     8422                dev.strHostDriveSrc = pMedium->getLocationFull();
    84138423            else
    84148424                dev.uuid = pMedium->getId();
  • trunk/src/VBox/Main/MediumImpl.cpp

    r33187 r33232  
    117117    MediumState_T state;
    118118    MediumVariant_T variant;
    119     Utf8Str strLocation;
    120119    Utf8Str strLocationFull;
    121120    uint64_t size;
     
    948947    if (FAILED(rc)) return rc;
    949948
    950     if (m->formatObj->getCapabilities() & MediumFormatCapabilities_File)
    951     {
    952         rc = setLocation(aLocation);
    953         if (FAILED(rc)) return rc;
    954     }
    955     else
    956     {
    957         rc = setLocation(aLocation);
    958         if (FAILED(rc)) return rc;
    959     }
     949    rc = setLocation(aLocation);
     950    if (FAILED(rc)) return rc;
    960951
    961952    if (!(m->formatObj->getCapabilities() & (   MediumFormatCapabilities_CreateFixed
     
    10851076 * @param uuidMachineRegistry The registry to which this medium should be added (global registry UUI or medium UUID).
    10861077 * @param aNode         Configuration settings.
    1087  *
    1088  * @note Locks VirtualBox for writing, the medium tree for writing.
     1078 * @param strMachineFolder The machine folder with which to resolve relative paths; if empty, then we use the VirtualBox home directory
     1079 *
     1080 * @note Locks the medium tree for writing.
    10891081 */
    10901082HRESULT Medium::init(VirtualBox *aVirtualBox,
     
    10921084                     DeviceType_T aDeviceType,
    10931085                     const Guid &uuidMachineRegistry,
    1094                      const settings::Medium &data)
     1086                     const settings::Medium &data,
     1087                     const Utf8Str &strMachineFolder)
    10951088{
    10961089    using namespace settings;
     
    11711164    }
    11721165
    1173     /* required */
    1174     rc = setLocation(data.strLocation);
     1166    // compose full path of the medium, if it's not fully qualified...
     1167    // slightly convoluted logic here. If the caller has given us a
     1168    // machine folder, then a relative path will be relative to that:
     1169    Utf8Str strFull;
     1170    if (    !strMachineFolder.isEmpty()
     1171         && !RTPathHavePath(data.strLocation.c_str()))
     1172    {
     1173        strFull = strMachineFolder;
     1174        strFull += RTPATH_DELIMITER;
     1175        strFull += data.strLocation;
     1176    }
     1177    else
     1178    {
     1179        // Otherwise use the old VirtualBox "make absolute path" logic:
     1180        rc = m->pVirtualBox->calculateFullPath(data.strLocation, strFull);
     1181        if (FAILED(rc)) return rc;
     1182    }
     1183
     1184    rc = setLocation(strFull);
    11751185    if (FAILED(rc)) return rc;
    11761186
     
    12121222                       aDeviceType,
    12131223                       uuidMachineRegistry,
    1214                        med);              // child data
     1224                       med,               // child data
     1225                       strMachineFolder);
    12151226        if (FAILED(rc)) break;
    12161227
     
    28882899
    28892900/**
    2890  * Internal method to return the medium's location. Must have caller + locking!
    2891  * @return
    2892  */
    2893 const Utf8Str& Medium::getLocation() const
    2894 {
    2895     return m->strLocation;
    2896 }
    2897 
    2898 /**
    28992901 * Internal method to return the medium's full location. Must have caller + locking!
    29002902 * @return
     
    31533155        unconst(m->strLocationFull) = newPath;
    31543156
    3155         Utf8Str path;
    3156         m->pVirtualBox->copyPathRelativeToConfig(newPath, path);
    3157         unconst(m->strLocation) = path;
    3158 
    31593157        LogFlowThisFunc(("locationFull.after='%s'\n", m->strLocationFull.c_str()));
    31603158    }
     
    32583256 *
    32593257 * @param data      Settings struct to be updated.
     3258 * @param strHardDiskFolder Folder for which paths should be relative.
    32603259 *
    32613260 * @note Locks this object, medium tree and children for reading.
    32623261 */
    3263 HRESULT Medium::saveSettings(settings::Medium &data)
     3262HRESULT Medium::saveSettings(settings::Medium &data,
     3263                             const Utf8Str &strHardDiskFolder)
    32643264{
    32653265    AutoCaller autoCaller(this);
     
    32723272
    32733273    data.uuid = m->id;
    3274     data.strLocation = m->strLocation;
     3274
     3275    // make path relative if needed
     3276    if (    !strHardDiskFolder.isEmpty()
     3277         && RTPathStartsWith(m->strLocationFull.c_str(), strHardDiskFolder.c_str())
     3278       )
     3279        data.strLocation = m->strLocationFull.substr(strHardDiskFolder.length() + 1);
     3280    else
     3281        data.strLocation = m->strLocationFull;
    32753282    data.strFormat = m->strFormat;
    32763283
     
    33093316    {
    33103317        settings::Medium med;
    3311         HRESULT rc = (*it)->saveSettings(med);
     3318        HRESULT rc = (*it)->saveSettings(med, strHardDiskFolder);
    33123319        AssertComRCReturnRC(rc);
    33133320        data.llChildren.push_back(med);
    33143321    }
    3315 
    3316     return S_OK;
    3317 }
    3318 
    3319 /**
    3320  * Compares the location of this medium to the given location.
    3321  *
    3322  * The comparison takes the location details into account. For example, if the
    3323  * location is a file in the host's filesystem, a case insensitive comparison
    3324  * will be performed for case insensitive filesystems.
    3325  *
    3326  * @param aLocation     Location to compare to (as is).
    3327  * @param aResult       Where to store the result of comparison: 0 if locations
    3328  *                      are equal, 1 if this object's location is greater than
    3329  *                      the specified location, and -1 otherwise.
    3330  */
    3331 HRESULT Medium::compareLocationTo(const Utf8Str &strLocation, int &aResult)
    3332 {
    3333     AutoCaller autoCaller(this);
    3334     AssertComRCReturnRC(autoCaller.rc());
    3335 
    3336     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    3337 
    3338     Utf8Str locationFull(m->strLocationFull);
    3339 
    3340     /// @todo NEWMEDIA delegate the comparison to the backend?
    3341 
    3342     if (m->formatObj->getCapabilities() & MediumFormatCapabilities_File)
    3343     {
    3344         Utf8Str location;
    3345 
    3346         /* For locations represented by files, append the default path if
    3347          * only the name is given, and then get the full path. */
    3348         if (!RTPathHavePath(strLocation.c_str()))
    3349         {
    3350             m->pVirtualBox->getDefaultHardDiskFolder(location);
    3351             location.append(RTPATH_DELIMITER);
    3352             location.append(strLocation);
    3353         }
    3354         else
    3355             location = strLocation;
    3356 
    3357         int vrc = m->pVirtualBox->calculateFullPath(location, location);
    3358         if (RT_FAILURE(vrc))
    3359             return setError(VBOX_E_FILE_ERROR,
    3360                             tr("Invalid medium storage file location '%s' (%Rrc)"),
    3361                             location.c_str(),
    3362                             vrc);
    3363 
    3364         aResult = RTPathCompare(locationFull.c_str(), location.c_str());
    3365     }
    3366     else
    3367         aResult = locationFull.compare(strLocation);
    33683322
    33693323    return S_OK;
     
    36043558
    36053559/**
    3606  * Sets the value of m->strLocation and calculates the value of m->strLocationFull.
    3607  *
    3608  * Treats non-FS-path locations specially, and prepends the default medium
    3609  * folder if the given location string does not contain any path information
    3610  * at all.
    3611  *
    3612  * Also, if the specified location is a file path that ends with '/' then the
    3613  * file name part will be generated by this method automatically in the format
     3560 * Sets the value of m->strLocationFull. The given location must be a fully
     3561 * qualified path; relative paths are not supported here.
     3562 *
     3563 * As a special exception, if the specified location is a file path that ends with '/'
     3564 * then the file name part will be generated by this method automatically in the format
    36143565 * '{<uuid>}.<ext>' where <uuid> is a fresh UUID that this method will generate
    36153566 * and assign to this medium, and <ext> is the default extension for this
     
    36523603        Guid id;
    36533604
    3654         Utf8Str location(aLocation);
     3605        Utf8Str locationFull(aLocation);
    36553606
    36563607        if (m->state == MediumState_NotCreated)
     
    36593610            Assert(m->formatObj->getCapabilities() & MediumFormatCapabilities_File);
    36603611
    3661             if (RTPathFilename(location.c_str()) == NULL)
     3612            if (RTPathFilename(aLocation.c_str()) == NULL)
    36623613            {
    36633614                /* no file name is given (either an empty string or ends with a
     
    36763627                id.create();
    36773628
    3678                 location = Utf8StrFmt("%s{%RTuuid}.%s",
    3679                                       location.c_str(), id.raw(), strExt.c_str());
     3629                locationFull = Utf8StrFmt("%s{%RTuuid}.%s",
     3630                                          aLocation.c_str(), id.raw(), strExt.c_str());
    36803631            }
    36813632        }
    36823633
    3683         /* append the default folder if no path is given */
    3684         if (!RTPathHavePath(location.c_str()))
    3685         {
    3686             Utf8Str tmp;
    3687             m->pVirtualBox->getDefaultHardDiskFolder(tmp);
    3688             tmp.append(RTPATH_DELIMITER);
    3689             tmp.append(location);
    3690             location = tmp;
    3691         }
    3692 
    3693         /* get the full file name */
    3694         Utf8Str locationFull;
    3695         int vrc = m->pVirtualBox->calculateFullPath(location, locationFull);
    3696         if (RT_FAILURE(vrc))
    3697             return setError(VBOX_E_FILE_ERROR,
    3698                             tr("Invalid medium storage file location '%s' (%Rrc)"),
    3699                             location.c_str(), vrc);
     3634        // we must always have full paths now
     3635        Assert(RTPathHavePath(locationFull.c_str()));
    37003636
    37013637        /* detect the backend from the storage unit if importing */
     
    37033639        {
    37043640            char *backendName = NULL;
     3641
     3642            int vrc = VINF_SUCCESS;
    37053643
    37063644            /* is it a file? */
     
    37193657            {
    37203658                /* assume it's not a file, restore the original location */
    3721                 location = locationFull = aLocation;
     3659                locationFull = aLocation;
    37223660                vrc = VDGetFormat(NULL /* pVDIfsDisk */, NULL /* pVDIfsImage */,
    37233661                                  locationFull.c_str(), &backendName);
     
    37553693        }
    37563694
     3695        m->strLocationFull = locationFull;
     3696
    37573697        /* is it still a file? */
    3758         if (m->formatObj->getCapabilities() & MediumFormatCapabilities_File)
    3759         {
    3760             m->strLocation = location;
    3761             m->strLocationFull = locationFull;
    3762 
    3763             if (m->state == MediumState_NotCreated)
    3764             {
    3765                 /* assign a new UUID (this UUID will be used when calling
    3766                  * VDCreateBase/VDCreateDiff as a wanted UUID). Note that we
    3767                  * also do that if we didn't generate it to make sure it is
    3768                  * either generated by us or reset to null */
    3769                 unconst(m->id) = id;
    3770             }
    3771         }
    3772         else
    3773         {
    3774             m->strLocation = locationFull;
    3775             m->strLocationFull = locationFull;
    3776         }
     3698        if (    (m->formatObj->getCapabilities() & MediumFormatCapabilities_File)
     3699             && (m->state == MediumState_NotCreated)
     3700           )
     3701            /* assign a new UUID (this UUID will be used when calling
     3702             * VDCreateBase/VDCreateDiff as a wanted UUID). Note that we
     3703             * also do that if we didn't generate it to make sure it is
     3704             * either generated by us or reset to null */
     3705            unconst(m->id) = id;
    37773706    }
    37783707    else
    3779     {
    3780         m->strLocation = aLocation;
    37813708        m->strLocationFull = aLocation;
    3782     }
    37833709
    37843710    return S_OK;
     
    40063932                    Guid id = parentId;
    40073933                    ComObjPtr<Medium> pParent;
    4008                     rc = m->pVirtualBox->findHardDisk(&id, Utf8Str::Empty, false /* aSetError */, &pParent);
     3934                    rc = m->pVirtualBox->findHardDiskById(id, false /* aSetError */, &pParent);
    40093935                    if (FAILED(rc))
    40103936                    {
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r33078 r33232  
    457457        /* all registered media, needed by machines */
    458458        if (FAILED(rc = initMedia(m->uuidMediaRegistry,
    459                                   m->pMainConfigFile->mediaRegistry)))
     459                                  m->pMainConfigFile->mediaRegistry,
     460                                  Utf8Str::Empty)))     // const Utf8Str &machineFolder
    460461            throw rc;
    461462
     
    608609 */
    609610HRESULT VirtualBox::initMedia(const Guid &uuidRegistry,
    610                               const settings::MediaRegistry mediaRegistry)
     611                              const settings::MediaRegistry mediaRegistry,
     612                              const Utf8Str &strMachineFolder)
    611613{
    612614    LogFlow(("VirtualBox::initMedia ENTERING, uuidRegistry=%s\n", uuidRegistry.toString().c_str()));
     
    628630                                 DeviceType_HardDisk,
    629631                                 uuidRegistry,
    630                                  xmlHD);        // XML data; this recurses to processes the children
     632                                 xmlHD,         // XML data; this recurses to processes the children
     633                                 strMachineFolder);
    631634        if (FAILED(rc)) return rc;
    632635
     
    648651                              DeviceType_DVD,
    649652                              uuidRegistry,
    650                               xmlDvd);
     653                              xmlDvd,
     654                              strMachineFolder);
    651655        if (FAILED(rc)) return rc;
    652656
     
    669673                              DeviceType_Floppy,
    670674                              uuidRegistry,
    671                               xmlFloppy);
     675                              xmlFloppy,
     676                              strMachineFolder);
    672677        if (FAILED(rc)) return rc;
    673678
     
    14791484        case DeviceType_HardDisk:
    14801485            if (!id.isEmpty())
    1481                 rc = findHardDisk(&id, Utf8Str::Empty, true /* setError */, &pMedium);
     1486                rc = findHardDiskById(id, true /* setError */, &pMedium);
    14821487            else
    1483                 rc = findHardDisk(NULL, strLocation, true /* setError */, &pMedium);
     1488                rc = findHardDiskByLocation(strLocation, true /* setError */, &pMedium);
    14841489        break;
    14851490
     
    25252530
    25262531/**
     2532 * Searches for a Medium object with the given ID in the list of registered
     2533 * hard disks.
     2534 *
     2535 * @param aId           ID of the hard disk. Must not be empty.
     2536 * @param aSetError     If @c true , the appropriate error info is set in case
     2537 *                      when the hard disk is not found.
     2538 * @param aHardDisk     Where to store the found hard disk object (can be NULL).
     2539 *
     2540 * @return S_OK, E_INVALIDARG or VBOX_E_OBJECT_NOT_FOUND when not found.
     2541 *
     2542 * @note Locks the media tree for reading.
     2543 */
     2544HRESULT VirtualBox::findHardDiskById(const Guid &id,
     2545                                     bool aSetError,
     2546                                     ComObjPtr<Medium> *aHardDisk /*= NULL*/)
     2547{
     2548    AssertReturn(!id.isEmpty(), E_INVALIDARG);
     2549
     2550    // we use the hard disks map, but it is protected by the
     2551    // hard disk _list_ lock handle
     2552    AutoReadLock alock(m->allHardDisks.getLockHandle() COMMA_LOCKVAL_SRC_POS);
     2553
     2554    HardDiskMap::const_iterator it = m->mapHardDisks.find(id);
     2555    if (it != m->mapHardDisks.end())
     2556    {
     2557        if (aHardDisk)
     2558            *aHardDisk = (*it).second;
     2559        return S_OK;
     2560    }
     2561
     2562    if (aSetError)
     2563        return setError(VBOX_E_OBJECT_NOT_FOUND,
     2564                        tr("Could not find an open hard disk with UUID {%RTuuid}"),
     2565                        id.raw());
     2566
     2567    return VBOX_E_OBJECT_NOT_FOUND;
     2568}
     2569
     2570/**
    25272571 * Searches for a Medium object with the given ID or location in the list of
    25282572 * registered hard disks. If both ID and location are specified, the first
    25292573 * object that matches either of them (not necessarily both) is returned.
    25302574 *
    2531  * @param aId           ID of the hard disk (unused when NULL).
    2532  * @param aLocation     Full location specification (unused NULL).
     2575 * @param aLocation     Full location specification. Must not be empty.
    25332576 * @param aSetError     If @c true , the appropriate error info is set in case
    25342577 *                      when the hard disk is not found.
    25352578 * @param aHardDisk     Where to store the found hard disk object (can be NULL).
    25362579 *
    2537  * @return S_OK when found or E_INVALIDARG when not found.
     2580 * @return S_OK, E_INVALIDARG or VBOX_E_OBJECT_NOT_FOUND when not found.
    25382581 *
    25392582 * @note Locks the media tree for reading.
    25402583 */
    2541 HRESULT VirtualBox::findHardDisk(const Guid *aId,
    2542                                  const Utf8Str &strLocation,
    2543                                  bool aSetError,
    2544                                  ComObjPtr<Medium> *aHardDisk /*= NULL*/)
    2545 {
    2546     AssertReturn(aId || !strLocation.isEmpty(), E_INVALIDARG);
     2584HRESULT VirtualBox::findHardDiskByLocation(const Utf8Str &strLocation,
     2585                                           bool aSetError,
     2586                                           ComObjPtr<Medium> *aHardDisk /*= NULL*/)
     2587{
     2588    AssertReturn(!strLocation.isEmpty(), E_INVALIDARG);
    25472589
    25482590    // we use the hard disks map, but it is protected by the
     
    25502592    AutoReadLock alock(m->allHardDisks.getLockHandle() COMMA_LOCKVAL_SRC_POS);
    25512593
    2552     /* first, look up by UUID in the map if UUID is provided */
    2553     if (aId)
    2554     {
    2555         HardDiskMap::const_iterator it = m->mapHardDisks.find(*aId);
    2556         if (it != m->mapHardDisks.end())
     2594    for (HardDiskMap::const_iterator it = m->mapHardDisks.begin();
     2595         it != m->mapHardDisks.end();
     2596         ++it)
     2597    {
     2598        const ComObjPtr<Medium> &pHD = (*it).second;
     2599
     2600        AutoCaller autoCaller(pHD);
     2601        if (FAILED(autoCaller.rc())) return autoCaller.rc();
     2602        AutoWriteLock mlock(pHD COMMA_LOCKVAL_SRC_POS);
     2603
     2604        Utf8Str strLocationFull = pHD->getLocationFull();
     2605
     2606        if (0 == RTPathCompare(strLocationFull.c_str(), strLocation.c_str()))
    25572607        {
    25582608            if (aHardDisk)
    2559                 *aHardDisk = (*it).second;
     2609                *aHardDisk = pHD;
    25602610            return S_OK;
    25612611        }
    25622612    }
    25632613
    2564     /* then iterate and search by location */
    2565     int result = -1;
    2566     if (!strLocation.isEmpty())
    2567     {
    2568         for (HardDiskMap::const_iterator it = m->mapHardDisks.begin();
    2569              it != m->mapHardDisks.end();
    2570              ++ it)
    2571         {
    2572             const ComObjPtr<Medium> &hd = (*it).second;
    2573 
    2574             HRESULT rc = hd->compareLocationTo(strLocation, result);
    2575             if (FAILED(rc)) return rc;
    2576 
    2577             if (result == 0)
    2578             {
    2579                 if (aHardDisk)
    2580                     *aHardDisk = hd;
    2581                 break;
    2582             }
    2583         }
    2584     }
    2585 
    2586     HRESULT rc = result == 0 ? S_OK : VBOX_E_OBJECT_NOT_FOUND;
    2587 
    2588     if (aSetError && result != 0)
    2589     {
    2590         if (aId)
    2591             setError(rc,
    2592                      tr("Could not find a hard disk with UUID {%RTuuid} in the media registry ('%s')"),
    2593                      aId->raw(),
    2594                      m->strSettingsFilePath.c_str());
    2595         else
    2596             setError(rc,
    2597                      tr("Could not find a hard disk with location '%s' in the media registry ('%s')"),
    2598                      strLocation.c_str(),
    2599                      m->strSettingsFilePath.c_str());
    2600     }
    2601 
    2602     return rc;
     2614    if (aSetError)
     2615        return setError(VBOX_E_OBJECT_NOT_FOUND,
     2616                        tr("Could not find an open hard disk with location '%s'"),
     2617                        strLocation.c_str());
     2618
     2619    return VBOX_E_OBJECT_NOT_FOUND;
    26032620}
    26042621
     
    28772894
    28782895    char folder[RTPATH_MAX];
    2879     int vrc = RTPathAbsEx(m->strHomeDir.c_str(), strPath.c_str(), folder, sizeof(folder));
     2896    int vrc = RTPathAbsEx(m->strHomeDir.c_str(),
     2897                          strPath.c_str(),
     2898                          folder,
     2899                          sizeof(folder));
    28802900    if (RT_SUCCESS(vrc))
    28812901        aResult = folder;
     
    29392959    HRESULT rc = S_OK;
    29402960
    2941     Bstr bstrLocation(aLocation);
    29422961    aConflict.setNull();
    29432962    fIdentical = false;
     
    29462965    const char *pcszType = NULL;
    29472966
    2948     {
    2949         rc = findHardDisk(&aId, bstrLocation, false /* aSetError */, &pMediumFound);
    2950         if (SUCCEEDED(rc))
    2951             pcszType = tr("hard disk");
    2952     }
     2967    if (!aId.isEmpty())
     2968        rc = findHardDiskById(aId, false /* aSetError */, &pMediumFound);
     2969    if (FAILED(rc) && !aLocation.isEmpty())
     2970        rc = findHardDiskByLocation(aLocation, false /* aSetError */, &pMediumFound);
     2971    if (SUCCEEDED(rc))
     2972        pcszType = tr("hard disk");
    29532973
    29542974    if (!pcszType)
    29552975    {
    2956         rc = findDVDOrFloppyImage(DeviceType_DVD, &aId, bstrLocation, false /* aSetError */, &pMediumFound);
     2976        rc = findDVDOrFloppyImage(DeviceType_DVD, &aId, aLocation, false /* aSetError */, &pMediumFound);
    29572977        if (SUCCEEDED(rc))
    29582978            pcszType = tr("CD/DVD image");
     
    29612981    if (!pcszType)
    29622982    {
    2963         rc = findDVDOrFloppyImage(DeviceType_Floppy, &aId, bstrLocation, false /* aSetError */, &pMediumFound);
     2983        rc = findDVDOrFloppyImage(DeviceType_Floppy, &aId, aLocation, false /* aSetError */, &pMediumFound);
    29642984        if (SUCCEEDED(rc))
    29652985            pcszType = tr("floppy image");
     
    30343054 * This throws HRESULT on errors!
    30353055 *
    3036  * @param mediaRegistry
    3037  * @param uuidRegistry
    3038  * @return
     3056 * @param mediaRegistry Settings structure to fill.
     3057 * @param uuidRegistry The UUID of the media registry; either a machine UUID (if machine registry) or the UUID of the global registry.
     3058 * @param hardDiskFolder The machine folder for relative paths, if machine registry, or an empty string otherwise.
    30393059 */
    30403060void VirtualBox::saveMediaRegistry(settings::MediaRegistry &mediaRegistry,
    3041                                    const Guid &uuidRegistry)
     3061                                   const Guid &uuidRegistry,
     3062                                   const Utf8Str &strMachineFolder)
    30423063{
    30433064    HRESULT rc;
     
    30523073        {
    30533074            settings::Medium med;
    3054             rc = pMedium->saveSettings(med);     // this recurses into its children
     3075            rc = pMedium->saveSettings(med, strMachineFolder);     // this recurses into its children
    30553076            if (FAILED(rc)) throw rc;
    30563077            mediaRegistry.llHardDisks.push_back(med);
     
    30683089        {
    30693090            settings::Medium med;
    3070             rc = pMedium->saveSettings(med);
     3091            rc = pMedium->saveSettings(med, strMachineFolder);
    30713092            if (FAILED(rc)) throw rc;
    30723093            mediaRegistry.llDvdImages.push_back(med);
     
    30843105        {
    30853106            settings::Medium med;
    3086             rc = pMedium->saveSettings(med);
     3107            rc = pMedium->saveSettings(med, strMachineFolder);
    30873108            if (FAILED(rc)) throw rc;
    30883109            mediaRegistry.llFloppyImages.push_back(med);
     
    31683189
    31693190        saveMediaRegistry(m->pMainConfigFile->mediaRegistry,
    3170                           m->uuidMediaRegistry);
     3191                          m->uuidMediaRegistry,         // global media registry ID
     3192                          Utf8Str::Empty);              // strMachineFolder
    31713193
    31723194        mediaLock.release();
  • trunk/src/VBox/Main/include/MachineImpl.h

    r33140 r33232  
    152152        BOOL                mRegistered;
    153153
    154         /** Flag indicating that the config file is read-only. */
    155154        Utf8Str             m_strConfigFile;
    156155        Utf8Str             m_strConfigFileFull;
  • trunk/src/VBox/Main/include/MediumImpl.h

    r33140 r33232  
    8787                 DeviceType_T aDeviceType,
    8888                 const Guid &uuidMachineRegistry,
    89                  const settings::Medium &data);
     89                 const settings::Medium &data,
     90                 const Utf8Str &strMachineFolder);
    9091
    9192    // initializer for host floppy/DVD
     
    167168    MediumVariant_T getVariant() const;
    168169    bool isHostDrive() const;
    169     const Utf8Str& getLocation() const;
    170170    const Utf8Str& getLocationFull() const;
    171171    const Utf8Str& getFormat() const;
     
    199199    bool isReadOnly();
    200200
    201     HRESULT saveSettings(settings::Medium &data);
    202 
    203     HRESULT compareLocationTo(const Utf8Str &strLocation, int &aResult);
     201    HRESULT saveSettings(settings::Medium &data,
     202                         const Utf8Str &strHardDiskFolder);
    204203
    205204    HRESULT createMediumLockList(bool fFailIfInaccessible,
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r33078 r33232  
    9898    HRESULT initMachines();
    9999    HRESULT initMedia(const Guid &uuidMachineRegistry,
    100                       const settings::MediaRegistry mediaRegistry);
     100                      const settings::MediaRegistry mediaRegistry,
     101                      const Utf8Str &strMachineFolder);
    101102    void uninit();
    102103
     
    212213                        ComObjPtr<Machine> *machine = NULL);
    213214
    214     HRESULT findHardDisk(const Guid *aId,
    215                          const Utf8Str &strLocation,
    216                          bool aSetError,
    217                          ComObjPtr<Medium> *aHardDisk = NULL);
     215    HRESULT findHardDiskById(const Guid &id,
     216                             bool aSetError,
     217                             ComObjPtr<Medium> *aHardDisk = NULL);
     218    HRESULT findHardDiskByLocation(const Utf8Str &strLocation,
     219                                   bool aSetError,
     220                                   ComObjPtr<Medium> *aHardDisk = NULL);
    218221    HRESULT findDVDOrFloppyImage(DeviceType_T mediumType,
    219222                                 const Guid *aId,
     
    262265
    263266    void saveMediaRegistry(settings::MediaRegistry &mediaRegistry,
    264                            const Guid &uuidRegistry);
     267                           const Guid &uuidRegistry,
     268                           const Utf8Str &strMachineFolder);
    265269    HRESULT saveSettings();
    266270
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