VirtualBox

Changeset 23882 in vbox


Ignore:
Timestamp:
Oct 19, 2009 6:36:03 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
53663
Message:

Main: make restoreSnapshot() work better, adjust VBoxManage

Location:
trunk/src/VBox
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h

    r23802 r23882  
    169169
    170170/* VBoxManageVMInfo.cpp */
    171 void showSnapshots(ComPtr<ISnapshot> rootSnapshot, VMINFO_DETAILS details, const com::Bstr &prefix = "", int level = 0);
     171void showSnapshots(ComPtr<ISnapshot> &rootSnapshot,
     172                   ComPtr<ISnapshot> &currentSnapshot,
     173                   VMINFO_DETAILS details,
     174                   const com::Bstr &prefix = "",
     175                   int level = 0);
    172176int handleShowVMInfo(HandlerArg *a);
    173177HRESULT showVMInfo(ComPtr<IVirtualBox> virtualBox,
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp

    r23847 r23882  
    327327        RTPrintf("VBoxManage snapshot         <uuid>|<name>\n"
    328328                 "                            take <name> [--description <desc>] [--pause] |\n"
    329                  "                            discard <uuid>|<name> |\n"
    330                  "                            discardcurrent --state|--all |\n"
     329                 "                            delete <uuid>|<name> |\n"
     330                 "                            restore <uuid>|<name> |\n"
    331331                 "                            edit <uuid>|<name>|--current\n"
    332332                 "                                 [--name <name>]\n"
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageInfo.cpp

    r23801 r23882  
    4848///////////////////////////////////////////////////////////////////////////////
    4949
    50 void showSnapshots(ComPtr<ISnapshot> rootSnapshot, VMINFO_DETAILS details, const Bstr &prefix /* = ""*/, int level /*= 0*/)
     50void showSnapshots(ComPtr<ISnapshot> &rootSnapshot,
     51                   ComPtr<ISnapshot> &currentSnapshot,
     52                   VMINFO_DETAILS details,
     53                   const Bstr &prefix /* = ""*/,
     54                   int level /*= 0*/)
    5155{
    5256    /* start with the root */
     
    6468    {
    6569        /* print with indentation */
    66         RTPrintf("   %lSName: %lS (UUID: %s)\n", prefix.raw(), name.raw(), Utf8Str(uuid).raw());
     70        bool fCurrent = (rootSnapshot == currentSnapshot);
     71        RTPrintf("   %lSName: %lS (UUID: %s)%s\n",
     72                 prefix.raw(),
     73                 name.raw(),
     74                 Utf8Str(uuid).raw(),
     75                 (fCurrent) ? " *" : "");
    6776    }
    6877
     
    8190                    newPrefix = Utf8StrFmt("%lS-%d", prefix.raw(), index + 1);
    8291                else
     92                {
    8393                    newPrefix = Utf8StrFmt("%lS   ", prefix.raw());
     94                }
     95
    8496                /* recursive call */
    85                 showSnapshots(snapshot, details, newPrefix, level + 1);
     97                showSnapshots(snapshot, currentSnapshot, details, newPrefix, level + 1);
    8698            }
    8799        }
     
    18321844    if (SUCCEEDED(rc) && snapshot)
    18331845    {
    1834         if (details != VMINFO_MACHINEREADABLE)
    1835             RTPrintf("Snapshots:\n\n");
    1836         showSnapshots(snapshot, details);
     1846        ComPtr<ISnapshot> currentSnapshot;
     1847        rc = machine->GetCurrentSnapshot(currentSnapshot.asOutParam());
     1848        if (SUCCEEDED(rc))
     1849        {
     1850            if (details != VMINFO_MACHINEREADABLE)
     1851                RTPrintf("Snapshots:\n\n");
     1852            showSnapshots(snapshot, currentSnapshot, details);
     1853        }
    18371854    }
    18381855
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageSnapshot.cpp

    r23879 r23882  
    6868
    6969        /* switch based on the command */
     70        bool fDelete = false, fRestore = false;
    7071        if (!strcmp(a->argv[1], "take"))
    7172        {
     
    154155            }
    155156        }
    156         else if (!strcmp(a->argv[1], "discard"))
     157        else if (    (fDelete = !strcmp(a->argv[1], "delete"))
     158                  || (fRestore = !strcmp(a->argv[1], "restore"))
     159                )
    157160        {
    158161            /* exactly one parameter: snapshot name */
     
    164167            }
    165168
    166             ComPtr<ISnapshot> snapshot;
     169            ComPtr<ISnapshot> pSnapshot;
    167170
    168171            /* assume it's a UUID */
     
    170173            if (!guid.isEmpty())
    171174            {
    172                 CHECK_ERROR_BREAK(machine, GetSnapshot(guid, snapshot.asOutParam()));
     175                CHECK_ERROR_BREAK(machine, GetSnapshot(guid, pSnapshot.asOutParam()));
    173176            }
    174177            else
    175178            {
    176179                /* then it must be a name */
    177                 CHECK_ERROR_BREAK(machine, FindSnapshot(Bstr(a->argv[2]), snapshot.asOutParam()));
    178             }
    179 
    180             snapshot->COMGETTER(Id)(guid.asOutParam());
    181 
    182             ComPtr<IProgress> progress;
    183             CHECK_ERROR_BREAK(console, DeleteSnapshot(guid, progress.asOutParam()));
    184 
    185             showProgress(progress);
    186             LONG iRc;
    187             progress->COMGETTER(ResultCode)(&iRc);
    188             rc = iRc;
    189             if (FAILED(rc))
    190             {
    191                 com::ProgressErrorInfo info(progress);
    192                 if (info.isBasicAvailable())
    193                     RTPrintf("Error: failed to discard snapshot. Error message: %lS\n", info.getText().raw());
    194                 else
    195                     RTPrintf("Error: failed to discard snapshot. No error message available!\n");
    196             }
    197         }
    198         else if (!strcmp(a->argv[1], "discardcurrent"))
    199         {
    200             if (   (a->argc != 3)
    201                 || (   strcmp(a->argv[2], "--state")
    202                     && strcmp(a->argv[2], "-state")))
    203             {
    204                 errorSyntax(USAGE_SNAPSHOT, "Invalid parameter '%s'", Utf8Str(a->argv[2]).raw());
    205                 rc = E_FAIL;
    206                 break;
    207             }
    208 
    209             ComPtr<ISnapshot> pCurrentSnapshot;
    210             CHECK_ERROR_BREAK(machine, COMGETTER(CurrentSnapshot)(pCurrentSnapshot.asOutParam()));
     180                CHECK_ERROR_BREAK(machine, FindSnapshot(Bstr(a->argv[2]), pSnapshot.asOutParam()));
     181                pSnapshot->COMGETTER(Id)(guid.asOutParam());
     182            }
    211183
    212184            ComPtr<IProgress> pProgress;
    213             CHECK_ERROR_BREAK(console, RestoreSnapshot(pCurrentSnapshot, pProgress.asOutParam()));
     185            if (fDelete)
     186            {
     187                CHECK_ERROR_BREAK(console, DeleteSnapshot(guid, pProgress.asOutParam()));
     188            }
     189            else
     190            {
     191                // must be restore
     192                CHECK_ERROR_BREAK(console, RestoreSnapshot(pSnapshot, pProgress.asOutParam()));
     193            }
    214194
    215195            showProgress(pProgress);
     
    221201                com::ProgressErrorInfo info(pProgress);
    222202                if (info.isBasicAvailable())
    223                     RTPrintf("Error: failed to restore snapshot. Error message: %lS\n", info.getText().raw());
    224                 else
    225                     RTPrintf("Error: failed to restore snapshot. No error message available!\n");
    226             }
    227 
     203                    RTPrintf("Error: snapshot operation failed. Error message: %lS\n", info.getText().raw());
     204                else
     205                    RTPrintf("Error: snapshot operation failed. No error message available!\n");
     206            }
    228207        }
    229208        else if (!strcmp(a->argv[1], "edit"))
  • trunk/src/VBox/Main/MachineImpl.cpp

    r23881 r23882  
    75867586    void handler()
    75877587    {
    7588         machine->discardSnapshotHandler(*this);
     7588        machine->deleteSnapshotHandler(*this);
    75897589    }
    75907590
     
    94459445
    94469446/**
    9447  * Helper struct for SessionMachine::discardSnapshotHandler().
     9447 * Helper struct for SessionMachine::deleteSnapshotHandler().
    94489448 */
    94499449struct MediumDiscardRec
     
    94849484 * @note Locks mParent + this + child objects for writing!
    94859485 */
    9486 void SessionMachine::discardSnapshotHandler(DeleteSnapshotTask &aTask)
     9486void SessionMachine::deleteSnapshotHandler(DeleteSnapshotTask &aTask)
    94879487{
    94889488    LogFlowThisFuncEnter();
     
    98959895                {
    98969896                    mSSData->mStateFilePath = stateFilePath;
     9897
     9898                    /* make the snapshot we restored from the current snapshot */
     9899                    mData->mCurrentSnapshot = aTask.pSnapshot;
    98979900                }
    98989901                else
  • trunk/src/VBox/Main/include/MachineImpl.h

    r23879 r23882  
    10371037    typedef std::map<ComObjPtr<Machine>, MachineState_T> AffectedMachines;
    10381038
    1039     void discardSnapshotHandler(DeleteSnapshotTask &aTask);
     1039    void deleteSnapshotHandler(DeleteSnapshotTask &aTask);
    10401040    void restoreSnapshotHandler(RestoreSnapshotTask &aTask);
    10411041
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