- 時間撮記:
- 2013-10-31 下午04:40:46 (11 年 以前)
- 檔案:
-
- 修改 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/Main/src-client/GuestDirectoryImpl.cpp
r47627 r49349 59 59 ///////////////////////////////////////////////////////////////////////////// 60 60 61 int GuestDirectory::init(GuestSession *aSession, 62 const Utf8Str &strPath, const Utf8Str &strFilter, uint32_t uFlags) 63 { 64 LogFlowThisFunc(("strPath=%s, strFilter=%s, uFlags=%x\n", 65 strPath.c_str(), strFilter.c_str(), uFlags)); 61 int GuestDirectory::init(Console *pConsole, GuestSession *pSession, 62 ULONG uDirID, const GuestDirectoryOpenInfo &openInfo) 63 { 64 LogFlowThisFunc(("pConsole=%p, pSession=%p, uDirID=%RU32, strPath=%s, strFilter=%s, uFlags=%x\n", 65 pConsole, pSession, uDirID, openInfo.mPath.c_str(), openInfo.mFilter.c_str(), 66 openInfo.mFlags)); 67 68 AssertPtrReturn(pConsole, VERR_INVALID_POINTER); 69 AssertPtrReturn(pSession, VERR_INVALID_POINTER); 66 70 67 71 /* Enclose the state transition NotReady->InInit->Ready. */ … … 69 73 AssertReturn(autoInitSpan.isOk(), E_FAIL); 70 74 71 mData.mSession = aSession; 72 mData.mName = strPath; 73 mData.mFilter = strFilter; 74 mData.mFlags = uFlags; 75 76 /* Start the directory process on the guest. */ 77 GuestProcessStartupInfo procInfo; 78 procInfo.mName = Utf8StrFmt(tr("Reading directory \"%s\"", strPath.c_str())); 79 procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_LS); 80 procInfo.mTimeoutMS = 5 * 60 * 1000; /* 5 minutes timeout. */ 81 procInfo.mFlags = ProcessCreateFlag_WaitForStdOut; 82 83 procInfo.mArguments.push_back(Utf8Str("--machinereadable")); 84 /* We want the long output format which contains all the object details. */ 85 procInfo.mArguments.push_back(Utf8Str("-l")); 75 #ifndef VBOX_WITH_GUEST_CONTROL 76 autoInitSpan.setSucceeded(); 77 return VINF_SUCCESS; 78 #else 79 int vrc = bindToSession(pConsole, pSession, uDirID /* Object ID */); 80 if (RT_SUCCESS(vrc)) 81 { 82 mSession = pSession; 83 84 mData.mID = uDirID; 85 mData.mOpenInfo = openInfo; 86 } 87 88 if (RT_SUCCESS(vrc)) 89 { 90 /* Start the directory process on the guest. */ 91 GuestProcessStartupInfo procInfo; 92 procInfo.mName = Utf8StrFmt(tr("Reading directory \"%s\"", openInfo.mPath.c_str())); 93 procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_LS); 94 procInfo.mTimeoutMS = 5 * 60 * 1000; /* 5 minutes timeout. */ 95 procInfo.mFlags = ProcessCreateFlag_WaitForStdOut; 96 97 procInfo.mArguments.push_back(Utf8Str("--machinereadable")); 98 /* We want the long output format which contains all the object details. */ 99 procInfo.mArguments.push_back(Utf8Str("-l")); 86 100 #if 0 /* Flags are not supported yet. */ 87 if (uFlags & DirectoryOpenFlag_NoSymlinks)88 procInfo.mArguments.push_back(Utf8Str("--nosymlinks")); /** @todo What does GNU here? */101 if (uFlags & DirectoryOpenFlag_NoSymlinks) 102 procInfo.mArguments.push_back(Utf8Str("--nosymlinks")); /** @todo What does GNU here? */ 89 103 #endif 90 /** @todo Recursion support? */ 91 procInfo.mArguments.push_back(strPath); /* The directory we want to open. */ 92 93 /* 94 * Start the process asynchronously and keep it around so that we can use 95 * it later in subsequent read() calls. 96 * Note: No guest rc available because operation is asynchronous. 97 */ 98 int rc = mData.mProcessTool.Init(mData.mSession, procInfo, 99 true /* Async */, NULL /* Guest rc */); 100 if (RT_SUCCESS(rc)) 104 /** @todo Recursion support? */ 105 procInfo.mArguments.push_back(openInfo.mPath); /* The directory we want to open. */ 106 107 /* 108 * Start the process asynchronously and keep it around so that we can use 109 * it later in subsequent read() calls. 110 * Note: No guest rc available because operation is asynchronous. 111 */ 112 vrc = mData.mProcessTool.Init(mSession, procInfo, 113 true /* Async */, NULL /* Guest rc */); 114 } 115 116 if (RT_SUCCESS(vrc)) 101 117 { 102 118 /* Confirm a successful initialization when it's the case. */ 103 119 autoInitSpan.setSucceeded(); 104 return rc; 105 } 106 107 autoInitSpan.setFailed(); 108 return rc; 120 return vrc; 121 } 122 else 123 autoInitSpan.setFailed(); 124 125 return vrc; 126 #endif /* VBOX_WITH_GUEST_CONTROL */ 109 127 } 110 128 … … 139 157 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 140 158 141 mData.m Name.cloneTo(aName);159 mData.mOpenInfo.mPath.cloneTo(aName); 142 160 143 161 return S_OK; … … 155 173 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 156 174 157 mData.m Filter.cloneTo(aFilter);175 mData.mOpenInfo.mFilter.cloneTo(aFilter); 158 176 159 177 return S_OK; … … 162 180 // private methods 163 181 ///////////////////////////////////////////////////////////////////////////// 182 183 int GuestDirectory::callbackDispatcher(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb) 184 { 185 AssertPtrReturn(pCbCtx, VERR_INVALID_POINTER); 186 AssertPtrReturn(pSvcCb, VERR_INVALID_POINTER); 187 188 LogFlowThisFunc(("strPath=%s, uContextID=%RU32, uFunction=%RU32, pSvcCb=%p\n", 189 mData.mOpenInfo.mPath.c_str(), pCbCtx->uContextID, pCbCtx->uFunction, pSvcCb)); 190 191 int vrc; 192 switch (pCbCtx->uFunction) 193 { 194 case GUEST_DIR_NOTIFY: 195 { 196 int idx = 1; /* Current parameter index. */ 197 CALLBACKDATA_DIR_NOTIFY dataCb; 198 /* pSvcCb->mpaParms[0] always contains the context ID. */ 199 pSvcCb->mpaParms[idx++].getUInt32(&dataCb.uType); 200 pSvcCb->mpaParms[idx++].getUInt32(&dataCb.rc); 201 202 int guestRc = (int)dataCb.rc; /* uint32_t vs. int. */ 203 204 LogFlowFunc(("uType=%RU32, guestRc=%Rrc\n", 205 dataCb.uType, guestRc)); 206 207 switch (dataCb.uType) 208 { 209 /* Nothing here yet, nothing to dispatch further. */ 210 211 default: 212 vrc = VERR_NOT_SUPPORTED; 213 break; 214 } 215 break; 216 } 217 218 default: 219 /* Silently ignore not implemented functions. */ 220 vrc = VERR_NOT_SUPPORTED; 221 break; 222 } 223 224 #ifdef DEBUG 225 LogFlowFuncLeaveRC(vrc); 226 #endif 227 return vrc; 228 } 229 230 /* static */ 231 Utf8Str GuestDirectory::guestErrorToString(int guestRc) 232 { 233 Utf8Str strError; 234 235 /** @todo pData->u32Flags: int vs. uint32 -- IPRT errors are *negative* !!! */ 236 switch (guestRc) 237 { 238 case VERR_DIR_NOT_EMPTY: 239 strError += Utf8StrFmt("Directoy is not empty"); 240 break; 241 242 default: 243 strError += Utf8StrFmt("%Rrc", guestRc); 244 break; 245 } 246 247 return strError; 248 } 249 250 /* static */ 251 HRESULT GuestDirectory::setErrorExternal(VirtualBoxBase *pInterface, int guestRc) 252 { 253 AssertPtr(pInterface); 254 AssertMsg(RT_FAILURE(guestRc), ("Guest rc does not indicate a failure when setting error\n")); 255 256 return pInterface->setError(VBOX_E_IPRT_ERROR, GuestDirectory::guestErrorToString(guestRc).c_str()); 257 } 164 258 165 259 // implementation of public methods … … 176 270 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 177 271 178 AssertPtr(m Data.mSession);179 int rc = m Data.mSession->directoryRemoveFromList(this);272 AssertPtr(mSession); 273 int rc = mSession->directoryRemoveFromList(this); 180 274 AssertRC(rc); 181 275 … … 188 282 switch (rc) 189 283 { 190 case VERR_GSTCTL_GUEST_ERROR:284 case VERR_GSTCTL_GUEST_ERROR: 191 285 hr = GuestProcess::setErrorExternal(this, guestRc); 192 286 break; … … 200 294 hr = setError(VBOX_E_IPRT_ERROR, 201 295 tr("Terminating open guest directory \"%s\" failed: %Rrc"), 202 mData.m Name.c_str(), rc);296 mData.mOpenInfo.mPath.c_str(), rc); 203 297 break; 204 298 } … … 293 387 case VERR_ACCESS_DENIED: 294 388 hr = setError(VBOX_E_IPRT_ERROR, tr("Reading directory \"%s\" failed: Unable to read / access denied"), 295 mData.m Name.c_str());389 mData.mOpenInfo.mPath.c_str()); 296 390 break; 297 391 298 392 case VERR_PATH_NOT_FOUND: 299 393 hr = setError(VBOX_E_IPRT_ERROR, tr("Reading directory \"%s\" failed: Path not found"), 300 mData.m Name.c_str());394 mData.mOpenInfo.mPath.c_str()); 301 395 break; 302 396 … … 304 398 /* See SDK reference. */ 305 399 hr = setError(VBOX_E_OBJECT_NOT_FOUND, tr("No more entries for directory \"%s\""), 306 mData.m Name.c_str());400 mData.mOpenInfo.mPath.c_str()); 307 401 break; 308 402 309 403 default: 310 404 hr = setError(VBOX_E_IPRT_ERROR, tr("Error while reading directory \"%s\": %Rrc\n"), 311 mData.m Name.c_str(), rc);405 mData.mOpenInfo.mPath.c_str(), rc); 312 406 break; 313 407 }
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器