VirtualBox

Changeset 85731 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Aug 12, 2020 8:26:52 PM (4 years ago)
Author:
vboxsync
Message:

Main/HostUpdateImpl.cpp: updateCheck() must validate the bugref:7983updateCheck

File:
1 edited

Legend:

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

    r85730 r85731  
    7474    /** Smart pointer to the progress object for this job. */
    7575    ComObjPtr<Progress> m_ptrProgress;
    76     HRESULT m_rc; /**< Not really used for anything, at the moment. */
     76    HRESULT m_rc; /**< Not really used for anything outside i_updateCheckTask, at the moment. */
    7777
    7878    friend class HostUpdate;  // allow member functions access to private data
     
    403403    else
    404404    {
     405        /** @todo r=bird: trusting the server reply too much here! */
    405406        m_updateNeeded = TRUE;
    406407        m_updateVersion = lstHttpReply.at(0).c_str();
     
    419420{
    420421    LogFlowFuncEnter();
    421 
    422422    AutoCaller autoCaller(this);
    423     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    424 
    425     if (pTask->m_checkType == UpdateCheckType_VirtualBox)
    426         pTask->m_rc = i_checkForVBoxUpdate();
    427 
     423    HRESULT hrc = autoCaller.rc();
     424    if (SUCCEEDED(hrc))
     425    {
     426        try
     427        {
     428            switch (pTask->m_checkType)
     429            {
     430                case UpdateCheckType_VirtualBox:
     431                    hrc = i_checkForVBoxUpdate();
     432                    break;
    428433#if 0
    429     else if (pTask->m_checkType == UpdateCheckType_ExtensionPack)
    430         ;
    431     else if (pTask->m_checkType == UpdateCheckType_GuestAdditions)
    432         ;
    433     else
    434         assert();
     434                case UpdateCheckType_ExtensionPack:
     435                    hrc = i_checkForExtPackUpdate();
     436                    break;
     437
     438                case UpdateCheckType_GuestAdditions:
     439                    hrc = i_checkForGuestAdditionsUpdate();
     440                    break;
    435441#endif
     442                default:
     443                    hrc = setError(E_FAIL, tr("Update check type %d is not implemented"), pTask->m_checkType);
     444                    break;
     445            }
     446        }
     447        catch (...)
     448        {
     449            AssertFailed();
     450            hrc = E_UNEXPECTED;
     451        }
     452    }
    436453
    437454    if (!pTask->m_ptrProgress.isNull())
    438         pTask->m_ptrProgress->i_notifyComplete(pTask->m_rc);
    439 
    440     LogFlowFunc(("rc=%Rhrc\n", pTask->m_rc));
     455        pTask->m_ptrProgress->i_notifyComplete(hrc);
     456
     457    LogFlowFunc(("rc=%Rhrc\n", hrc));
    441458    LogFlowFuncLeave();
    442 
    443     return pTask->m_rc;
     459    return pTask->m_rc = hrc;
    444460}
    445461
     
    495511                                ComPtr<IProgress> &aProgress)
    496512{
    497     HRESULT rc;
     513    /* Validate input */
     514    switch (aCheckType)
     515    {
     516        case UpdateCheckType_VirtualBox:
     517            break;
     518        case UpdateCheckType_ExtensionPack:
     519            return setError(E_NOTIMPL, tr("UpdateCheckType::ExtensionPack is not implemented"));
     520        case UpdateCheckType_GuestAdditions:
     521            return setError(E_NOTIMPL, tr("UpdateCheckType::GuestAdditions is not implemented"));
     522        default:
     523            return setError(E_INVALIDARG, tr("Invalid aCheckType value %d"), aCheckType);
     524    }
    498525
    499526    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     
    501528    // Check whether VirtualBox updates have been disabled before spawning the task thread.
    502529    ComPtr<ISystemProperties> pSystemProperties;
    503     rc = mVirtualBox->COMGETTER(SystemProperties)(pSystemProperties.asOutParam());
     530    HRESULT rc = mVirtualBox->COMGETTER(SystemProperties)(pSystemProperties.asOutParam());
    504531    if (FAILED(rc))
    505532        return setErrorVrc(rc, tr("%s: IVirtualBox::systemProperties() failed: %Rrc"), __FUNCTION__, rc);
     
    510537        return setErrorVrc(rc, tr("%s: retrieving ISystemProperties::VBoxUpdateEnabled failed: %Rrc"), __FUNCTION__, rc);
    511538
     539    /** @todo r=bird: Not sure if this makes sense, it should at least have a
     540     * better status code and a proper error message.  Also, isn't this really
     541     * something the caller should check?  Presumably the caller already check
     542     * whther this was a good time to perform an update check (i.e. the configured
     543     * time has elapsed since last check) ...
     544     *
     545     * It would make sense to allow performing a one-off update check even if the
     546     * automatic update checking is disabled, wouldn't it? */
    512547    if (!fVBoxUpdateEnabled)
    513548        return E_NOTIMPL;
     
    516551    rc = pProgress.createObject();
    517552    if (FAILED(rc))
    518     {
    519553        return rc;
    520     }
    521554
    522555    rc = pProgress->init(mVirtualBox,
     
    525558                         TRUE /* aCancelable */);
    526559    if (FAILED(rc))
    527     {
    528560        return rc;
    529     }
    530561
    531562    /* initialize the worker task */
     
    534565    pTask = NULL;
    535566    if (FAILED(rc))
    536     {
    537567        return rc;
    538     }
    539568
    540569    rc = pProgress.queryInterfaceTo(aProgress.asOutParam());
     
    547576    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    548577
    549     if (m_updateVersion.isNotEmpty())
    550     {
    551         aUpdateVersion = m_updateVersion;
    552     }
     578    aUpdateVersion = m_updateVersion;
    553579
    554580    return S_OK;
     
    559585    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    560586
    561     if (m_updateURL.isNotEmpty())
    562     {
    563         aUpdateURL = m_updateURL;
    564     }
     587    aUpdateURL = m_updateURL;
    565588
    566589    return S_OK;
     
    586609        return rc;
    587610
     611    /*
     612     * Is update checking enabled?
     613     */
    588614    BOOL fVBoxUpdateEnabled;
    589615    rc = pSystemProperties->COMGETTER(VBoxUpdateEnabled)(&fVBoxUpdateEnabled);
     
    597623    }
    598624
     625    /*
     626     * When was the last update?
     627     */
    599628    Bstr strVBoxUpdateLastCheckDate;
    600629    rc = pSystemProperties->COMGETTER(VBoxUpdateLastCheckDate)(strVBoxUpdateLastCheckDate.asOutParam());
     
    617646    }
    618647
     648    /*
     649     * Compare last update with how often we are supposed to check for updates.
     650     */
    619651    ULONG uVBoxUpdateFrequency = 0;  // value in days
    620652    rc = pSystemProperties->COMGETTER(VBoxUpdateFrequency)(&uVBoxUpdateFrequency);
     
    624656    if (!uVBoxUpdateFrequency)
    625657    {
     658        /* Consider config (enable, 0 day interval) as checking once but never again.
     659           We've already check since we've got a date. */
    626660        *aUpdateCheckNeeded = false;
    627661        return S_OK;
    628662    }
    629 
    630     ULONG ulSecondsInXDays = uVBoxUpdateFrequency /* in days */ * 24 /* hours */ * 60 /* minutes */ * 60 /* seconds */;
    631     RTTIMESPEC TimeNow;
    632     (void) RTTimeNow(&TimeNow);
    633     PRTTIMESPEC TimeDiff = RTTimeSpecSub(&TimeNow, &LastCheckTime);
    634 
    635     LogRelFunc(("Checking if seconds since last check (%ld) >= Number of seconds in %lu day%s (%ld)\n",
    636         RTTimeSpecGetSeconds(TimeDiff), uVBoxUpdateFrequency, uVBoxUpdateFrequency > 1 ? "s" : "", ulSecondsInXDays));
    637 
    638     if (RTTimeSpecGetSeconds(TimeDiff) >= ulSecondsInXDays)
     663    uint64_t const cSecsInXDays = uVBoxUpdateFrequency * RT_SEC_1DAY_64;
     664
     665    RTTIMESPEC TimeDiff;
     666    RTTimeSpecSub(RTTimeNow(&TimeDiff), &LastCheckTime);
     667
     668    LogRelFunc(("Checking if seconds since last check (%lld) >= Number of seconds in %lu day%s (%lld)\n",
     669                RTTimeSpecGetSeconds(&TimeDiff), uVBoxUpdateFrequency, uVBoxUpdateFrequency > 1 ? "s" : "", cSecsInXDays));
     670
     671    if (RTTimeSpecGetSeconds(&TimeDiff) >= (int64_t)cSecsInXDays)
    639672        *aUpdateCheckNeeded = true;
    640673
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