Changeset 42618 in vbox for trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp
- Timestamp:
- Aug 6, 2012 1:31:38 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp
r42611 r42618 1928 1928 } 1929 1929 1930 STDMETHODIMP GuestSession::FileRemove(IN_BSTR aPath, LONG *aReturnCode) 1931 { 1932 #ifndef VBOX_WITH_GUEST_CONTROL 1933 ReturnComNotImplemented(); 1934 #else 1935 LogFlowThisFuncEnter(); 1936 1937 if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0')) 1938 return setError(E_INVALIDARG, tr("No file to remove specified")); 1939 1940 AutoCaller autoCaller(this); 1941 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 1942 1943 GuestProcessStartupInfo procInfo; 1944 GuestProcessStream streamOut; 1945 int rc = VINF_SUCCESS; 1946 1947 try /* Can this be done without exceptions? */ 1948 { 1949 Utf8Str strPath(aPath); 1950 procInfo.mName = Utf8StrFmt(tr("Removing file \"%s\"", 1951 strPath.c_str())); 1952 procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_RM); 1953 /* Construct arguments. */ 1954 procInfo.mArguments.push_back(Utf8Str("--machinereadable")); 1955 procInfo.mArguments.push_back(Bstr(aPath)); /* The directory we want to create. */ 1956 } 1957 catch (...) 1958 { 1959 return E_OUTOFMEMORY; 1960 } 1961 1962 ComObjPtr<GuestProcess> pProcess; 1963 rc = processCreateExInteral(procInfo, pProcess); 1964 if (RT_SUCCESS(rc)) 1965 { 1966 GuestProcessWaitResult waitRes; 1967 BYTE byBuf[_64K]; 1968 size_t cbRead; 1969 1970 for (;;) 1971 { 1972 rc = pProcess->waitFor(ProcessWaitForFlag_StdOut, 1973 30 * 1000 /* Timeout */, waitRes); 1974 if ( RT_FAILURE(rc) 1975 || waitRes.mResult != ProcessWaitResult_StdOut) 1976 { 1977 break; 1978 } 1979 1980 rc = pProcess->readData(OUTPUT_HANDLE_ID_STDOUT, sizeof(byBuf), 1981 30 * 1000 /* Timeout */, byBuf, sizeof(byBuf), 1982 &cbRead); 1983 if (RT_FAILURE(rc)) 1984 break; 1985 1986 rc = streamOut.AddData(byBuf, cbRead); 1987 if (RT_FAILURE(rc)) 1988 break; 1989 } 1990 1991 LogFlowThisFunc(("rc=%Rrc, cbRead=%RU32, cbStreamOut=%RU32\n", 1992 rc, cbRead, streamOut.GetSize())); 1993 } 1994 1995 if (RT_FAILURE(rc)) 1996 return setError(E_FAIL, tr("Error while deleting file: %Rrc"), rc); 1997 if (!streamOut.GetSize()) 1998 return setError(E_FAIL, tr("No return code after deleting file")); 1999 GuestProcessStreamBlock streamBlock; 2000 rc = streamOut.ParseBlock(streamBlock); 2001 if (RT_SUCCESS(rc)) 2002 { 2003 streamBlock.GetString("fname"); 2004 int64_t i64rc; 2005 if (RT_FAILURE(streamBlock.GetInt64Ex("rc", &i64rc))) 2006 return setError(E_FAIL, tr("No return code after deleting file")); 2007 *aReturnCode = (LONG)i64rc; 2008 } 2009 else 2010 return setError(E_FAIL, tr("Error while getting return code from deleting file: %Rrc"), rc); 2011 return S_OK; 2012 #endif /* VBOX_WITH_GUEST_CONTROL */ 2013 } 2014 1930 2015 STDMETHODIMP GuestSession::FileOpen(IN_BSTR aPath, IN_BSTR aOpenMode, IN_BSTR aDisposition, ULONG aCreationMode, LONG64 aOffset, IGuestFile **aFile) 1931 2016 {
Note:
See TracChangeset
for help on using the changeset viewer.