VirtualBox

Changeset 37900 in vbox for trunk/src/VBox/Main/src-server


Ignore:
Timestamp:
Jul 12, 2011 1:31:46 PM (14 years ago)
Author:
vboxsync
Message:

Main-CloneVM;FE/CLI;Doc: update differencing disk names with there new uuid; rename all other disks to the new name + disk#; optional allow keeping old disk names

Location:
trunk/src/VBox/Main/src-server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/MachineImplCloneVM.cpp

    r37612 r37900  
    464464    /*
    465465     * Todo:
    466      * - Snapshot diffs (can) have the uuid as name. After cloning this isn't
    467      *   right anymore. Is it worth to change to the new uuid? Or should the
    468      *   cloned disks called exactly as the original one or should all new disks
    469      *   get a new name with the new VM name in it.
    470466     * - What about log files?
    471467     */
     
    541537        strTrgSnapshotFolder = Utf8StrFmt("%s%c%s", strTrgMachineFolder.c_str(), RTPATH_DELIMITER, trgMCF.machineUserData.strSnapshotFolder.c_str());
    542538
     539        /* Should we rename the disk names. */
     540        bool fKeepDiskNames = d->options.contains(CloneOptions_KeepDiskNames);
     541
    543542        /* We need to create a map with the already created medias. This is
    544543         * necessary, cause different snapshots could have the same
     
    548547        typedef std::pair<Utf8Str, ComObjPtr<Medium> > TStrMediumPair;
    549548        TStrMediumMap map;
     549        size_t cDisks = 0;
    550550        for (size_t i = 0; i < d->llMedias.size(); ++i)
    551551        {
     
    596596                    }
    597597
     598                    /* If the old disk name was in {uuid} format we also want
     599                     * the new name in this format, but with the updated id of
     600                     * course. For all other disks we rename them with this
     601                     * template: "new name-disk1.vdi". */
     602                    Guid newId;
     603                    newId.create();
     604                    Utf8Str strNewName(bstrSrcName);
     605                    if (!fKeepDiskNames)
     606                    {
     607                        strNewName = Utf8StrFmt("%s-disk%d%s", trgMCF.machineUserData.strName.c_str(), ++cDisks, RTPathExt(Utf8Str(bstrSrcName).c_str()));
     608                        Utf8Str strSrcTest = Utf8Str(bstrSrcName).stripExt();
     609                        if (strSrcTest.startsWith("{") &&
     610                            strSrcTest.endsWith("}"))
     611                        {
     612                            strSrcTest = strSrcTest.substr(1, strSrcTest.length() - 2);
     613                            if (isValidGuid(strSrcTest))
     614                            {
     615                                strNewName = Utf8StrFmt("%s%s", newId.toStringCurly().c_str(), RTPathExt(strNewName.c_str()));
     616                                --cDisks;
     617                            }
     618                        }
     619                    }
     620
    598621                    /* Check if this medium comes from the snapshot folder, if
    599622                     * so, put it there in the cloned machine as well.
    600623                     * Otherwise it goes to the machine folder. */
    601                     Utf8Str strFile = Utf8StrFmt("%s%c%lS", strTrgMachineFolder.c_str(), RTPATH_DELIMITER, bstrSrcName.raw());
    602624                    Bstr bstrSrcPath;
     625                    Utf8Str strFile = Utf8StrFmt("%s%c%s", strTrgMachineFolder.c_str(), RTPATH_DELIMITER, strNewName.c_str());
    603626                    rc = pMedium->COMGETTER(Location)(bstrSrcPath.asOutParam());
    604627                    if (FAILED(rc)) throw rc;
    605628                    if (   !bstrSrcPath.isEmpty()
    606629                        &&  RTPathStartsWith(Utf8Str(bstrSrcPath).c_str(), Utf8Str(bstrSrcSnapshotFolder).c_str()))
    607                         strFile = Utf8StrFmt("%s%c%lS", strTrgSnapshotFolder.c_str(), RTPATH_DELIMITER, bstrSrcName.raw());
     630                        strFile = Utf8StrFmt("%s%c%s", strTrgSnapshotFolder.c_str(), RTPATH_DELIMITER, strNewName.c_str());
    608631                    else
    609                         strFile = Utf8StrFmt("%s%c%lS", strTrgMachineFolder.c_str(), RTPATH_DELIMITER, bstrSrcName.raw());
     632                        strFile = Utf8StrFmt("%s%c%s", strTrgMachineFolder.c_str(), RTPATH_DELIMITER, strNewName.c_str());
    610633
    611634                    /* Start creating the clone. */
     
    620643                                       NULL          /* llRegistriesThatNeedSaving */);
    621644                    if (FAILED(rc)) throw rc;
     645
     646                    /* Update the new uuid. */
     647                    pTarget->updateId(newId);
    622648
    623649                    srcLock.release();
  • trunk/src/VBox/Main/src-server/MediumImpl.cpp

    r37831 r37900  
    36403640
    36413641    AssertFailedReturn(false);
     3642}
     3643
     3644/**
     3645 * Internal method to return the medium's size. Must have caller + locking!
     3646 * @return
     3647 */
     3648void Medium::updateId(const Guid &id)
     3649{
     3650    unconst(m->id) = id;
    36423651}
    36433652
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