Changeset 35757 in vbox for trunk/src/VBox/Main/src-client
- Timestamp:
- Jan 28, 2011 12:51:37 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 69718
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-client/ConsoleImpl.cpp
r35755 r35757 1384 1384 strHostPath, 1385 1385 writable, 1386 autoMount); 1386 autoMount, 1387 false /* fFailOnError */); 1387 1388 AssertComRCReturn(rc, VERR_INTERNAL_ERROR); 1388 1389 … … 2851 2852 CheckComArgStrNotEmptyOrNull(aHostPath); 2852 2853 2854 LogFlowThisFunc(("Entering for '%ls' -> '%ls'\n", aName, aHostPath)); 2855 2853 2856 AutoCaller autoCaller(this); 2854 2857 if (FAILED(autoCaller.rc())) return autoCaller.rc(); … … 2877 2880 if (SUCCEEDED(rc)) 2878 2881 return setError(VBOX_E_FILE_ERROR, 2879 tr("Shared folder named '%s' already exists"),2880 strName.c_str());2882 tr("Shared folder named '%s' already exists"), 2883 strName.c_str()); 2881 2884 2882 2885 pSharedFolder.createObject(); 2883 rc = pSharedFolder->init(this, strName, strHostPath, aWritable, aAutoMount); 2886 rc = pSharedFolder->init(this, 2887 strName, 2888 strHostPath, 2889 aWritable, 2890 aAutoMount, 2891 true /* fFailOnError */); 2884 2892 if (FAILED(rc)) return rc; 2885 2893 … … 2914 2922 fireSharedFolderChangedEvent(mEventSource, Scope_Session); 2915 2923 2924 LogFlowThisFunc(("Leaving for '%ls' -> '%ls'\n", aName, aHostPath)); 2925 2916 2926 return rc; 2917 2927 } … … 2923 2933 AutoCaller autoCaller(this); 2924 2934 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 2935 2936 LogFlowThisFunc(("Entering for '%ls'\n", aName)); 2925 2937 2926 2938 Utf8Str strName(aName); … … 2976 2988 /* notify console callbacks after the folder is removed to the list */ 2977 2989 fireSharedFolderChangedEvent(mEventSource, Scope_Session); 2990 2991 LogFlowThisFunc(("Leaving for '%ls'\n", aName)); 2978 2992 2979 2993 return rc; … … 6195 6209 isWriteLockOnCurrentThread(), E_FAIL); 6196 6210 6211 LogFlowThisFunc(("Entering\n")); 6212 6197 6213 /* protect mpVM (if not NULL) */ 6198 6214 AutoVMCallerQuietWeak autoVMCaller(this); … … 6205 6221 && m_pVMMDev->isShFlActive(); 6206 6222 6207 if (aGlobal) 6208 { 6209 /// @todo grab & process global folders when they are done 6210 } 6211 else 6212 { 6213 SharedFolderDataMap oldFolders; 6214 if (online) 6215 oldFolders = m_mapMachineSharedFolders; 6216 6217 m_mapMachineSharedFolders.clear(); 6218 6219 SafeIfaceArray<ISharedFolder> folders; 6220 rc = mMachine->COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(folders)); 6221 AssertComRCReturnRC(rc); 6222 6223 for (size_t i = 0; i < folders.size(); ++i) 6224 { 6225 ComPtr<ISharedFolder> pSharedFolder = folders[i]; 6226 6227 Bstr bstrName; 6228 Bstr bstrHostPath; 6229 BOOL writable; 6230 BOOL autoMount; 6231 6232 rc = pSharedFolder->COMGETTER(Name)(bstrName.asOutParam()); 6233 if (FAILED(rc)) break; 6234 Utf8Str strName(bstrName); 6235 6236 rc = pSharedFolder->COMGETTER(HostPath)(bstrHostPath.asOutParam()); 6237 if (FAILED(rc)) break; 6238 Utf8Str strHostPath(bstrHostPath); 6239 6240 rc = pSharedFolder->COMGETTER(Writable)(&writable); 6241 if (FAILED(rc)) break; 6242 6243 rc = pSharedFolder->COMGETTER(AutoMount)(&autoMount); 6244 if (FAILED(rc)) break; 6245 6246 m_mapMachineSharedFolders.insert(std::make_pair(strName, 6247 SharedFolderData(strHostPath, writable, autoMount))); 6248 6249 /* send changes to HGCM if the VM is running */ 6250 /// @todo umoeller report errors as runtime warnings through VMSetError 6223 try 6224 { 6225 if (aGlobal) 6226 { 6227 /// @todo grab & process global folders when they are done 6228 } 6229 else 6230 { 6231 SharedFolderDataMap oldFolders; 6232 if (online) 6233 oldFolders = m_mapMachineSharedFolders; 6234 6235 m_mapMachineSharedFolders.clear(); 6236 6237 SafeIfaceArray<ISharedFolder> folders; 6238 rc = mMachine->COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(folders)); 6239 if (FAILED(rc)) throw rc; 6240 6241 for (size_t i = 0; i < folders.size(); ++i) 6242 { 6243 ComPtr<ISharedFolder> pSharedFolder = folders[i]; 6244 6245 Bstr bstrName; 6246 Bstr bstrHostPath; 6247 BOOL writable; 6248 BOOL autoMount; 6249 6250 rc = pSharedFolder->COMGETTER(Name)(bstrName.asOutParam()); 6251 if (FAILED(rc)) throw rc; 6252 Utf8Str strName(bstrName); 6253 6254 rc = pSharedFolder->COMGETTER(HostPath)(bstrHostPath.asOutParam()); 6255 if (FAILED(rc)) throw rc; 6256 Utf8Str strHostPath(bstrHostPath); 6257 6258 rc = pSharedFolder->COMGETTER(Writable)(&writable); 6259 if (FAILED(rc)) throw rc; 6260 6261 rc = pSharedFolder->COMGETTER(AutoMount)(&autoMount); 6262 if (FAILED(rc)) throw rc; 6263 6264 m_mapMachineSharedFolders.insert(std::make_pair(strName, 6265 SharedFolderData(strHostPath, writable, autoMount))); 6266 6267 /* send changes to HGCM if the VM is running */ 6268 /// @todo umoeller report errors as runtime warnings through VMSetError 6269 if (online) 6270 { 6271 SharedFolderDataMap::iterator it = oldFolders.find(strName); 6272 if ( it == oldFolders.end() 6273 || it->second.m_strHostPath != strHostPath) 6274 { 6275 /* a new machine folder is added or 6276 * the existing machine folder is changed */ 6277 if (m_mapSharedFolders.find(strName) != m_mapSharedFolders.end()) 6278 ; /* the console folder exists, nothing to do */ 6279 else 6280 { 6281 /* remove the old machine folder (when changed) 6282 * or the global folder if any (when new) */ 6283 if ( it != oldFolders.end() 6284 || m_mapGlobalSharedFolders.find(strName) != m_mapGlobalSharedFolders.end() 6285 ) 6286 { 6287 rc = removeSharedFolder(strName); 6288 if (FAILED(rc)) throw rc; 6289 } 6290 6291 /* create the new machine folder */ 6292 rc = createSharedFolder(strName, 6293 SharedFolderData(strHostPath, 6294 writable, 6295 autoMount)); 6296 if (FAILED(rc)) throw rc; 6297 } 6298 } 6299 /* forget the processed (or identical) folder */ 6300 if (it != oldFolders.end()) 6301 oldFolders.erase(it); 6302 } 6303 } 6304 6305 /* process outdated (removed) folders */ 6251 6306 if (online) 6252 6307 { 6253 SharedFolderDataMap::iterator it = oldFolders.find(strName); 6254 if ( it == oldFolders.end() 6255 || it->second.m_strHostPath != strHostPath) 6308 for (SharedFolderDataMap::const_iterator it = oldFolders.begin(); 6309 it != oldFolders.end(); ++ it) 6256 6310 { 6257 /* a new machine folder is added or 6258 * the existing machine folder is changed */ 6259 if (m_mapSharedFolders.find(strName) != m_mapSharedFolders.end()) 6311 if (m_mapSharedFolders.find(it->first) != m_mapSharedFolders.end()) 6260 6312 ; /* the console folder exists, nothing to do */ 6261 6313 else 6262 6314 { 6263 /* remove the old machine folder (when changed) 6264 * or the global folder if any (when new) */ 6265 if ( it != oldFolders.end() 6266 || m_mapGlobalSharedFolders.find(strName) != m_mapGlobalSharedFolders.end() 6267 ) 6268 rc = removeSharedFolder(strName); 6269 /* create the new machine folder */ 6270 rc = createSharedFolder(strName, 6271 SharedFolderData(strHostPath, 6272 writable, 6273 autoMount)); 6315 /* remove the outdated machine folder */ 6316 rc = removeSharedFolder(it->first); 6317 if (FAILED(rc)) throw rc; 6318 6319 /* create the global folder if there is any */ 6320 SharedFolderDataMap::const_iterator git = 6321 m_mapGlobalSharedFolders.find(it->first); 6322 if (git != m_mapGlobalSharedFolders.end()) 6323 { 6324 rc = createSharedFolder(git->first, git->second); 6325 if (FAILED(rc)) throw rc; 6326 } 6274 6327 } 6275 6328 } 6276 /* forget the processed (or identical) folder */6277 if (it != oldFolders.end())6278 oldFolders.erase(it);6279 6280 rc = S_OK;6281 6329 } 6282 6330 } 6283 6284 AssertComRCReturnRC(rc); 6285 6286 /* process outdated (removed) folders */ 6287 /// @todo report errors as runtime warnings through VMSetError 6331 } 6332 catch (HRESULT rc2) 6333 { 6288 6334 if (online) 6289 { 6290 for (SharedFolderDataMap::const_iterator it = oldFolders.begin(); 6291 it != oldFolders.end(); ++ it) 6292 { 6293 if (m_mapSharedFolders.find(it->first) != m_mapSharedFolders.end()) 6294 ; /* the console folder exists, nothing to do */ 6295 else 6296 { 6297 /* remove the outdated machine folder */ 6298 rc = removeSharedFolder(it->first); 6299 /* create the global folder if there is any */ 6300 SharedFolderDataMap::const_iterator git = 6301 m_mapGlobalSharedFolders.find(it->first); 6302 if (git != m_mapGlobalSharedFolders.end()) 6303 rc = createSharedFolder(git->first, git->second); 6304 } 6305 } 6306 6307 rc = S_OK; 6308 } 6309 } 6335 setVMRuntimeErrorCallbackF(mpVM, this, 0, "BrokenSharedFolder", 6336 N_("Broken shared folder!")); 6337 } 6338 6339 LogFlowThisFunc(("Leaving\n")); 6310 6340 6311 6341 return rc; … … 6364 6394 6365 6395 Log(("Adding shared folder '%s' -> '%s'\n", strName.c_str(), aData.m_strHostPath.c_str())); 6396 6397 // check whether the path is valid and exists 6398 /* Check whether the path is full (absolute) */ 6399 char hostPathFull[RTPATH_MAX]; 6400 int vrc = RTPathAbsEx(NULL, 6401 aData.m_strHostPath.c_str(), 6402 hostPathFull, 6403 sizeof(hostPathFull)); 6404 if (RT_FAILURE(vrc)) 6405 return setError(E_INVALIDARG, 6406 tr("Invalid shared folder path: '%s' (%Rrc)"), 6407 aData.m_strHostPath.c_str(), vrc); 6408 6409 if (RTPathCompare(aData.m_strHostPath.c_str(), hostPathFull) != 0) 6410 return setError(E_INVALIDARG, 6411 tr("Shared folder path '%s' is not absolute"), 6412 aData.m_strHostPath.c_str()); 6413 if (!RTPathExists(hostPathFull)) 6414 return setError(E_INVALIDARG, 6415 tr("Shared folder path '%s' does not exist on the host"), 6416 aData.m_strHostPath.c_str()); 6417 6418 // now that we know the path is good, give it to HGCM 6366 6419 6367 6420 Bstr bstrName(strName); … … 6411 6464 parms[3].u.uint32 = aData.m_fAutoMount; 6412 6465 6413 intvrc = m_pVMMDev->hgcmHostCall("VBoxSharedFolders",6414 6415 6466 vrc = m_pVMMDev->hgcmHostCall("VBoxSharedFolders", 6467 SHFL_FN_ADD_MAPPING, 6468 SHFL_CPARMS_ADD_MAPPING2, &parms[0]); 6416 6469 RTMemFree(pFolderName); 6417 6470 RTMemFree(pMapName); … … 7830 7883 { 7831 7884 const SharedFolderData &d = it->second; 7832 rc = pConsole->createSharedFolder(it->first, 7833 d); 7834 if (FAILED(rc)) break; 7885 rc = pConsole->createSharedFolder(it->first, d); 7886 if (FAILED(rc)) 7887 { 7888 ErrorInfoKeeper eik; 7889 setVMRuntimeErrorCallbackF(pVM, pConsole, 0, "BrokenSharedFolder", 7890 N_("The shared folder '%s' could not be set up: %ls.\n" 7891 "The shared folder setup will not be complete. It is recommended to power down the virtual machine and " 7892 "fix the shared folder settings while the machine is not running."), 7893 it->first.c_str(), eik.getText().raw()); 7894 break; 7895 } 7835 7896 } 7836 if (FAILED(rc)) break; 7897 if (FAILED(rc)) 7898 rc = S_OK; // do not fail with broken shared folders 7837 7899 7838 7900 /* enter the lock again */
Note:
See TracChangeset
for help on using the changeset viewer.