Changeset 15556 in vbox for trunk/src/VBox/Frontends/VBoxManage
- Timestamp:
- Dec 15, 2008 10:31:49 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 41058
- Location:
- trunk/src/VBox/Frontends/VBoxManage
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp
r15492 r15556 530 530 { 531 531 RTPrintf("VBoxManage clonehd <uuid>|<filename> <outputfile>\n" 532 " [-format VDI|VMDK|VHD|RAW|<other>]\n" 533 " [-remember]\n" 532 534 "\n"); 533 535 } -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp
r15529 r15556 314 314 ComPtr<IVirtualBox> virtualBox, ComPtr<ISession> session) 315 315 { 316 #if 1 317 RTPrintf("Error: Clone hard disk operation is temporarily unavailable!\n"); 318 return 1; 319 #else 320 /// @todo NEWMEDIA use IHardDisk2::cloneTo/flattenTo (not yet implemented) 316 Bstr src, dst; 317 Bstr format; 318 bool remember = false; 319 321 320 HRESULT rc; 322 321 323 /* source hard disk and target path */ 324 if (argc != 2) 325 return errorSyntax(USAGE_CLONEHD, "Incorrect number of parameters"); 322 /* Parse the arguments. */ 323 for (int i = 0; i < argc; i++) 324 { 325 if (strcmp(argv[i], "-format") == 0) 326 { 327 if (argc <= i + 1) 328 { 329 return errorArgument("Missing argument to '%s'", argv[i]); 330 } 331 i++; 332 format = argv[i]; 333 } 334 else if (strcmp(argv[i], "-remember") == 0 || 335 strcmp(argv[i], "-register") == 0 /* backward compatiblity */) 336 { 337 remember = true; 338 } 339 else if (src.isEmpty()) 340 { 341 src = argv[i]; 342 } 343 else if (dst.isEmpty()) 344 { 345 dst = argv[i]; 346 } 347 else 348 { 349 return errorSyntax(USAGE_CLONEHD, "Invalid parameter '%s'", Utf8Str(argv[i]).raw()); 350 } 351 } 352 353 if (src.isEmpty()) 354 return errorSyntax(USAGE_CLONEHD, "Mandatory UUID or input file parameter missing"); 355 if (dst.isEmpty()) 356 return errorSyntax(USAGE_CLONEHD, "Mandatory output file parameter missing"); 357 358 ComPtr<IHardDisk2> srcDisk; 359 ComPtr<IHardDisk2> dstDisk; 360 bool unknown = false; 326 361 327 362 /* first guess is that it's a UUID */ 328 363 Guid uuid(argv[0]); 329 ComPtr<IHardDisk2> hardDisk; 330 rc = virtualBox->GetHardDisk2(uuid, hardDisk.asOutParam()); 331 if (!hardDisk) 332 { 333 /* not successful? Then it must be a filename */ 334 CHECK_ERROR(virtualBox, OpenHardDisk2(Bstr(argv[0]), hardDisk.asOutParam())); 335 } 336 if (hardDisk) 337 { 364 rc = virtualBox->GetHardDisk2(uuid, srcDisk.asOutParam()); 365 /* no? then it must be a filename */ 366 if (FAILED (rc)) 367 { 368 rc = virtualBox->FindHardDisk2(src, srcDisk.asOutParam()); 369 /* no? well, then it's an unkwnown image */ 370 if (FAILED (rc)) 371 { 372 CHECK_ERROR(virtualBox, OpenHardDisk2(src, srcDisk.asOutParam())); 373 if (SUCCEEDED (rc)) 374 { 375 unknown = true; 376 } 377 } 378 } 379 380 do 381 { 382 if (!SUCCEEDED(rc)) 383 break; 384 385 if (format.isEmpty()) 386 { 387 /* get the format of the source hard disk */ 388 CHECK_ERROR_BREAK(srcDisk, COMGETTER(Format) (format.asOutParam())); 389 } 390 391 CHECK_ERROR_BREAK(virtualBox, CreateHardDisk2(format, dst, dstDisk.asOutParam())); 392 338 393 ComPtr<IProgress> progress; 339 CHECK_ERROR(hardDisk, CloneToImage(Bstr(argv[1]), hardDisk.asOutParam(), progress.asOutParam())); 340 if (SUCCEEDED(rc)) 341 { 342 showProgress(progress); 343 progress->COMGETTER(ResultCode)(&rc); 344 if (FAILED(rc)) 345 { 346 com::ProgressErrorInfo info(progress); 347 if (info.isBasicAvailable()) 348 { 349 RTPrintf("Error: failed to clone disk image. Error message: %lS\n", info.getText().raw()); 350 } 351 else 352 { 353 RTPrintf("Error: failed to clone disk image. No error message available!\n"); 354 } 355 } 356 } 357 } 394 CHECK_ERROR_BREAK(srcDisk, CloneTo(dstDisk, progress.asOutParam())); 395 396 showProgress(progress); 397 progress->COMGETTER(ResultCode)(&rc); 398 if (FAILED(rc)) 399 { 400 com::ProgressErrorInfo info(progress); 401 if (info.isBasicAvailable()) 402 RTPrintf("Error: failed to clone hard disk. Error message: %lS\n", info.getText().raw()); 403 else 404 RTPrintf("Error: failed to clone hard disk. No error message available!\n"); 405 break; 406 } 407 408 CHECK_ERROR_BREAK(dstDisk, COMGETTER(Id)(uuid.asOutParam())); 409 410 RTPrintf("Clone hard disk created in format '%ls'. UUID: %s\n", 411 format.raw(), uuid.toString().raw()); 412 } 413 while (0); 414 415 if (!remember && !dstDisk.isNull()) 416 { 417 /* forget the created clone */ 418 dstDisk->Close(); 419 } 420 421 if (unknown) 422 { 423 /* close the unknown hard disk to forget it again */ 424 srcDisk->Close(); 425 } 426 358 427 return SUCCEEDED(rc) ? 0 : 1; 359 #endif360 428 } 361 429
Note:
See TracChangeset
for help on using the changeset viewer.