VirtualBox

Changeset 71250 in vbox for trunk/src/VBox/Main/src-client


Ignore:
Timestamp:
Mar 7, 2018 11:02:14 AM (7 years ago)
Author:
vboxsync
Message:

Guest Control/GuestDirectoryImpl: Factored out the implementations of read() and close() into internal methods, various small cleanups.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/GuestDirectoryImpl.cpp

    r71173 r71250  
    204204    }
    205205
    206 #ifdef DEBUG
    207206    LogFlowFuncLeaveRC(vrc);
    208 #endif
    209207    return vrc;
    210208}
     
    244242}
    245243
     244/**
     245 * Closes this guest directory and removes it from the
     246 * guest session's directory list.
     247 *
     248 * @return VBox status code.
     249 * @param  pGuestRc             Where to store the guest result code in case VERR_GSTCTL_GUEST_ERROR is returned.
     250 */
     251int GuestDirectory::i_closeInternal(int *pGuestRc)
     252{
     253    AssertPtrReturn(pGuestRc, VERR_INVALID_POINTER);
     254
     255    int rc = mData.mProcessTool.i_terminate(30 * 1000 /* 30s timeout */, pGuestRc);
     256    if (RT_FAILURE(rc))
     257        return rc;
     258
     259    AssertPtr(mSession);
     260    int rc2 = mSession->i_directoryRemoveFromList(this);
     261    if (RT_SUCCESS(rc))
     262        rc = rc2;
     263
     264    LogFlowThisFunc(("Returning rc=%Rrc\n", rc));
     265    return rc;
     266}
     267
     268/**
     269 * Reads the next directory entry.
     270 *
     271 * @return VBox status code. Will return VERR_NO_MORE_FILES if no more entries are available.
     272 * @param  fsObjInfo            Where to store the read directory entry.
     273 * @param  pGuestRc             Where to store the guest result code in case VERR_GSTCTL_GUEST_ERROR is returned.
     274 */
     275int GuestDirectory::i_readInternal(ComObjPtr<GuestFsObjInfo> &fsObjInfo, int *pGuestRc)
     276{
     277    AssertPtrReturn(pGuestRc, VERR_INVALID_POINTER);
     278
     279    /* Create the FS info object. */
     280    HRESULT hr = fsObjInfo.createObject();
     281    if (FAILED(hr))
     282        return VERR_COM_UNEXPECTED;
     283
     284    GuestProcessStreamBlock curBlock;
     285    int rc = mData.mProcessTool.i_waitEx(GUESTPROCESSTOOL_FLAG_STDOUT_BLOCK,
     286                                         &curBlock, pGuestRc);
     287    if (RT_SUCCESS(rc))
     288    {
     289        /*
     290         * Note: The guest process can still be around to serve the next
     291         *       upcoming stream block next time.
     292         */
     293        if (!mData.mProcessTool.i_isRunning())
     294            rc = mData.mProcessTool.i_terminatedOk();
     295
     296        if (RT_SUCCESS(rc))
     297        {
     298            if (curBlock.GetCount()) /* Did we get content? */
     299            {
     300                GuestFsObjData objData;
     301                rc = objData.FromLs(curBlock);
     302                if (RT_SUCCESS(rc))
     303                {
     304                   rc = fsObjInfo->init(objData);
     305                }
     306                else
     307                    rc = VERR_PATH_NOT_FOUND;
     308            }
     309            else
     310            {
     311                /* Nothing to read anymore. Tell the caller. */
     312                rc = VERR_NO_MORE_FILES;
     313            }
     314        }
     315    }
     316
     317    LogFlowThisFunc(("Returning rc=%Rrc\n", rc));
     318    return rc;
     319}
     320
    246321/* static */
    247322HRESULT GuestDirectory::i_setErrorExternal(VirtualBoxBase *pInterface, int guestRc)
     
    264339    HRESULT hr = S_OK;
    265340
    266     int guestRc;
    267     int rc = mData.mProcessTool.i_terminate(30 * 1000, &guestRc);
     341    int rcGuest;
     342    int rc = i_closeInternal(&rcGuest);
    268343    if (RT_FAILURE(rc))
    269344    {
     
    271346        {
    272347            case VERR_GSTCTL_GUEST_ERROR:
    273                 hr = GuestProcess::i_setErrorExternal(this, guestRc);
     348                hr = GuestDirectory::i_setErrorExternal(this, rcGuest);
    274349                break;
    275350
     
    287362    }
    288363
    289     AssertPtr(mSession);
    290     int rc2 = mSession->i_directoryRemoveFromList(this);
    291     if (RT_SUCCESS(rc))
    292         rc = rc2;
    293 
    294     LogFlowThisFunc(("Returning rc=%Rrc\n", rc));
    295364    return hr;
    296365}
     
    303372    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    304373
    305     GuestProcessStreamBlock curBlock;
    306     int guestRc;
    307 
    308     int rc = mData.mProcessTool.i_waitEx(GUESTPROCESSTOOL_FLAG_STDOUT_BLOCK,
    309                                          &curBlock, &guestRc);
    310 
    311     /*
    312      * Note: The guest process can still be around to serve the next
    313      *       upcoming stream block next time.
    314      */
    315     if (   RT_SUCCESS(rc)
    316         && !mData.mProcessTool.i_isRunning())
    317     {
    318         rc = mData.mProcessTool.i_terminatedOk();
    319     }
    320 
     374    HRESULT hr = S_OK;
     375
     376    ComObjPtr<GuestFsObjInfo> fsObjInfo; int rcGuest;
     377    int rc = i_readInternal(fsObjInfo, &rcGuest);
    321378    if (RT_SUCCESS(rc))
    322379    {
    323         if (curBlock.GetCount()) /* Did we get content? */
    324         {
    325             GuestFsObjData objData;
    326             rc = objData.FromLs(curBlock);
    327             if (RT_FAILURE(rc))
    328                 rc = VERR_PATH_NOT_FOUND;
    329 
    330             if (RT_SUCCESS(rc))
    331             {
    332                 /* Create the object. */
    333                 ComObjPtr<GuestFsObjInfo> pFsObjInfo;
    334                 HRESULT hr2 = pFsObjInfo.createObject();
    335                 if (FAILED(hr2))
    336                     rc = VERR_COM_UNEXPECTED;
    337 
    338                 if (RT_SUCCESS(rc))
    339                     rc = pFsObjInfo->init(objData);
    340 
    341                 if (RT_SUCCESS(rc))
    342                 {
    343                     /* Return info object to the caller. */
    344                     hr2 = pFsObjInfo.queryInterfaceTo(aObjInfo.asOutParam());
    345                     if (FAILED(hr2))
    346                         rc = VERR_COM_UNEXPECTED;
    347                 }
    348             }
    349         }
    350         else
    351         {
    352             /* Nothing to read anymore. Tell the caller. */
    353             rc = VERR_NO_MORE_FILES;
    354         }
    355     }
    356 
    357     HRESULT hr = S_OK;
    358 
    359     if (RT_FAILURE(rc)) /** @todo Add more errors here. */
     380        /* Return info object to the caller. */
     381        hr = fsObjInfo.queryInterfaceTo(aObjInfo.asOutParam());
     382    }
     383    else
    360384    {
    361385        switch (rc)
    362386        {
    363387            case VERR_GSTCTL_GUEST_ERROR:
    364                 hr = GuestProcess::i_setErrorExternal(this, guestRc);
     388                hr = GuestDirectory::i_setErrorExternal(this, rcGuest);
    365389                break;
    366390
     
    377401            case VERR_NO_MORE_FILES:
    378402                /* See SDK reference. */
    379                 hr = setError(VBOX_E_OBJECT_NOT_FOUND, tr("No more entries for directory \"%s\""),
     403                hr = setError(VBOX_E_OBJECT_NOT_FOUND, tr("Reading directory \"%s\" failed: No more entries"),
    380404                              mData.mOpenInfo.mPath.c_str());
    381405                break;
    382406
    383407            default:
    384                 hr = setError(VBOX_E_IPRT_ERROR, tr("Error while reading directory \"%s\": %Rrc\n"),
     408                hr = setError(VBOX_E_IPRT_ERROR, tr("Reading directory \"%s\" returned error: %Rrc\n"),
    385409                              mData.mOpenInfo.mPath.c_str(), rc);
    386410                break;
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