- Timestamp:
- Oct 11, 2013 6:23:11 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/ApplianceImplExport.cpp
r49039 r49047 326 326 if (FAILED(rc)) throw rc; 327 327 328 Utf8Str strTarget VmdkName;328 Utf8Str strTargetImageName; 329 329 Utf8Str strLocation; 330 330 LONG64 llSize = 0; … … 334 334 { 335 335 Bstr bstrLocation; 336 336 337 rc = pMedium->COMGETTER(Location)(bstrLocation.asOutParam()); 337 338 if (FAILED(rc)) throw rc; … … 348 349 if (FAILED(rc)) throw rc; 349 350 350 Bstr bstrBaseName; 351 rc = pBaseMedium->COMGETTER(Name)(bstrBaseName.asOutParam()); 352 if (FAILED(rc)) throw rc; 353 354 Utf8Str strTargetName = Utf8Str(locInfo.strPath).stripPath().stripSuffix(); 355 strTargetVmdkName = Utf8StrFmt("%s-disk%d.vmdk", strTargetName.c_str(), ++pAppliance->m->cDisks); 356 if (strTargetVmdkName.length() > RTTAR_NAME_MAX) 351 Utf8Str strName = Utf8Str(locInfo.strPath).stripPath().stripSuffix(); 352 strTargetImageName = Utf8StrFmt("%s-disk%d.vmdk", strName.c_str(), ++pAppliance->m->cDisks); 353 if (strTargetImageName.length() > RTTAR_NAME_MAX) 357 354 throw setError(VBOX_E_NOT_SUPPORTED, 358 tr("Cannot attach disk '%s' -- file name too long"), strTarget VmdkName.c_str());355 tr("Cannot attach disk '%s' -- file name too long"), strTargetImageName.c_str()); 359 356 360 357 // force reading state, or else size will be returned as 0 … … 369 366 && pMedium) 370 367 { 368 /* 369 * check the minimal rules to grant access to export an image 370 * 1. no host drive CD/DVD image 371 * 2. the image must be accessible and readable 372 * 3. only ISO image is exported 373 */ 374 375 //1. no host drive CD/DVD image 376 BOOL fHostDrive = false; 377 rc = pMedium->COMGETTER(HostDrive)(&fHostDrive); 378 if (FAILED(rc)) throw rc; 379 380 if(fHostDrive) 381 continue; 382 383 //2. the image must be accessible and readable 384 MediumState_T ms; 385 rc = pMedium->RefreshState(&ms); 386 if (FAILED(rc)) throw rc; 387 388 if (ms != MediumState_Created) 389 continue; 390 391 //3. only ISO image is exported 371 392 Bstr bstrLocation; 372 393 rc = pMedium->COMGETTER(Location)(bstrLocation.asOutParam()); 373 394 if (FAILED(rc)) throw rc; 395 374 396 strLocation = bstrLocation; 375 397 376 // find the source's base medium for two things: 377 // 1) we'll use its name to determine the name of the target disk, which is readable, 378 // as opposed to the UUID filename of a differencing image, if pMedium is one 379 // 2) we need the size of the base image so we can give it to addEntry(), and later 380 // on export, the progress will be based on that (and not the diff image) 381 ComPtr<IMedium> pBaseMedium; 382 rc = pMedium->COMGETTER(Base)(pBaseMedium.asOutParam()); 383 // returns pMedium if there are no diff images 384 if (FAILED(rc)) throw rc; 385 386 Bstr bstrBaseName; 387 rc = pBaseMedium->COMGETTER(Name)(bstrBaseName.asOutParam()); 388 if (FAILED(rc)) throw rc; 389 390 Utf8Str strTargetName = Utf8Str(locInfo.strPath).stripPath().stripSuffix(); 391 strTargetVmdkName = Utf8StrFmt("%s-disk%d.iso", strTargetName.c_str(), ++pAppliance->m->cDisks); 392 if (strTargetVmdkName.length() > RTTAR_NAME_MAX) 398 Utf8Str ext = strLocation; 399 ext.assignEx(RTPathSuffix(ext.c_str()));//returns extension with dot (".iso") 400 401 int eq = ext.compare(".iso", Utf8Str::CaseInsensitive); 402 if (eq != 0) 403 continue; 404 405 Utf8Str strName = Utf8Str(locInfo.strPath).stripPath().stripSuffix(); 406 strTargetImageName = Utf8StrFmt("%s-disk%d.iso", strName.c_str(), ++pAppliance->m->cDisks); 407 if (strTargetImageName.length() > RTTAR_NAME_MAX) 393 408 throw setError(VBOX_E_NOT_SUPPORTED, 394 tr("Cannot attach image '%s' -- file name too long"), strTargetVmdkName.c_str()); 395 396 // force reading state, or else size will be returned as 0 397 MediumState_T ms; 398 rc = pBaseMedium->RefreshState(&ms); 399 if (FAILED(rc)) throw rc; 400 401 rc = pBaseMedium->COMGETTER(Size)(&llSize); 409 tr("Cannot attach image '%s' -- file name too long"), strTargetImageName.c_str()); 410 411 rc = pMedium->COMGETTER(Size)(&llSize); 402 412 if (FAILED(rc)) throw rc; 403 413 } … … 469 479 Log(("Adding VirtualSystemDescriptionType_HardDiskImage, disk size: %RI64\n", llSize)); 470 480 pNewDesc->addEntry(VirtualSystemDescriptionType_HardDiskImage, 471 strTarget VmdkName, // disk ID: let's use the name472 strTarget VmdkName, // OVF value:481 strTargetImageName, // disk ID: let's use the name 482 strTargetImageName, // OVF value: 473 483 strLocation, // vbox value: media path 474 484 (uint32_t)(llSize / _1M), … … 477 487 478 488 case DeviceType_DVD: 479 { 480 if (!pMedium) 481 break; 482 483 /* get info about whether medium is a real drive/device or not */ 484 BOOL fHostDrive = false; 485 rc = pMedium->COMGETTER(HostDrive)(&fHostDrive); 486 487 /* Only virtual CD-ROM is exported, the real device/drive isn't exported */ 488 if(!fHostDrive) 489 pNewDesc->addEntry(VirtualSystemDescriptionType_CDROM, 490 strTargetVmdkName, // disk ID 491 strTargetVmdkName, // OVF value 492 strLocation, // vbox value 493 (uint32_t)(llSize / _1M),// ulSize 494 strExtra); 495 } 489 Log(("Adding VirtualSystemDescriptionType_CDROM, disk size: %RI64\n", llSize)); 490 pNewDesc->addEntry(VirtualSystemDescriptionType_CDROM, 491 strTargetImageName, // disk ID 492 strTargetImageName, // OVF value 493 strLocation, // vbox value 494 (uint32_t)(llSize / _1M),// ulSize 495 strExtra); 496 496 break; 497 497 … … 1813 1813 // fill the machine config 1814 1814 vsdescThis->m->pMachine->copyMachineDataToSettings(*pConfig); 1815 1815 1816 // write the machine config to the vbox:Machine element 1816 1817 pConfig->buildMachineXML(*pelmVBoxMachine, … … 2131 2132 waitForAsyncProgress(pTask->pProgress, pProgress3); 2132 2133 } 2133 else 2134 else//pDiskEntry->type == VirtualSystemDescriptionType_CDROM 2134 2135 { 2135 2136 //copy/clone CD/DVD image
Note:
See TracChangeset
for help on using the changeset viewer.