VirtualBox

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


Ignore:
Timestamp:
May 26, 2019 4:31:12 AM (6 years ago)
Author:
vboxsync
Message:

Main/Machine::moveTo: Some cleanups and a lot of @todo's. bugref:8345

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

Legend:

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

    r78632 r78761  
    54585458    DeleteConfigTask *pTask = new DeleteConfigTask(this, pProgress, "DeleteVM", llMediums, llFilesToDelete);
    54595459    rc = pTask->createThread();
     5460    pTask = NULL;
    54605461    if (FAILED(rc))
    54615462        return rc;
     
    71547155    LogFlowThisFuncEnter();
    71557156
    7156     ComObjPtr<Progress> progress;
    7157 
    7158     progress.createObject();
    7159 
    7160     HRESULT rc = S_OK;
    7161     Utf8Str targetPath = aTargetPath;
    7162     Utf8Str type = aType;
    7163 
    7164     /* Initialize our worker task */
    7165     MachineMoveVM* task = NULL;
    7166     try
    7167     {
    7168         task = new MachineMoveVM(this, targetPath, type, progress);
    7169     }
    7170     catch(...)
    7171     {
    7172         delete task;
    7173         return rc;
    7174     }
    7175 
    7176     /*
    7177      * task pointer will be owned by the ThreadTask class.
    7178      * There is no need to call operator "delete" in the end.
    7179      */
    7180     rc = task->init();
    7181     if (SUCCEEDED(rc))
    7182     {
    7183         rc = task->createThread();
    7184         if (FAILED(rc))
    7185         {
    7186             setError(rc, tr("Could not run the thread for the task MachineMoveVM"));
    7187         }
    7188 
    7189         /* Return progress to the caller */
    7190         progress.queryInterfaceTo(aProgress.asOutParam());
     7157    ComObjPtr<Progress> ptrProgress;
     7158    HRESULT hrc = ptrProgress.createObject();
     7159    if (SUCCEEDED(hrc))
     7160    {
     7161        /* Initialize our worker task */
     7162        MachineMoveVM *pTask = NULL;
     7163        try
     7164        {
     7165            pTask = new MachineMoveVM(this, aTargetPath, aType, ptrProgress);
     7166        }
     7167        catch (std::bad_alloc &)
     7168        {
     7169            return E_OUTOFMEMORY;
     7170        }
     7171        /** @todo r=bird: Turned out the init() function throws stuff of type int
     7172         *        without telling anyone.  Probably unintentionally.  The catching
     7173         *        here is only temporary until someone can be bothered to fix it
     7174         *        properly. */
     7175        try
     7176        {
     7177            hrc = pTask->init();
     7178        }
     7179        catch (...)
     7180        {
     7181            hrc = setError(E_FAIL, tr("Unknown exception thrown by MachineMoveVM::init"));
     7182        }
     7183        if (SUCCEEDED(hrc))
     7184        {
     7185            hrc = pTask->createThread();
     7186            pTask = NULL; /* Consumed by createThread(). */
     7187            if (SUCCEEDED(hrc))
     7188                ptrProgress.queryInterfaceTo(aProgress.asOutParam());
     7189            else
     7190                setError(hrc, tr("Failed to create a worker thread for the MachineMoveVM task"));
     7191        }
     7192        else
     7193            delete pTask;
    71917194    }
    71927195
    71937196    LogFlowThisFuncLeave();
    7194     return rc;
     7197    return hrc;
    71957198
    71967199}
  • trunk/src/VBox/Main/src-server/MachineImplMoveVM.cpp

    r78404 r78761  
    153153    {
    154154        size_t len = m_targetPath.length() + 2;
    155         if (len >=RTPATH_MAX)
    156         {
     155        if (len >= RTPATH_MAX)
     156        {
     157            /** @todo r=bird: Why the leading space in errorDesc? */
     158            /** @todo "The destination path exceeds the maximum length" should
     159             *        suffice here, I think. */
     160            /** @todo r=bird: missing tr(). */
     161            /** @todo r=bird: Actually, why bother with these error strings here? Nobody
     162             *        will ever see them, given that the caller deletes the task when
     163             *        init() fails. */
    157164            Utf8Str errorDesc(" The destination path isn't correct. The length of path exceeded the maximum value.");
    158165            errorsList.push_back(ErrorInfoItem(VBOX_E_IPRT_ERROR, errorDesc.c_str()));
     166            /** @todo r=bird: What on earth is this?  It will cause the caller to leak the
     167             *        task structure, unless it's catching exception (which it wasn't, but
     168             *        I made it is now).  I sure hope this wasn't intentional... */
    159169            throw m_pMachine->setError(VBOX_E_IPRT_ERROR, m_pMachine->tr(errorDesc.c_str()));
    160170        }
    161171
     172        /** @todo r=bird: I need to add a Utf8Str method or iprt/cxx/path.h thingy
     173         *        for doing this.  We need this often and code like this doesn't
     174         *        need to be repeated and re-optimized in each instance... */
    162175        char* path = new char [len];
    163176        RTStrCopy(path, len, m_targetPath.c_str());
     
    178191    try
    179192    {
    180         Utf8Str info;
    181         int vrc = 0;
    182 
    183193        RTFOFF cbTotal = 0;
    184194        RTFOFF cbFree = 0;
     
    186196        uint32_t cbSector = 0;
    187197
    188         vrc = RTFsQuerySizes(strTargetFolder.c_str(), &cbTotal, &cbFree, &cbBlock, &cbSector);
     198        int vrc = RTFsQuerySizes(strTargetFolder.c_str(), &cbTotal, &cbFree, &cbBlock, &cbSector);
    189199        if (FAILED(vrc))
    190200        {
     201            /** @todo r=bird: What's this RTPrint doing here?!? */
    191202            RTPrintf("strTargetFolder is %s\n", strTargetFolder.c_str());
    192203            Utf8StrFmt errorDesc("Unable to move machine. Can't get the destination storage size (%s)",
     
    201212        vrc = RTDirOpen(&hDir, strTargetFolder.c_str());
    202213        if (FAILED(vrc))
    203             throw rc = vrc;
     214            throw rc = vrc; /** @todo r=bird: RTDirOpen returns a VBox status code. That is _not_ the same as a COM HRESULT! */
    204215        else
    205216        {
     
    213224                errorsList.push_back(ErrorInfoItem(HRESULT(vrc), errorDesc.c_str()));
    214225                rc = m_pMachine->setErrorBoth(VBOX_E_FILE_ERROR, vrc, m_pMachine->tr(errorDesc.c_str()));
    215             }
    216 
    217             RTFileClose(hFile);
     226                /** @todo r=bird: What happens to this error and 'rc'?  Should it be ignored? */
     227            }
     228
     229            RTFileClose(hFile); /** @todo r=bird: Whey close if opening fail? */
    218230            RTFileDelete(strTempFile.c_str());
    219231            RTDirClose(hDir);
    220232        }
    221233
    222         long long totalFreeSpace = cbFree;
    223         long long totalSpace = cbTotal;
    224         info = Utf8StrFmt("blocks: total %lld, free %u ", cbTotal, cbFree);
     234        /** @todo r=bird: Why the need for 'info' here?  LogRelFunc can do the exact
     235         *        same thing without touching the heap.  I don't get what this is
     236         *        about...  There is also excessive log duplication here as well as
     237         *        seemingly unnecessary trailing whitespace. */
     238        Utf8Str info = Utf8StrFmt("blocks: total %RTfoff, free %RTfoff ", cbTotal, cbFree);
    225239        LogRelFunc(("%s \n", info.c_str()));
    226         LogRelFunc(("total space (Kb) %lld (Mb) %lld (Gb) %lld\n",
    227                totalSpace/1024, totalSpace/(1024*1024), totalSpace/(1024*1024*1024)));
    228         LogRelFunc(("total free space (Kb) %lld (Mb) %lld (Gb) %lld\n",
    229                totalFreeSpace/1024, totalFreeSpace/(1024*1024), totalFreeSpace/(1024*1024*1024)));
     240        LogRelFunc(("total space (Kb) %RTfoff (Mb) %RTfoff (Gb) %RTfoff\n", cbTotal/_1K, cbTotal/_1M, cbTotal/_1G));
     241        LogRelFunc(("total free space (Kb) %RTfoff (Mb) %RTfoff (Gb) %RTfoff\n", cbFree/_1K, cbFree/_1M, cbFree/_1G));
    230242
    231243        RTFSPROPERTIES properties;
     
    245257        Utf8Str strSettingsFilePath;
    246258        Bstr bstr_settingsFilePath;
    247         m_pMachine->COMGETTER(SettingsFilePath)(bstr_settingsFilePath.asOutParam());
     259        m_pMachine->COMGETTER(SettingsFilePath)(bstr_settingsFilePath.asOutParam()); /** @todo r=bird: check the status code. */
    248260        strSettingsFilePath = bstr_settingsFilePath;
    249261        strSettingsFilePath.stripFilename();
     
    277289        rc = m_pMachine->COMGETTER(State)(&machineState);
    278290        if (FAILED(rc)) throw rc;
    279         else if (machineState == MachineState_Saved)
     291        if (machineState == MachineState_Saved)
    280292        {
    281293            m_pMachine->COMGETTER(StateFilePath)(bstr_stateFilePath.asOutParam());
     
    340352
    341353        /* The lists llMedias and llSaveStateFiles are filled in the queryMediasForAllStates() */
    342         queryMediasForAllStates(machineList);
     354        queryMediasForAllStates(machineList); /** @todo r=bird: As a rule status codes needs checking every time. */
    343355
    344356        {
     
    429441                {
    430442                    neededFreeSpace += totalLogSize;
    431                     if (totalFreeSpace - neededFreeSpace <= 1024*1024)
     443                    if (cbFree - neededFreeSpace <= _1M)
    432444                    {
    433445                        throw VERR_OUT_OF_RESOURCES;//less than 1Mb free space on the target location
     
    435447
    436448                    fileList_t filesList;
    437                     getFilesList(strFolder, filesList);
     449                    getFilesList(strFolder, filesList); /** @todo r=bird: return code check */
    438450                    cit_t it = filesList.m_list.begin();
    439                     while(it != filesList.m_list.end())
     451                    while (it != filesList.m_list.end())
    440452                    {
    441453                        Utf8Str strFile = it->first.c_str();
     
    467479        LogRelFunc(("Total space needed is %lld bytes\n", neededFreeSpace));
    468480        /* Check a target location on enough room */
    469         if (totalFreeSpace - neededFreeSpace <= 1024*1024)
    470         {
    471             LogRelFunc(("but free space on destination is %lld\n", totalFreeSpace));
     481        if (cbFree - neededFreeSpace <= _1M)
     482        {
     483            LogRelFunc(("but free space on destination is %RTfoff\n", cbFree));
     484            /** @todo r=bird: You're throwing a VBox status code here, but only catching
     485             *        HRESULT.  So, this will go to the caller or someone else up the
     486             *        stack, which is unacceptable throw behaviour. */
    472487            throw VERR_OUT_OF_RESOURCES;//less than 1Mb free space on the target location
    473488        }
    474489
    475490        /* Add step for .vbox machine setting file */
    476         {
     491        { /** @todo what's the scoping for? */
    477492            ++uCount;
    478493            uTotalWeight += 1;
     
    488503        {
    489504            rc = m_pProgress->init(m_pMachine->i_getVirtualBox(),
    490                                  static_cast<IMachine*>(m_pMachine) /* aInitiator */,
    491                                  Bstr(m_pMachine->tr("Moving Machine")).raw(),
    492                                  true /* fCancellable */,
    493                                  uCount,
    494                                  uTotalWeight,
    495                                  Bstr(m_pMachine->tr("Initialize Moving")).raw(),
    496                                  1);
     505                                   static_cast<IMachine*>(m_pMachine) /* aInitiator */,
     506                                   Utf8Str(m_pMachine->tr("Moving Machine")),
     507                                   true /* fCancellable */,
     508                                   uCount,
     509                                   uTotalWeight,
     510                                   Utf8Str(m_pMachine->tr("Initialize Moving")),
     511                                   1);
    497512            if (FAILED(rc))
    498513            {
     
    510525    catch(HRESULT hrc)
    511526    {
     527/** @todo r=bird: Seriously, why throw any error when you can just return
     528 *        them.  This is just copying the thrown message and passing it onto
     529 *        the return statemnt a few lines later.  (The log statemnt doesn't
     530 *        really count as it doesn't log the status.) */
    512531        rc = hrc;
    513532    }
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