- Timestamp:
- Oct 19, 2010 2:24:46 PM (14 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ApplianceImplExport.cpp
r33102 r33232 1776 1776 // source path: where the VBox image is 1777 1777 const Utf8Str &strSrcFilePath = pDiskEntry->strVboxCurrent; 1778 Bstr bstrSrcFilePath(strSrcFilePath);1779 1778 1780 1779 // Do NOT check here whether the file exists. findHardDisk will … … 1785 1784 ComObjPtr<Medium> pSourceDisk; 1786 1785 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); 1789 1788 if (FAILED(rc)) throw rc; 1790 1789 -
trunk/src/VBox/Main/HostImpl.cpp
r32932 r33232 1612 1612 { 1613 1613 Medium *pCached = *itCached; 1614 const Utf8Str strLocationCached = pCached->getLocation ();1614 const Utf8Str strLocationCached = pCached->getLocationFull(); 1615 1615 bool fFound = false; 1616 1616 for (MediaList::iterator itNew = llNew.begin(); … … 1619 1619 { 1620 1620 Medium *pNew = *itNew; 1621 const Utf8Str strLocationNew = pNew->getLocation ();1621 const Utf8Str strLocationNew = pNew->getLocationFull(); 1622 1622 if (strLocationNew == strLocationCached) 1623 1623 { … … 1636 1636 { 1637 1637 Medium *pNew = *itNew; 1638 const Utf8Str strLocationNew = pNew->getLocation ();1638 const Utf8Str strLocationNew = pNew->getLocationFull(); 1639 1639 bool fFound = false; 1640 1640 for (MediaList::iterator itCached = pllCached->begin(); … … 1643 1643 { 1644 1644 Medium *pCached = *itCached; 1645 const Utf8Str strLocationCached = pCached->getLocation ();1645 const Utf8Str strLocationCached = pCached->getLocationFull(); 1646 1646 if (strLocationNew == strLocationCached) 1647 1647 { -
trunk/src/VBox/Main/MachineImpl.cpp
r33140 r33232 6928 6928 if (config.canHaveOwnMediaRegistry()) 6929 6929 { 6930 // determine machine folder 6931 Utf8Str strMachineFolder = getSettingsFileFull(); 6932 strMachineFolder.stripFilename(); 6930 6933 rc = mParent->initMedia(getId(), // media registry ID == machine UUID 6931 config.mediaRegistry); 6934 config.mediaRegistry, 6935 strMachineFolder); 6932 6936 if (FAILED(rc)) return rc; 6933 6937 } … … 7408 7412 { 7409 7413 /* 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); 7411 7415 if (FAILED(rc)) 7412 7416 { … … 8053 8057 // save machine's media registry if this is VirtualBox 4.0 or later 8054 8058 if (config.canHaveOwnMediaRegistry()) 8059 { 8060 // determine machine folder 8061 Utf8Str strMachineFolder = getSettingsFileFull(); 8062 strMachineFolder.stripFilename(); 8055 8063 mParent->saveMediaRegistry(config.mediaRegistry, 8056 getId()); // only media with registry ID == machine UUID 8064 getId(), // only media with registry ID == machine UUID 8065 strMachineFolder); 8057 8066 // this throws HRESULT 8067 } 8058 8068 8059 8069 // save snapshots … … 8410 8420 { 8411 8421 if (pMedium->isHostDrive()) 8412 dev.strHostDriveSrc = pMedium->getLocation ();8422 dev.strHostDriveSrc = pMedium->getLocationFull(); 8413 8423 else 8414 8424 dev.uuid = pMedium->getId(); -
trunk/src/VBox/Main/MediumImpl.cpp
r33187 r33232 117 117 MediumState_T state; 118 118 MediumVariant_T variant; 119 Utf8Str strLocation;120 119 Utf8Str strLocationFull; 121 120 uint64_t size; … … 948 947 if (FAILED(rc)) return rc; 949 948 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; 960 951 961 952 if (!(m->formatObj->getCapabilities() & ( MediumFormatCapabilities_CreateFixed … … 1085 1076 * @param uuidMachineRegistry The registry to which this medium should be added (global registry UUI or medium UUID). 1086 1077 * @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. 1089 1081 */ 1090 1082 HRESULT Medium::init(VirtualBox *aVirtualBox, … … 1092 1084 DeviceType_T aDeviceType, 1093 1085 const Guid &uuidMachineRegistry, 1094 const settings::Medium &data) 1086 const settings::Medium &data, 1087 const Utf8Str &strMachineFolder) 1095 1088 { 1096 1089 using namespace settings; … … 1171 1164 } 1172 1165 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); 1175 1185 if (FAILED(rc)) return rc; 1176 1186 … … 1212 1222 aDeviceType, 1213 1223 uuidMachineRegistry, 1214 med); // child data 1224 med, // child data 1225 strMachineFolder); 1215 1226 if (FAILED(rc)) break; 1216 1227 … … 2888 2899 2889 2900 /** 2890 * Internal method to return the medium's location. Must have caller + locking!2891 * @return2892 */2893 const Utf8Str& Medium::getLocation() const2894 {2895 return m->strLocation;2896 }2897 2898 /**2899 2901 * Internal method to return the medium's full location. Must have caller + locking! 2900 2902 * @return … … 3153 3155 unconst(m->strLocationFull) = newPath; 3154 3156 3155 Utf8Str path;3156 m->pVirtualBox->copyPathRelativeToConfig(newPath, path);3157 unconst(m->strLocation) = path;3158 3159 3157 LogFlowThisFunc(("locationFull.after='%s'\n", m->strLocationFull.c_str())); 3160 3158 } … … 3258 3256 * 3259 3257 * @param data Settings struct to be updated. 3258 * @param strHardDiskFolder Folder for which paths should be relative. 3260 3259 * 3261 3260 * @note Locks this object, medium tree and children for reading. 3262 3261 */ 3263 HRESULT Medium::saveSettings(settings::Medium &data) 3262 HRESULT Medium::saveSettings(settings::Medium &data, 3263 const Utf8Str &strHardDiskFolder) 3264 3264 { 3265 3265 AutoCaller autoCaller(this); … … 3272 3272 3273 3273 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; 3275 3282 data.strFormat = m->strFormat; 3276 3283 … … 3309 3316 { 3310 3317 settings::Medium med; 3311 HRESULT rc = (*it)->saveSettings(med );3318 HRESULT rc = (*it)->saveSettings(med, strHardDiskFolder); 3312 3319 AssertComRCReturnRC(rc); 3313 3320 data.llChildren.push_back(med); 3314 3321 } 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 the3323 * location is a file in the host's filesystem, a case insensitive comparison3324 * 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 locations3328 * are equal, 1 if this object's location is greater than3329 * 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 if3347 * 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 else3355 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 else3367 aResult = locationFull.compare(strLocation);3368 3322 3369 3323 return S_OK; … … 3604 3558 3605 3559 /** 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 3614 3565 * '{<uuid>}.<ext>' where <uuid> is a fresh UUID that this method will generate 3615 3566 * and assign to this medium, and <ext> is the default extension for this … … 3652 3603 Guid id; 3653 3604 3654 Utf8Str location (aLocation);3605 Utf8Str locationFull(aLocation); 3655 3606 3656 3607 if (m->state == MediumState_NotCreated) … … 3659 3610 Assert(m->formatObj->getCapabilities() & MediumFormatCapabilities_File); 3660 3611 3661 if (RTPathFilename( location.c_str()) == NULL)3612 if (RTPathFilename(aLocation.c_str()) == NULL) 3662 3613 { 3663 3614 /* no file name is given (either an empty string or ends with a … … 3676 3627 id.create(); 3677 3628 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()); 3680 3631 } 3681 3632 } 3682 3633 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())); 3700 3636 3701 3637 /* detect the backend from the storage unit if importing */ … … 3703 3639 { 3704 3640 char *backendName = NULL; 3641 3642 int vrc = VINF_SUCCESS; 3705 3643 3706 3644 /* is it a file? */ … … 3719 3657 { 3720 3658 /* assume it's not a file, restore the original location */ 3721 location = locationFull = aLocation;3659 locationFull = aLocation; 3722 3660 vrc = VDGetFormat(NULL /* pVDIfsDisk */, NULL /* pVDIfsImage */, 3723 3661 locationFull.c_str(), &backendName); … … 3755 3693 } 3756 3694 3695 m->strLocationFull = locationFull; 3696 3757 3697 /* 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; 3777 3706 } 3778 3707 else 3779 {3780 m->strLocation = aLocation;3781 3708 m->strLocationFull = aLocation; 3782 }3783 3709 3784 3710 return S_OK; … … 4006 3932 Guid id = parentId; 4007 3933 ComObjPtr<Medium> pParent; 4008 rc = m->pVirtualBox->findHardDisk (&id, Utf8Str::Empty, false /* aSetError */, &pParent);3934 rc = m->pVirtualBox->findHardDiskById(id, false /* aSetError */, &pParent); 4009 3935 if (FAILED(rc)) 4010 3936 { -
trunk/src/VBox/Main/VirtualBoxImpl.cpp
r33078 r33232 457 457 /* all registered media, needed by machines */ 458 458 if (FAILED(rc = initMedia(m->uuidMediaRegistry, 459 m->pMainConfigFile->mediaRegistry))) 459 m->pMainConfigFile->mediaRegistry, 460 Utf8Str::Empty))) // const Utf8Str &machineFolder 460 461 throw rc; 461 462 … … 608 609 */ 609 610 HRESULT VirtualBox::initMedia(const Guid &uuidRegistry, 610 const settings::MediaRegistry mediaRegistry) 611 const settings::MediaRegistry mediaRegistry, 612 const Utf8Str &strMachineFolder) 611 613 { 612 614 LogFlow(("VirtualBox::initMedia ENTERING, uuidRegistry=%s\n", uuidRegistry.toString().c_str())); … … 628 630 DeviceType_HardDisk, 629 631 uuidRegistry, 630 xmlHD); // XML data; this recurses to processes the children 632 xmlHD, // XML data; this recurses to processes the children 633 strMachineFolder); 631 634 if (FAILED(rc)) return rc; 632 635 … … 648 651 DeviceType_DVD, 649 652 uuidRegistry, 650 xmlDvd); 653 xmlDvd, 654 strMachineFolder); 651 655 if (FAILED(rc)) return rc; 652 656 … … 669 673 DeviceType_Floppy, 670 674 uuidRegistry, 671 xmlFloppy); 675 xmlFloppy, 676 strMachineFolder); 672 677 if (FAILED(rc)) return rc; 673 678 … … 1479 1484 case DeviceType_HardDisk: 1480 1485 if (!id.isEmpty()) 1481 rc = findHardDisk (&id, Utf8Str::Empty, true /* setError */, &pMedium);1486 rc = findHardDiskById(id, true /* setError */, &pMedium); 1482 1487 else 1483 rc = findHardDisk (NULL,strLocation, true /* setError */, &pMedium);1488 rc = findHardDiskByLocation(strLocation, true /* setError */, &pMedium); 1484 1489 break; 1485 1490 … … 2525 2530 2526 2531 /** 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 */ 2544 HRESULT 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 /** 2527 2571 * Searches for a Medium object with the given ID or location in the list of 2528 2572 * registered hard disks. If both ID and location are specified, the first 2529 2573 * object that matches either of them (not necessarily both) is returned. 2530 2574 * 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. 2533 2576 * @param aSetError If @c true , the appropriate error info is set in case 2534 2577 * when the hard disk is not found. 2535 2578 * @param aHardDisk Where to store the found hard disk object (can be NULL). 2536 2579 * 2537 * @return S_OK when found or E_INVALIDARGwhen not found.2580 * @return S_OK, E_INVALIDARG or VBOX_E_OBJECT_NOT_FOUND when not found. 2538 2581 * 2539 2582 * @note Locks the media tree for reading. 2540 2583 */ 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); 2584 HRESULT VirtualBox::findHardDiskByLocation(const Utf8Str &strLocation, 2585 bool aSetError, 2586 ComObjPtr<Medium> *aHardDisk /*= NULL*/) 2587 { 2588 AssertReturn(!strLocation.isEmpty(), E_INVALIDARG); 2547 2589 2548 2590 // we use the hard disks map, but it is protected by the … … 2550 2592 AutoReadLock alock(m->allHardDisks.getLockHandle() COMMA_LOCKVAL_SRC_POS); 2551 2593 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())) 2557 2607 { 2558 2608 if (aHardDisk) 2559 *aHardDisk = (*it).second;2609 *aHardDisk = pHD; 2560 2610 return S_OK; 2561 2611 } 2562 2612 } 2563 2613 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; 2603 2620 } 2604 2621 … … 2877 2894 2878 2895 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)); 2880 2900 if (RT_SUCCESS(vrc)) 2881 2901 aResult = folder; … … 2939 2959 HRESULT rc = S_OK; 2940 2960 2941 Bstr bstrLocation(aLocation);2942 2961 aConflict.setNull(); 2943 2962 fIdentical = false; … … 2946 2965 const char *pcszType = NULL; 2947 2966 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"); 2953 2973 2954 2974 if (!pcszType) 2955 2975 { 2956 rc = findDVDOrFloppyImage(DeviceType_DVD, &aId, bstrLocation, false /* aSetError */, &pMediumFound);2976 rc = findDVDOrFloppyImage(DeviceType_DVD, &aId, aLocation, false /* aSetError */, &pMediumFound); 2957 2977 if (SUCCEEDED(rc)) 2958 2978 pcszType = tr("CD/DVD image"); … … 2961 2981 if (!pcszType) 2962 2982 { 2963 rc = findDVDOrFloppyImage(DeviceType_Floppy, &aId, bstrLocation, false /* aSetError */, &pMediumFound);2983 rc = findDVDOrFloppyImage(DeviceType_Floppy, &aId, aLocation, false /* aSetError */, &pMediumFound); 2964 2984 if (SUCCEEDED(rc)) 2965 2985 pcszType = tr("floppy image"); … … 3034 3054 * This throws HRESULT on errors! 3035 3055 * 3036 * @param mediaRegistry 3037 * @param uuidRegistry 3038 * @ return3056 * @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. 3039 3059 */ 3040 3060 void VirtualBox::saveMediaRegistry(settings::MediaRegistry &mediaRegistry, 3041 const Guid &uuidRegistry) 3061 const Guid &uuidRegistry, 3062 const Utf8Str &strMachineFolder) 3042 3063 { 3043 3064 HRESULT rc; … … 3052 3073 { 3053 3074 settings::Medium med; 3054 rc = pMedium->saveSettings(med ); // this recurses into its children3075 rc = pMedium->saveSettings(med, strMachineFolder); // this recurses into its children 3055 3076 if (FAILED(rc)) throw rc; 3056 3077 mediaRegistry.llHardDisks.push_back(med); … … 3068 3089 { 3069 3090 settings::Medium med; 3070 rc = pMedium->saveSettings(med );3091 rc = pMedium->saveSettings(med, strMachineFolder); 3071 3092 if (FAILED(rc)) throw rc; 3072 3093 mediaRegistry.llDvdImages.push_back(med); … … 3084 3105 { 3085 3106 settings::Medium med; 3086 rc = pMedium->saveSettings(med );3107 rc = pMedium->saveSettings(med, strMachineFolder); 3087 3108 if (FAILED(rc)) throw rc; 3088 3109 mediaRegistry.llFloppyImages.push_back(med); … … 3168 3189 3169 3190 saveMediaRegistry(m->pMainConfigFile->mediaRegistry, 3170 m->uuidMediaRegistry); 3191 m->uuidMediaRegistry, // global media registry ID 3192 Utf8Str::Empty); // strMachineFolder 3171 3193 3172 3194 mediaLock.release(); -
trunk/src/VBox/Main/include/MachineImpl.h
r33140 r33232 152 152 BOOL mRegistered; 153 153 154 /** Flag indicating that the config file is read-only. */155 154 Utf8Str m_strConfigFile; 156 155 Utf8Str m_strConfigFileFull; -
trunk/src/VBox/Main/include/MediumImpl.h
r33140 r33232 87 87 DeviceType_T aDeviceType, 88 88 const Guid &uuidMachineRegistry, 89 const settings::Medium &data); 89 const settings::Medium &data, 90 const Utf8Str &strMachineFolder); 90 91 91 92 // initializer for host floppy/DVD … … 167 168 MediumVariant_T getVariant() const; 168 169 bool isHostDrive() const; 169 const Utf8Str& getLocation() const;170 170 const Utf8Str& getLocationFull() const; 171 171 const Utf8Str& getFormat() const; … … 199 199 bool isReadOnly(); 200 200 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); 204 203 205 204 HRESULT createMediumLockList(bool fFailIfInaccessible, -
trunk/src/VBox/Main/include/VirtualBoxImpl.h
r33078 r33232 98 98 HRESULT initMachines(); 99 99 HRESULT initMedia(const Guid &uuidMachineRegistry, 100 const settings::MediaRegistry mediaRegistry); 100 const settings::MediaRegistry mediaRegistry, 101 const Utf8Str &strMachineFolder); 101 102 void uninit(); 102 103 … … 212 213 ComObjPtr<Machine> *machine = NULL); 213 214 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); 218 221 HRESULT findDVDOrFloppyImage(DeviceType_T mediumType, 219 222 const Guid *aId, … … 262 265 263 266 void saveMediaRegistry(settings::MediaRegistry &mediaRegistry, 264 const Guid &uuidRegistry); 267 const Guid &uuidRegistry, 268 const Utf8Str &strMachineFolder); 265 269 HRESULT saveSettings(); 266 270
Note:
See TracChangeset
for help on using the changeset viewer.