Changeset 33898 in vbox for trunk/src/VBox/Main/GuestImpl.cpp
- Timestamp:
- Nov 9, 2010 1:49:22 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/GuestImpl.cpp
r33776 r33898 2316 2316 if (RTStrPrintf(szOutput, sizeof(szOutput), "--output=%s", Utf8Dest.c_str())) 2317 2317 { 2318 /* 2319 * Normalize path slashes, based on the detected guest. 2320 */ 2321 Utf8Str osType = mData.mOSTypeId; 2322 if ( osType.contains("Microsoft", Utf8Str::CaseInsensitive) 2323 || osType.contains("Windows", Utf8Str::CaseInsensitive)) 2324 { 2325 /* We have a Windows guest. */ 2326 RTPathChangeToDosSlashes(szOutput, true /* Force conversion. */); 2327 } 2328 else /* ... or something which isn't from Redmond ... */ 2329 { 2330 RTPathChangeToUnixSlashes(szOutput, true /* Force conversion. */); 2331 } 2332 2318 2333 args.push_back(Bstr(VBOXSERVICE_TOOL_CAT).raw()); /* The actual (internal) tool to use (as argv[0]). */ 2319 2334 args.push_back(Bstr(szOutput).raw()); /* We want to write a file ... */ … … 2326 2341 if (SUCCEEDED(rc)) 2327 2342 { 2328 LogRel(("Copying file \"%s\" to guest \"%s\" ...\n",2329 Utf8Source.c_str(), Utf8Dest.c_str() ));2343 LogRel(("Copying file \"%s\" to guest \"%s\" (%u bytes) ...\n", 2344 Utf8Source.c_str(), Utf8Dest.c_str(), cbSize)); 2330 2345 /* 2331 2346 * Okay, since we gathered all stuff we need until now to start the … … 2389 2404 } 2390 2405 RTFileClose(fileSource); 2406 } 2407 } 2408 } 2409 catch (std::bad_alloc &) 2410 { 2411 rc = E_OUTOFMEMORY; 2412 } 2413 return rc; 2414 #endif /* VBOX_WITH_GUEST_CONTROL */ 2415 } 2416 2417 STDMETHODIMP Guest::CreateDirectory(IN_BSTR aDirectory, 2418 IN_BSTR aUserName, IN_BSTR aPassword, 2419 ULONG aMode, ULONG aFlags, 2420 IProgress **aProgress) 2421 { 2422 #ifndef VBOX_WITH_GUEST_CONTROL 2423 ReturnComNotImplemented(); 2424 #else /* VBOX_WITH_GUEST_CONTROL */ 2425 using namespace guestControl; 2426 2427 CheckComArgStrNotEmptyOrNull(aDirectory); 2428 2429 /* Do not allow anonymous executions (with system rights). */ 2430 if (RT_UNLIKELY((aUserName) == NULL || *(aUserName) == '\0')) 2431 return setError(E_INVALIDARG, tr("No user name specified")); 2432 2433 LogRel(("Creating guest directory \"%s\" as user \"%s\" ...\n", 2434 Utf8Str(aDirectory).c_str(), Utf8Str(aUserName).c_str())); 2435 2436 return createDirectoryInternal(aDirectory, 2437 aUserName, aPassword, 2438 aMode, aFlags, aProgress, NULL /* rc */); 2439 #endif 2440 } 2441 2442 STDMETHODIMP Guest::createDirectoryInternal(IN_BSTR aDirectory, 2443 IN_BSTR aUserName, IN_BSTR aPassword, 2444 ULONG aMode, ULONG aFlags, 2445 IProgress **aProgress, int *pRC) 2446 { 2447 #ifndef VBOX_WITH_GUEST_CONTROL 2448 ReturnComNotImplemented(); 2449 #else /* VBOX_WITH_GUEST_CONTROL */ 2450 using namespace guestControl; 2451 2452 CheckComArgStrNotEmptyOrNull(aDirectory); 2453 CheckComArgOutPointerValid(aProgress); 2454 2455 AutoCaller autoCaller(this); 2456 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 2457 2458 /* Validate flags. */ 2459 if (aFlags != CreateDirectoryFlag_None) 2460 { 2461 if (!(aFlags & CreateDirectoryFlag_Parents)) 2462 { 2463 return setError(E_INVALIDARG, tr("Unknown flags (%#x)"), aFlags); 2464 } 2465 } 2466 2467 HRESULT rc = S_OK; 2468 2469 try 2470 { 2471 Utf8Str Utf8Directory(aDirectory); 2472 Utf8Str Utf8UserName(aUserName); 2473 Utf8Str Utf8Password(aPassword); 2474 2475 com::SafeArray<IN_BSTR> args; 2476 com::SafeArray<IN_BSTR> env; 2477 2478 /* 2479 * Prepare tool command line. 2480 */ 2481 args.push_back(Bstr(VBOXSERVICE_TOOL_CAT).raw()); /* The actual (internal) tool to use (as argv[0]). */ 2482 if (aFlags & CreateDirectoryFlag_Parents) 2483 args.push_back(Bstr("--parents").raw()); /* We also want to create the parent directories. */ 2484 if (aMode > 0) 2485 { 2486 args.push_back(Bstr("--mode").raw()); /* Set the creation mode. */ 2487 2488 char szMode[16]; 2489 if (RTStrPrintf(szMode, sizeof(szMode), "%o", aMode)) 2490 args.push_back(Bstr(szMode).raw()); 2491 else 2492 rc = setError(VBOX_E_IPRT_ERROR, tr("Error preparing command line")); 2493 } 2494 args.push_back(Bstr(Utf8Directory).raw()); /* The directory we want to create. */ 2495 2496 /* 2497 * Execute guest process. 2498 */ 2499 ComPtr<IProgress> execProgress; 2500 ULONG uPID; 2501 if (SUCCEEDED(rc)) 2502 { 2503 rc = ExecuteProcess(Bstr(VBOXSERVICE_TOOL_CAT).raw(), 2504 ExecuteProcessFlag_None, 2505 ComSafeArrayAsInParam(args), 2506 ComSafeArrayAsInParam(env), 2507 Bstr(Utf8UserName).raw(), 2508 Bstr(Utf8Password).raw(), 2509 5 * 1000 /* Wait 5s for getting the process started. */, 2510 &uPID, execProgress.asOutParam()); 2511 } 2512 2513 if (SUCCEEDED(rc)) 2514 { 2515 /* Wait for process to exit ... */ 2516 BOOL fCompleted = FALSE; 2517 BOOL fCanceled = FALSE; 2518 2519 while ( SUCCEEDED(execProgress->COMGETTER(Completed(&fCompleted))) 2520 && !fCompleted) 2521 { 2522 /* Progress canceled by Main API? */ 2523 if ( SUCCEEDED(execProgress->COMGETTER(Canceled(&fCanceled))) 2524 && fCanceled) 2525 { 2526 break; 2527 } 2528 } 2529 2530 if (SUCCEEDED(rc)) 2531 { 2532 /* Return the progress to the caller. */ 2533 execProgress.queryInterfaceTo(aProgress); 2391 2534 } 2392 2535 }
Note:
See TracChangeset
for help on using the changeset viewer.