VirtualBox

Changeset 49687 in vbox for trunk/src/VBox/Main/xml


Ignore:
Timestamp:
Nov 27, 2013 6:00:49 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
90957
Message:

Main/Snapshot: block deleting of current snapshot if it has child snapshots, as this would lead to VM config corruption, plus safety belts in the GUI and settings reader

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/xml/Settings.cpp

    r49296 r49687  
    36983698 * Snapshot structure.
    36993699 *
     3700 * @param curSnapshotUuid
    37003701 * @param depth
    37013702 * @param elmSnapshot
    37023703 * @param snap
    3703  */
    3704 void MachineConfigFile::readSnapshot(uint32_t depth,
     3704 * @returns true if curSnapshotUuid is in this snapshot subtree, otherwise false
     3705 */
     3706bool MachineConfigFile::readSnapshot(const Guid &curSnapshotUuid,
     3707                                     uint32_t depth,
    37053708                                     const xml::ElementNode &elmSnapshot,
    37063709                                     Snapshot &snap)
     
    37143717        throw ConfigFileError(this, &elmSnapshot, N_("Required Snapshot/@uuid attribute is missing"));
    37153718    parseUUID(snap.uuid, strTemp);
     3719    bool foundCurrentSnapshot = (snap.uuid == curSnapshotUuid);
    37163720
    37173721    if (!elmSnapshot.getAttributeValue("name", snap.strName))
     
    37583762                    // small, especially with XPCOM.
    37593763                    Snapshot *child = new Snapshot();
    3760                     readSnapshot(depth + 1, *pelmChildSnapshot, *child);
     3764                    bool found = readSnapshot(curSnapshotUuid, depth + 1, *pelmChildSnapshot, *child);
     3765                    foundCurrentSnapshot = foundCurrentSnapshot || found;
    37613766                    snap.llChildSnapshots.push_back(*child);
    37623767                    delete child;
     
    37743779    readAutostart(elmSnapshot.findChildElement("Autostart"), &snap.autostart);
    37753780    // note: Groups exist only for Machine, not for Snapshot
     3781
     3782    return foundCurrentSnapshot;
    37763783}
    37773784
     
    38943901            else if (pelmMachineChild->nameEquals("Snapshot"))
    38953902            {
     3903                if (uuidCurrentSnapshot.isZero())
     3904                    throw ConfigFileError(this, &elmMachine, N_("Snapshots present but required Machine/@currentSnapshot attribute is missing"));
     3905                bool foundCurrentSnapshot = false;
    38963906                Snapshot snap;
    38973907                // this will recurse into child snapshots, if necessary
    3898                 readSnapshot(1, *pelmMachineChild, snap);
     3908                foundCurrentSnapshot = readSnapshot(uuidCurrentSnapshot, 1, *pelmMachineChild, snap);
     3909                if (!foundCurrentSnapshot)
     3910                    throw ConfigFileError(this, &elmMachine, N_("Snapshots present but none matches the UUID in the Machine/@currentSnapshot attribute"));
    38993911                llFirstSnapshot.push_back(snap);
    39003912            }
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