VirtualBox

Changeset 42691 in vbox


Ignore:
Timestamp:
Aug 8, 2012 7:15:02 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
79895
Message:

Main/GuestCtrl: split off the implementation of FileRemove into fileRemoveInternal.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/GuestSessionImpl.h

    r42673 r42691  
    208208    int                     dispatchToProcess(uint32_t uContextID, uint32_t uFunction, void *pvData, size_t cbData);
    209209    int                     fileClose(ComObjPtr<GuestFile> pFile);
     210    int                     fileRemoveInternal(Utf8Str strPath, int *prc);
    210211    int                     fileOpenInternal(const Utf8Str &strPath, const Utf8Str &strOpenMode, const Utf8Str &strDisposition,
    211212                                             uint32_t uCreationMode, int64_t iOffset, ComObjPtr<GuestFile> &pFile);
  • trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp

    r42682 r42691  
    11721172}
    11731173
     1174/**
     1175 * Implementation of FileRemove().  Can throw an exception due to the use of
     1176 * Utf8Str, Utf8StrFmt and std::vector near the beginning (and others?).  The
     1177 * caller should catch this.  On success, *prc will be set to the return code
     1178 * of the delete operation to distinguish between API and command failure.
     1179 */
     1180int GuestSession::fileRemoveInternal(Utf8Str strPath, int *prc)
     1181{
     1182    GuestProcessStartupInfo procInfo;
     1183    GuestProcessStream      streamOut;
     1184    int rc = VINF_SUCCESS;
     1185
     1186    AssertPtrReturn(prc, VERR_INVALID_POINTER);
     1187    procInfo.mName    = Utf8StrFmt(tr("Removing file \"%s\"",
     1188                                   strPath.c_str()));
     1189    procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_RM);
     1190    procInfo.mFlags   =   ProcessCreateFlag_Hidden
     1191                        | ProcessCreateFlag_WaitForStdOut;
     1192    /* Construct arguments. */
     1193    procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
     1194    procInfo.mArguments.push_back(strPath); /* The directory we want to create. */
     1195
     1196    ComObjPtr<GuestProcess> pProcess;
     1197    rc = processCreateExInteral(procInfo, pProcess);
     1198    if (RT_SUCCESS(rc))
     1199        rc = pProcess->startProcess();
     1200    if (RT_SUCCESS(rc))
     1201    {
     1202        GuestProcessWaitResult waitRes;
     1203        BYTE byBuf[_64K];
     1204        size_t cbRead;
     1205
     1206        for (;;)
     1207        {
     1208            rc = pProcess->waitFor(ProcessWaitForFlag_StdOut,
     1209                                   30 * 1000 /* Timeout */, waitRes);
     1210            if (   RT_FAILURE(rc)
     1211                || waitRes.mResult == ProcessWaitResult_Terminate
     1212                || waitRes.mResult == ProcessWaitResult_Error
     1213                || waitRes.mResult == ProcessWaitResult_Timeout)
     1214            {
     1215                break;
     1216            }
     1217
     1218            rc = pProcess->readData(OUTPUT_HANDLE_ID_STDOUT, sizeof(byBuf),
     1219                                    30 * 1000 /* Timeout */, byBuf, sizeof(byBuf),
     1220                                    &cbRead);
     1221            if (RT_FAILURE(rc))
     1222                break;
     1223
     1224            if (cbRead)
     1225            {
     1226                rc = streamOut.AddData(byBuf, cbRead);
     1227                if (RT_FAILURE(rc))
     1228                    break;
     1229            }
     1230        }
     1231
     1232        LogFlowThisFunc(("rc=%Rrc, cbRead=%RU32, cbStreamOut=%RU32\n",
     1233                         rc, cbRead, streamOut.GetSize()));
     1234    }
     1235    else
     1236        LogThisFunc(("Error starting delete tool on guest: %Rrc\n", rc));
     1237    if (RT_FAILURE(rc))
     1238        LogThisFunc(("Error running delete tool on guest: %Rrc\n", rc));
     1239    else if (!streamOut.GetSize())
     1240    {
     1241        LogThisFunc(("No return code after deleting file"));
     1242        rc = VERR_NO_DATA;
     1243    }
     1244    if (RT_SUCCESS(rc))
     1245    {
     1246        GuestProcessStreamBlock streamBlock;
     1247        int64_t i64rc;
     1248        rc = streamOut.ParseBlock(streamBlock);
     1249        streamBlock.GetString("fname");
     1250        rc = streamBlock.GetInt64Ex("rc", &i64rc);
     1251        if (RT_SUCCESS(rc))
     1252            *prc = (int)i64rc;
     1253    }
     1254    else
     1255        Log(("Error getting return code from deleting file: %Rrc\n", rc));
     1256    return rc;
     1257}
     1258
    11741259int GuestSession::fileOpenInternal(const Utf8Str &strPath, const Utf8Str &strOpenMode, const Utf8Str &strDisposition,
    11751260                                   uint32_t uCreationMode, int64_t iOffset, ComObjPtr<GuestFile> &pFile)
     
    21512236    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    21522237
    2153     GuestProcessStartupInfo procInfo;
    2154     GuestProcessStream      streamOut;
    2155     int rc = VINF_SUCCESS;
    2156 
    21572238    try  /* Can this be done without exceptions? */
    21582239    {
    2159         Utf8Str strPath(aPath);
    2160         procInfo.mName    = Utf8StrFmt(tr("Removing file \"%s\"",
    2161                                        strPath.c_str()));
    2162         procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_RM);
    2163         procInfo.mFlags   =   ProcessCreateFlag_Hidden
    2164                             | ProcessCreateFlag_WaitForStdOut;
    2165         /* Construct arguments. */
    2166         procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
    2167         procInfo.mArguments.push_back(Bstr(aPath)); /* The directory we want to create. */
     2240        int rc2;
     2241        int rc = fileRemoveInternal(Utf8Str(aPath), &rc2);
     2242        if (RT_FAILURE((rc)))
     2243            return setError(E_FAIL,
     2244                            tr("Internal error deleting file: %Rrc"), rc);
     2245        else if (RT_FAILURE((rc2)))
     2246            return setError(VBOX_E_IPRT_ERROR,
     2247                            tr("File deletion on guest returned: %Rrc"), rc2);
    21682248    }
    21692249    catch (...)
     
    21712251        return E_OUTOFMEMORY;
    21722252    }
    2173 
    2174     ComObjPtr<GuestProcess> pProcess;
    2175     rc = processCreateExInteral(procInfo, pProcess);
    2176     if (RT_SUCCESS(rc))
    2177         rc = pProcess->startProcess();
    2178     if (RT_SUCCESS(rc))
    2179     {
    2180         GuestProcessWaitResult waitRes;
    2181         BYTE byBuf[_64K];
    2182         size_t cbRead;
    2183 
    2184         for (;;)
    2185         {
    2186             rc = pProcess->waitFor(ProcessWaitForFlag_StdOut,
    2187                                    30 * 1000 /* Timeout */, waitRes);
    2188             if (   RT_FAILURE(rc)
    2189                 || waitRes.mResult == ProcessWaitResult_Terminate
    2190                 || waitRes.mResult == ProcessWaitResult_Error
    2191                 || waitRes.mResult == ProcessWaitResult_Timeout)
    2192             {
    2193                 break;
    2194             }
    2195 
    2196             rc = pProcess->readData(OUTPUT_HANDLE_ID_STDOUT, sizeof(byBuf),
    2197                                     30 * 1000 /* Timeout */, byBuf, sizeof(byBuf),
    2198                                     &cbRead);
    2199             if (RT_FAILURE(rc))
    2200                 break;
    2201 
    2202             if (cbRead)
    2203             {
    2204                 rc = streamOut.AddData(byBuf, cbRead);
    2205                 if (RT_FAILURE(rc))
    2206                     break;
    2207             }
    2208         }
    2209 
    2210         LogFlowThisFunc(("rc=%Rrc, cbRead=%RU32, cbStreamOut=%RU32\n",
    2211                          rc, cbRead, streamOut.GetSize()));
    2212     }
    2213     else
    2214         return setError(E_FAIL, tr("Error while starting delete tool on guest: %Rrc"), rc);
    2215     if (RT_FAILURE(rc))
    2216         return setError(E_FAIL, tr("Error while running delete tool on guest: %Rrc"), rc);
    2217     if (!streamOut.GetSize())
    2218         return setError(E_FAIL, tr("No return code after deleting file"));
    2219     GuestProcessStreamBlock streamBlock;
    2220     rc = streamOut.ParseBlock(streamBlock);
    2221     if (RT_SUCCESS(rc))
    2222     {
    2223         streamBlock.GetString("fname");
    2224         int64_t i64rc;
    2225         if (RT_FAILURE(streamBlock.GetInt64Ex("rc", &i64rc)))
    2226             return setError(E_FAIL, tr("No return code after deleting file"));
    2227         if (RT_FAILURE((int)i64rc))
    2228             return setError(VBOX_E_IPRT_ERROR, tr("File deletion failed: %Rrc"), rc);
    2229     }
    2230     else
    2231         return setError(E_FAIL, tr("Error while getting return code from deleting file: %Rrc"), rc);
    22322253    return S_OK;
    22332254#endif /* VBOX_WITH_GUEST_CONTROL */
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