Changeset 33898 in vbox for trunk/src/VBox/Frontends/VBoxManage
- Timestamp:
- Nov 9, 2010 1:49:22 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp
r33841 r33898 95 95 " --username <name> --password <password>\n" 96 96 " [--dryrun] [--recursive] [--verbose] [--flags <flags>]\n" 97 "\n" 98 " createdirectory <vmname>|<uuid>\n" 99 " <directory to create on guest>\n" 100 " --username <name> --password <password>\n" 101 " [--parents] [--mode <mode>]\n" 97 102 "\n" 98 103 " updateadditions <vmname>|<uuid>\n" … … 593 598 return VERR_NO_MEMORY; 594 599 } 595 600 596 601 pNode->Node.pPrev = NULL; 597 602 pNode->Node.pNext = NULL; … … 1237 1242 } 1238 1243 1244 static int handleCtrlCreateDirectory(HandlerArg *a) 1245 { 1246 /* 1247 * Check the syntax. We can deduce the correct syntax from the number of 1248 * arguments. 1249 */ 1250 if (a->argc < 2) /* At least the directory we want to create should be present :-). */ 1251 return errorSyntax(USAGE_GUESTCONTROL, "Incorrect parameters"); 1252 1253 Utf8Str Utf8Directory(a->argv[1]); 1254 Utf8Str Utf8UserName; 1255 Utf8Str Utf8Password; 1256 uint32_t uFlags = CreateDirectoryFlag_None; 1257 uint32_t uMode = 0; 1258 bool fVerbose = false; 1259 1260 /* Iterate through all possible commands (if available). */ 1261 bool usageOK = true; 1262 for (int i = 3; usageOK && i < a->argc; i++) 1263 { 1264 if ( !strcmp(a->argv[i], "--username") 1265 || !strcmp(a->argv[i], "--user")) 1266 { 1267 if (i + 1 >= a->argc) 1268 usageOK = false; 1269 else 1270 { 1271 Utf8UserName = a->argv[i + 1]; 1272 ++i; 1273 } 1274 } 1275 else if ( !strcmp(a->argv[i], "--password") 1276 || !strcmp(a->argv[i], "--pwd")) 1277 { 1278 if (i + 1 >= a->argc) 1279 usageOK = false; 1280 else 1281 { 1282 Utf8Password = a->argv[i + 1]; 1283 ++i; 1284 } 1285 } 1286 else if ( !strcmp(a->argv[i], "--parents") 1287 || !strcmp(a->argv[i], "-p")) 1288 { 1289 uFlags |= CreateDirectoryFlag_Parents; 1290 } 1291 else if ( !strcmp(a->argv[i], "--mode") 1292 || !strcmp(a->argv[i], "-m")) 1293 { 1294 if (i + 1 >= a->argc) 1295 usageOK = false; 1296 else 1297 { 1298 uMode = atoi(a->argv[i + 1]); 1299 ++i; 1300 } 1301 } 1302 else if (!strcmp(a->argv[i], "--flags")) 1303 { 1304 if (i + 1 >= a->argc) 1305 usageOK = false; 1306 else 1307 { 1308 /* Nothing to do here yet. */ 1309 ++i; 1310 } 1311 } 1312 /** @todo Add force flag for overwriting existing stuff. */ 1313 else if (!strcmp(a->argv[i], "--verbose")) 1314 fVerbose = true; 1315 else 1316 return errorSyntax(USAGE_GUESTCONTROL, 1317 "Invalid parameter '%s'", Utf8Str(a->argv[i]).c_str()); 1318 } 1319 1320 if (!usageOK) 1321 return errorSyntax(USAGE_GUESTCONTROL, "Incorrect parameters"); 1322 1323 if (Utf8Directory.isEmpty()) 1324 return errorSyntax(USAGE_GUESTCONTROL, 1325 "No directory specified!"); 1326 1327 if (Utf8UserName.isEmpty()) 1328 return errorSyntax(USAGE_GUESTCONTROL, 1329 "No user name specified!"); 1330 1331 /* Lookup VM. */ 1332 ComPtr<IMachine> machine; 1333 /* Assume it's an UUID. */ 1334 HRESULT rc; 1335 CHECK_ERROR(a->virtualBox, FindMachine(Bstr(a->argv[0]).raw(), 1336 machine.asOutParam())); 1337 if (FAILED(rc)) 1338 return 1; 1339 1340 /* Machine is running? */ 1341 MachineState_T machineState; 1342 CHECK_ERROR_RET(machine, COMGETTER(State)(&machineState), 1); 1343 if (machineState != MachineState_Running) 1344 { 1345 RTMsgError("Machine \"%s\" is not running!\n", a->argv[0]); 1346 return 1; 1347 } 1348 1349 /* Open a session for the VM. */ 1350 CHECK_ERROR_RET(machine, LockMachine(a->session, LockType_Shared), 1); 1351 1352 do 1353 { 1354 /* Get the associated console. */ 1355 ComPtr<IConsole> console; 1356 CHECK_ERROR_BREAK(a->session, COMGETTER(Console)(console.asOutParam())); 1357 /* ... and session machine */ 1358 ComPtr<IMachine> sessionMachine; 1359 CHECK_ERROR_BREAK(a->session, COMGETTER(Machine)(sessionMachine.asOutParam())); 1360 1361 ComPtr<IGuest> guest; 1362 CHECK_ERROR_BREAK(console, COMGETTER(Guest)(guest.asOutParam())); 1363 1364 ComPtr<IProgress> progress; 1365 rc = guest->CreateDirectory(Bstr(Utf8Directory).raw(), 1366 Bstr(Utf8UserName).raw(), Bstr(Utf8Password).raw(), 1367 uMode, uFlags, progress.asOutParam()); 1368 if (FAILED(rc)) 1369 { 1370 /* If we got a VBOX_E_IPRT error we handle the error in a more gentle way 1371 * because it contains more accurate info about what went wrong. */ 1372 ErrorInfo info(guest, COM_IIDOF(IGuest)); 1373 if (info.isFullAvailable()) 1374 { 1375 if (rc == VBOX_E_IPRT_ERROR) 1376 RTMsgError("%ls.", info.getText().raw()); 1377 else 1378 RTMsgError("%ls (%Rhrc).", info.getText().raw(), info.getResultCode()); 1379 } 1380 } 1381 else 1382 { 1383 /* Setup signal handling if cancelable. */ 1384 ASSERT(progress); 1385 bool fCanceledAlready = false; 1386 BOOL fCancelable; 1387 HRESULT hrc = progress->COMGETTER(Cancelable)(&fCancelable); 1388 if (FAILED(hrc)) 1389 fCancelable = FALSE; 1390 if (fCancelable) 1391 { 1392 signal(SIGINT, ctrlCopySignalHandler); 1393 #ifdef SIGBREAK 1394 signal(SIGBREAK, ctrlCopySignalHandler); 1395 #endif 1396 } 1397 1398 /* Wait for process to exit ... */ 1399 BOOL fCompleted = FALSE; 1400 BOOL fCanceled = FALSE; 1401 while ( SUCCEEDED(progress->COMGETTER(Completed(&fCompleted))) 1402 && !fCompleted) 1403 { 1404 /* Process async cancelation */ 1405 if (g_fCopyCanceled && !fCanceledAlready) 1406 { 1407 hrc = progress->Cancel(); 1408 if (SUCCEEDED(hrc)) 1409 fCanceledAlready = TRUE; 1410 else 1411 g_fCopyCanceled = false; 1412 } 1413 1414 /* Progress canceled by Main API? */ 1415 if ( SUCCEEDED(progress->COMGETTER(Canceled(&fCanceled))) 1416 && fCanceled) 1417 { 1418 break; 1419 } 1420 } 1421 1422 /* Undo signal handling */ 1423 if (fCancelable) 1424 { 1425 signal(SIGINT, SIG_DFL); 1426 #ifdef SIGBREAK 1427 signal(SIGBREAK, SIG_DFL); 1428 #endif 1429 } 1430 1431 if (fCanceled) 1432 { 1433 //RTPrintf("Copy operation canceled!\n"); 1434 } 1435 else if ( fCompleted 1436 && SUCCEEDED(rc)) 1437 { 1438 LONG iRc = false; 1439 CHECK_ERROR_RET(progress, COMGETTER(ResultCode)(&iRc), rc); 1440 if (FAILED(iRc)) 1441 { 1442 com::ProgressErrorInfo info(progress); 1443 if ( info.isFullAvailable() 1444 || info.isBasicAvailable()) 1445 { 1446 /* If we got a VBOX_E_IPRT error we handle the error in a more gentle way 1447 * because it contains more accurate info about what went wrong. */ 1448 if (info.getResultCode() == VBOX_E_IPRT_ERROR) 1449 RTMsgError("%ls.", info.getText().raw()); 1450 else 1451 { 1452 RTMsgError("Copy operation error details:"); 1453 GluePrintErrorInfo(info); 1454 } 1455 } 1456 } 1457 } 1458 } 1459 1460 a->session->UnlockMachine(); 1461 } while (0); 1462 return SUCCEEDED(rc) ? 0 : 1; 1463 } 1464 1239 1465 static int handleCtrlUpdateAdditions(HandlerArg *a) 1240 1466 { … … 1388 1614 return handleCtrlExecProgram(&arg); 1389 1615 } 1390 else if (!strcmp(a->argv[0], "copyto")) 1616 else if ( !strcmp(a->argv[0], "copyto") 1617 || !strcmp(a->argv[0], "cp")) 1391 1618 { 1392 1619 return handleCtrlCopyTo(&arg); 1620 } 1621 else if ( !strcmp(a->argv[0], "createdirectory") 1622 || !strcmp(a->argv[0], "createdir") 1623 || !strcmp(a->argv[0], "mkdir")) 1624 { 1625 return handleCtrlCreateDirectory(&arg); 1393 1626 } 1394 1627 else if ( !strcmp(a->argv[0], "updateadditions")
Note:
See TracChangeset
for help on using the changeset viewer.