VirtualBox

Changeset 33905 in vbox


Ignore:
Timestamp:
Nov 9, 2010 3:10:12 PM (14 years ago)
Author:
vboxsync
Message:

Main: fix regression that media in 4.0 machine folders became inaccessible after a machine rename (since 4.0 directory changes)

File:
1 edited

Legend:

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

    r33806 r33905  
    31003100 * ID match the given UUID.
    31013101 *
     3102 * Before actually writing to the structures, all media paths (not just the
     3103 * ones for the given registry) are updated if machines have been renamed
     3104 * since the last call.
     3105 *
    31023106 * This gets called from two contexts:
    31033107 *
     
    31143118 * get saved.
    31153119 *
    3116  * This throws HRESULT on errors!
     3120 * This locks the media tree. Throws HRESULT on errors!
    31173121 *
    31183122 * @param mediaRegistry Settings structure to fill.
     
    31243128                                   const Utf8Str &strMachineFolder)
    31253129{
     3130    // lock all media for the following; use a write lock because we're
     3131    // modifying the PendingMachineRenamesList, which is protected by this
     3132    AutoWriteLock mediaLock(getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS);
     3133
     3134    // if a machine was renamed, then we'll need to refresh media paths
     3135    if (m->llPendingMachineRenames.size())
     3136    {
     3137        // make a single list from the three media lists so we don't need three loops
     3138        MediaList llAllMedia;
     3139        // with hard disks, we must use the map, not the list, because the list only has base images
     3140        for (HardDiskMap::iterator it = m->mapHardDisks.begin(); it != m->mapHardDisks.end(); ++it)
     3141            llAllMedia.push_back(it->second);
     3142        for (MediaList::iterator it = m->allDVDImages.begin(); it != m->allDVDImages.end(); ++it)
     3143            llAllMedia.push_back(*it);
     3144        for (MediaList::iterator it = m->allFloppyImages.begin(); it != m->allFloppyImages.end(); ++it)
     3145            llAllMedia.push_back(*it);
     3146
     3147        for (MediaList::iterator it = llAllMedia.begin();
     3148             it != llAllMedia.end();
     3149             ++it)
     3150        {
     3151            Medium *pMedium = *it;
     3152            for (Data::PendingMachineRenamesList::iterator it2 = m->llPendingMachineRenames.begin();
     3153                 it2 != m->llPendingMachineRenames.end();
     3154                 ++it2)
     3155            {
     3156                const Data::PendingMachineRename &pmr = *it2;
     3157                pMedium->updatePath(pmr.strConfigDirOld,
     3158                                    pmr.strConfigDirNew);
     3159            }
     3160        }
     3161        // done, don't do it again until we have more machine renames
     3162        m->llPendingMachineRenames.clear();
     3163    }
     3164
    31263165    HRESULT rc;
    31273166    // hard disks
     
    32113250        }
    32123251
    3213         // lock all media for the following; use a write lock because we're
    3214         // modifying the PendingMachineRenamesList, which is protected by this
    3215         AutoWriteLock mediaLock(getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS);
    3216 
    3217         // if a machine was renamed, then we'll need to refresh media paths
    3218         if (m->llPendingMachineRenames.size())
    3219         {
    3220             // make a single list from the three media lists so we don't need three loops
    3221             MediaList llAllMedia;
    3222             // with hard disks, we must use the map, not the list, because the list only has base images
    3223             for (HardDiskMap::iterator it = m->mapHardDisks.begin(); it != m->mapHardDisks.end(); ++it)
    3224                 llAllMedia.push_back(it->second);
    3225             for (MediaList::iterator it = m->allDVDImages.begin(); it != m->allDVDImages.end(); ++it)
    3226                 llAllMedia.push_back(*it);
    3227             for (MediaList::iterator it = m->allFloppyImages.begin(); it != m->allFloppyImages.end(); ++it)
    3228                 llAllMedia.push_back(*it);
    3229 
    3230             for (MediaList::iterator it = llAllMedia.begin();
    3231                  it != llAllMedia.end();
    3232                  ++it)
    3233             {
    3234                 Medium *pMedium = *it;
    3235                 for (Data::PendingMachineRenamesList::iterator it2 = m->llPendingMachineRenames.begin();
    3236                      it2 != m->llPendingMachineRenames.end();
    3237                      ++it2)
    3238                 {
    3239                     // is medium in global registry:?
    3240                     if (pMedium->isInRegistry(m->uuidMediaRegistry))
    3241                     {
    3242                         const Data::PendingMachineRename &pmr = *it2;
    3243                         pMedium->updatePath(pmr.strConfigDirOld,
    3244                                             pmr.strConfigDirNew);
    3245                     }
    3246                 }
    3247             }
    3248             // done, don't do it again until we have more machine renames
    3249             m->llPendingMachineRenames.clear();
    3250         }
    3251 
    32523252        saveMediaRegistry(m->pMainConfigFile->mediaRegistry,
    32533253                          m->uuidMediaRegistry,         // global media registry ID
    32543254                          Utf8Str::Empty);              // strMachineFolder
    3255 
    3256         mediaLock.release();
    32573255
    32583256        m->pMainConfigFile->llDhcpServers.clear();
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