Changeset 72476 in vbox for trunk/src/VBox/Main/src-server
- Timestamp:
- Jun 7, 2018 1:49:48 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 122961
- Location:
- trunk/src/VBox/Main/src-server
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/ApplianceImpl.cpp
r70217 r72476 954 954 } 955 955 956 HRESULT Appliance::i_searchUniqueDiskImageFilePath( Utf8Str&aName) const956 HRESULT Appliance::i_searchUniqueDiskImageFilePath(const Utf8Str &aMachineFolder, Utf8Str &aName) const 957 957 { 958 958 IMedium *harddisk = NULL; 959 959 char *tmpName = RTStrDup(aName.c_str()); 960 char *tmpAbsName = RTPathAbsExDup(aMachineFolder.c_str(), tmpName); 960 961 int i = 1; 961 962 /* Check if the file exists or if a file with this path is registered 962 963 * already */ 963 964 /** @todo Maybe too cost-intensive; try to find a lighter way */ 964 while ( RTPathExists(tmp Name)965 || mVirtualBox->OpenMedium(Bstr(tmp Name).raw(), DeviceType_HardDisk, AccessMode_ReadWrite,965 while ( RTPathExists(tmpAbsName) 966 || mVirtualBox->OpenMedium(Bstr(tmpAbsName).raw(), DeviceType_HardDisk, AccessMode_ReadWrite, 966 967 FALSE /* fForceNewUuid */, &harddisk) != VBOX_E_OBJECT_NOT_FOUND) 967 968 { 968 RTStrFree(tmp Name);969 RTStrFree(tmpAbsName); 969 970 char *tmpDir = RTStrDup(aName.c_str()); 970 RTPathStripFilename(tmpDir); ;971 RTPathStripFilename(tmpDir); 971 972 char *tmpFile = RTStrDup(RTPathFilename(aName.c_str())); 972 973 RTPathStripSuffix(tmpFile); 973 974 const char *pszTmpSuff = RTPathSuffix(aName.c_str()); 974 975 RTStrAPrintf(&tmpName, "%s%c%s_%d%s", tmpDir, RTPATH_DELIMITER, tmpFile, i, pszTmpSuff); 976 tmpAbsName = RTPathAbsExDup(aMachineFolder.c_str(), tmpName); 975 977 RTStrFree(tmpFile); 976 978 RTStrFree(tmpDir); -
trunk/src/VBox/Main/src-server/ApplianceImplExport.cpp
r67273 r72476 1918 1918 // fill the machine config 1919 1919 vsdescThis->m->pMachine->i_copyMachineDataToSettings(*pConfig); 1920 pConfig->machineUserData.strName = strVMName; 1920 1921 1921 1922 // Apply export tweaks to machine settings -
trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp
r72201 r72476 200 200 201 201 /* Based on the VM name, create a target machine path. */ 202 Bstr bstr MachineFilename;202 Bstr bstrSettingsFilename; 203 203 rc = mVirtualBox->ComposeMachineFilename(Bstr(nameVBox).raw(), 204 204 NULL /* aGroup */, 205 205 NULL /* aCreateFlags */, 206 206 NULL /* aBaseFolder */, 207 bstr MachineFilename.asOutParam());207 bstrSettingsFilename.asOutParam()); 208 208 if (FAILED(rc)) throw rc; 209 /* Determine the machine folder from that */ 210 Utf8Str strMachineFolder = Utf8Str(bstrMachineFilename).stripFilename(); 209 Utf8Str strMachineFolder(bstrSettingsFilename); 210 strMachineFolder.stripFilename(); 211 212 #if 1 213 /* The import logic should work exactly the same whether the 214 * following 3 items are present or not, but of course it may have 215 * an influence on the exact presentation of the import settings 216 * of an API client. */ 217 Utf8Str strSettingsFilename(bstrSettingsFilename); 218 pNewDesc->i_addEntry(VirtualSystemDescriptionType_SettingsFile, 219 "", 220 "" /* no direct OVF correspondence */, 221 strSettingsFilename); 222 Utf8Str strBaseFolder; 223 mVirtualBox->i_getDefaultMachineFolder(strBaseFolder); 224 pNewDesc->i_addEntry(VirtualSystemDescriptionType_BaseFolder, 225 "", 226 "" /* no direct OVF correspondence */, 227 strBaseFolder); 228 pNewDesc->i_addEntry(VirtualSystemDescriptionType_PrimaryGroup, 229 "", 230 "" /* no direct OVF correspondence */, 231 ""); 232 #endif 211 233 212 234 /* VM Product */ … … 643 665 // - we need a url specifier for the vdi format 644 666 667 Utf8Str strFilename = di.strHref; 645 668 if (vdf.compare("VMDK", Utf8Str::CaseInsensitive) == 0) 646 669 { 647 670 /* If the href is empty use the VM name as filename */ 648 Utf8Str strFilename = di.strHref;649 671 if (!strFilename.length()) 650 672 strFilename = Utf8StrFmt("%s.vmdk", hd.strDiskId.c_str()); 651 652 Utf8Str strTargetPath = Utf8Str(strMachineFolder);653 strTargetPath.append(RTPATH_DELIMITER).append(di.strHref);654 /*655 * Remove last extension from the file name if the file is compressed656 */657 if (di.strCompression.compare("gzip", Utf8Str::CaseInsensitive)==0)658 {659 strTargetPath.stripSuffix();660 }661 662 i_searchUniqueDiskImageFilePath(strTargetPath);663 664 /* find the description for the hard disk controller665 * that has the same ID as hd.idController */666 const VirtualSystemDescriptionEntry *pController;667 if (!(pController = pNewDesc->i_findControllerFromID(hd.idController)))668 throw setError(E_FAIL,669 tr("Cannot find hard disk controller with OVF instance ID %RI32 "670 "to which disk \"%s\" should be attached"),671 hd.idController,672 di.strHref.c_str());673 674 /* controller to attach to, and the bus within that controller */675 Utf8StrFmt strExtraConfig("controller=%RI16;channel=%RI16",676 pController->ulIndex,677 hd.ulAddressOnParent);678 pNewDesc->i_addEntry(VirtualSystemDescriptionType_HardDiskImage,679 hd.strDiskId,680 di.strHref,681 strTargetPath,682 di.ulSuggestedSizeMB,683 strExtraConfig);684 673 } 685 674 else if (vdf.compare("RAW", Utf8Str::CaseInsensitive) == 0) 686 675 { 687 676 /* If the href is empty use the VM name as filename */ 688 Utf8Str strFilename = di.strHref;689 677 if (!strFilename.length()) 690 678 strFilename = Utf8StrFmt("%s.iso", hd.strDiskId.c_str()); 691 692 Utf8Str strTargetPath = Utf8Str(strMachineFolder)693 .append(RTPATH_DELIMITER)694 .append(di.strHref);695 /*696 * Remove last extension from the file name if the file is compressed697 */698 if (di.strCompression.compare("gzip", Utf8Str::CaseInsensitive)==0)699 {700 strTargetPath.stripSuffix();701 }702 703 i_searchUniqueDiskImageFilePath(strTargetPath);704 705 /* find the description for the hard disk controller706 * that has the same ID as hd.idController */707 const VirtualSystemDescriptionEntry *pController;708 if (!(pController = pNewDesc->i_findControllerFromID(hd.idController)))709 throw setError(E_FAIL,710 tr("Cannot find disk controller with OVF instance ID %RI32 "711 "to which disk \"%s\" should be attached"),712 hd.idController,713 di.strHref.c_str());714 715 /* controller to attach to, and the bus within that controller */716 Utf8StrFmt strExtraConfig("controller=%RI16;channel=%RI16",717 pController->ulIndex,718 hd.ulAddressOnParent);719 pNewDesc->i_addEntry(VirtualSystemDescriptionType_HardDiskImage,720 hd.strDiskId,721 di.strHref,722 strTargetPath,723 di.ulSuggestedSizeMB,724 strExtraConfig);725 679 } 726 680 else … … 729 683 di.strHref.c_str(), 730 684 di.strFormat.c_str()); 685 686 /* 687 * Remove last extension from the file name if the file is compressed 688 */ 689 if (di.strCompression.compare("gzip", Utf8Str::CaseInsensitive)==0) 690 strFilename.stripSuffix(); 691 692 i_searchUniqueDiskImageFilePath(strMachineFolder, strFilename); 693 694 /* find the description for the hard disk controller 695 * that has the same ID as hd.idController */ 696 const VirtualSystemDescriptionEntry *pController; 697 if (!(pController = pNewDesc->i_findControllerFromID(hd.idController))) 698 throw setError(E_FAIL, 699 tr("Cannot find hard disk controller with OVF instance ID %RI32 " 700 "to which disk \"%s\" should be attached"), 701 hd.idController, 702 di.strHref.c_str()); 703 704 /* controller to attach to, and the bus within that controller */ 705 Utf8StrFmt strExtraConfig("controller=%RI16;channel=%RI16", 706 pController->ulIndex, 707 hd.ulAddressOnParent); 708 pNewDesc->i_addEntry(VirtualSystemDescriptionType_HardDiskImage, 709 hd.strDiskId, 710 di.strHref, 711 strFilename, 712 di.ulSuggestedSizeMB, 713 strExtraConfig); 731 714 } 732 715 } … … 2383 2366 * 2384 2367 * @param di ovfreader.cpp structure describing the disk image from the OVF that is to be imported 2385 * @param str TargetPath Where to create the target image.2368 * @param strDstPath Where to create the target image. 2386 2369 * @param pTargetHD out: The newly created target disk. This also gets pushed on stack.llHardDisksCreated for cleanup. 2387 2370 * @param stack 2388 2371 */ 2389 2372 void Appliance::i_importOneDiskImage(const ovf::DiskImage &di, 2390 Utf8Str *pStrDstPath,2373 const Utf8Str &strDstPath, 2391 2374 ComObjPtr<Medium> &pTargetHD, 2392 2375 ImportStack &stack) 2393 2376 { 2377 char *pszAbsDstPath = RTPathAbsExDup(stack.strMachineFolder.c_str(), 2378 strDstPath.c_str()); 2379 Utf8Str strAbsDstPath(pszAbsDstPath); 2380 RTStrFree(pszAbsDstPath); 2381 pszAbsDstPath = NULL; 2382 2394 2383 ComObjPtr<Progress> pProgress; 2395 2384 pProgress.createObject(); … … 2397 2386 static_cast<IAppliance*>(this), 2398 2387 BstrFmt(tr("Creating medium '%s'"), 2399 pStrDstPath->c_str()).raw(),2388 strAbsDstPath.c_str()).raw(), 2400 2389 TRUE); 2401 2390 if (FAILED(rc)) throw rc; … … 2418 2407 } 2419 2408 2420 /* First of all check if the path is an UUID. If so, the user like to2421 * import the disk into an existing path. This is useful for iSCSI for2422 * example. */2409 /* First of all check if the original (non-absolute) destination path is 2410 * a valid hard disk UUID. If so, the user wants to import the disk into 2411 * an existing path. This is useful for iSCSI for example. */ 2423 2412 RTUUID uuid; 2424 int vrc = RTUuidFromStr(&uuid, pStrDstPath->c_str());2413 int vrc = RTUuidFromStr(&uuid, strDstPath.c_str()); 2425 2414 if (vrc == VINF_SUCCESS) 2426 2415 { … … 2442 2431 ULONG lCabs = 0; 2443 2432 2444 char *pszSuff = RTPathSuffix( pStrDstPath->c_str());2433 char *pszSuff = RTPathSuffix(strAbsDstPath.c_str()); 2445 2434 if (pszSuff != NULL) 2446 2435 { … … 2472 2461 strTrgFormat = "vdi"; 2473 2462 trgFormat = pSysProps->i_mediumFormatFromExtension(strTrgFormat); 2474 *pStrDstPath = pStrDstPath->stripSuffix();2475 *pStrDstPath = pStrDstPath->append(".");2476 *pStrDstPath = pStrDstPath->append(strTrgFormat.c_str());2463 strAbsDstPath.stripSuffix(); 2464 strAbsDstPath.append("."); 2465 strAbsDstPath.append(strTrgFormat.c_str()); 2477 2466 } 2478 2467 … … 2492 2481 throw setError(VBOX_E_NOT_SUPPORTED, 2493 2482 tr("Could not find a valid medium format for the target disk '%s'"), 2494 pStrDstPath->c_str());2483 strAbsDstPath.c_str()); 2495 2484 } 2496 2485 else … … 2498 2487 throw setError(VBOX_E_FILE_ERROR, 2499 2488 tr("The target disk '%s' has no extension "), 2500 pStrDstPath->c_str(), VERR_INVALID_NAME);2489 strAbsDstPath.c_str(), VERR_INVALID_NAME); 2501 2490 } 2502 2491 … … 2510 2499 { 2511 2500 if (fGzipped) 2512 i_importDecompressFile(stack, strSrcFilePath, *pStrDstPath, strSourceOVF.c_str());2501 i_importDecompressFile(stack, strSrcFilePath, strAbsDstPath, strSourceOVF.c_str()); 2513 2502 else 2514 i_importCopyFile(stack, strSrcFilePath, *pStrDstPath, strSourceOVF.c_str());2503 i_importCopyFile(stack, strSrcFilePath, strAbsDstPath, strSourceOVF.c_str()); 2515 2504 } 2516 2505 catch (HRESULT /*arc*/) … … 2529 2518 rc = pTargetHD->init(mVirtualBox, 2530 2519 strTrgFormat, 2531 *pStrDstPath,2520 strAbsDstPath, 2532 2521 Guid::Empty /* media registry: none yet */, 2533 2522 DeviceType_HardDisk); … … 2536 2525 /* Now create an empty hard disk. */ 2537 2526 rc = mVirtualBox->CreateMedium(Bstr(strTrgFormat).raw(), 2538 Bstr( *pStrDstPath).raw(),2527 Bstr(strAbsDstPath).raw(), 2539 2528 AccessMode_ReadWrite, DeviceType_HardDisk, 2540 2529 ComPtr<IMedium>(pTargetHD).asOutParam()); … … 2556 2545 /* operation's weight, as set up with the IProgress originally */ 2557 2546 stack.pProgress->SetNextOperation(BstrFmt(tr("Creating disk image '%s'"), 2558 pStrDstPath->c_str()).raw(),2547 strAbsDstPath.c_str()).raw(), 2559 2548 di.ulSuggestedSizeMB); 2560 2549 } … … 2575 2564 if (fGzipped) 2576 2565 { 2577 Utf8Str strTargetFilePath( *pStrDstPath);2566 Utf8Str strTargetFilePath(strAbsDstPath); 2578 2567 strTargetFilePath.stripFilename(); 2579 2568 strTargetFilePath.append(RTPATH_SLASH_STR); … … 2685 2674 2686 2675 /* Create the machine */ 2687 SafeArray<BSTR> groups; /* no groups */ 2688 rc = mVirtualBox->CreateMachine(NULL, /* machine name: use default */ 2676 SafeArray<BSTR> groups; /* no groups, or maybe one group... */ 2677 if (!stack.strPrimaryGroup.isEmpty()) 2678 Bstr(stack.strPrimaryGroup).detachTo(groups.appendedRaw()); 2679 rc = mVirtualBox->CreateMachine(Bstr(stack.strSettingsFilename).raw(), 2689 2680 Bstr(stack.strNameVBox).raw(), 2690 2681 ComSafeArrayAsInParam(groups), … … 3290 3281 3291 3282 i_importOneDiskImage(diCurrent, 3292 &vsdeTargetHD->strVBoxCurrent,3283 vsdeTargetHD->strVBoxCurrent, 3293 3284 pTargetHD, 3294 3285 stack); … … 3451 3442 /* OS Type */ 3452 3443 config.machineUserData.strOsType = stack.strOsTypeVBox; 3444 /* Groups */ 3445 if (!stack.strPrimaryGroup.isEmpty()) 3446 { 3447 config.machineUserData.llGroups.clear(); 3448 config.machineUserData.llGroups.push_back(stack.strPrimaryGroup); 3449 } 3453 3450 /* Description */ 3454 3451 config.machineUserData.strDescription = stack.strDescription; … … 3849 3846 3850 3847 i_importOneDiskImage(diCurrent, 3851 &vsdeTargetHD->strVBoxCurrent,3848 vsdeTargetHD->strVBoxCurrent, 3852 3849 pTargetHD, 3853 3850 stack); … … 3942 3939 rc = pNewMachine->init(mVirtualBox, 3943 3940 stack.strNameVBox,// name from OVF preparations; can be suffixed to avoid duplicates 3941 stack.strSettingsFilename, 3944 3942 config); // the whole machine config 3945 3943 if (FAILED(rc)) throw rc; … … 4002 4000 stack.strNameVBox = vsdeName.front()->strVBoxCurrent; 4003 4001 4004 // have VirtualBox suggest where the filename would be placed so we can 4005 // put the disk images in the same directory 4006 Bstr bstrMachineFilename; 4007 rc = mVirtualBox->ComposeMachineFilename(Bstr(stack.strNameVBox).raw(), 4008 NULL /* aGroup */, 4009 NULL /* aCreateFlags */, 4010 NULL /* aBaseFolder */, 4011 bstrMachineFilename.asOutParam()); 4012 if (FAILED(rc)) throw rc; 4013 // and determine the machine folder from that 4014 stack.strMachineFolder = bstrMachineFilename; 4002 // Primary group, which is entirely optional. 4003 std::list<VirtualSystemDescriptionEntry*> vsdePrimaryGroup = vsdescThis->i_findByType(VirtualSystemDescriptionType_PrimaryGroup); 4004 if (vsdePrimaryGroup.size() >= 1) 4005 stack.strPrimaryGroup = vsdePrimaryGroup.front()->strVBoxCurrent; 4006 4007 // Draw the right conclusions from the (possibly modified) VM settings 4008 // file name and base folder. If the VM settings file name is modified, 4009 // it takes precedence, otherwise it is recreated from the base folder 4010 // and the primary group. 4011 std::list<VirtualSystemDescriptionEntry*> vsdeSettingsFile = vsdescThis->i_findByType(VirtualSystemDescriptionType_SettingsFile); 4012 if (vsdeSettingsFile.size() >= 1) 4013 { 4014 VirtualSystemDescriptionEntry *vsdeSF1 = vsdeSettingsFile.front(); 4015 if (vsdeSF1->strVBoxCurrent != vsdeSF1->strVBoxSuggested) 4016 stack.strSettingsFilename = vsdeSF1->strVBoxCurrent; 4017 } 4018 if (stack.strSettingsFilename.isEmpty()) 4019 { 4020 Utf8Str strBaseFolder; 4021 std::list<VirtualSystemDescriptionEntry*> vsdeBaseFolder = vsdescThis->i_findByType(VirtualSystemDescriptionType_BaseFolder); 4022 if (vsdeBaseFolder.size() >= 1) 4023 strBaseFolder = vsdeBaseFolder.front()->strVBoxCurrent; 4024 Bstr bstrSettingsFilename; 4025 rc = mVirtualBox->ComposeMachineFilename(Bstr(stack.strNameVBox).raw(), 4026 Bstr(stack.strPrimaryGroup).raw(), 4027 NULL /* aCreateFlags */, 4028 Bstr(strBaseFolder).raw(), 4029 bstrSettingsFilename.asOutParam()); 4030 if (FAILED(rc)) throw rc; 4031 stack.strSettingsFilename = bstrSettingsFilename; 4032 } 4033 4034 // Determine the machine folder from the settings file. 4035 LogFunc(("i=%zu strName=%s strSettingsFilename=%s\n", i, stack.strNameVBox.c_str(), stack.strSettingsFilename.c_str())); 4036 stack.strMachineFolder = stack.strSettingsFilename; 4015 4037 stack.strMachineFolder.stripFilename(); 4016 LogFunc(("i=%zu strName=%s bstrMachineFilename=%ls\n", i, stack.strNameVBox.c_str(), bstrMachineFilename.raw()));4017 4038 4018 4039 // guest OS type -
trunk/src/VBox/Main/src-server/MachineImpl.cpp
r72332 r72476 516 516 * 517 517 * @param aParent Associated parent object. 518 * @param strName Name for the new machine; this overrides what is specified in config and is used519 * for the settings file as well.518 * @param strName Name for the new machine; this overrides what is specified in config. 519 * @param strSettingsFilename File name of .vbox file. 520 520 * @param config Machine configuration loaded and parsed from XML. 521 521 * … … 524 524 HRESULT Machine::init(VirtualBox *aParent, 525 525 const Utf8Str &strName, 526 const Utf8Str &strSettingsFilename, 526 527 const settings::MachineConfigFile &config) 527 528 { … … 532 533 AssertReturn(autoInitSpan.isOk(), E_FAIL); 533 534 534 Utf8Str strConfigFile; 535 aParent->i_getDefaultMachineFolder(strConfigFile); 536 strConfigFile.append(RTPATH_DELIMITER); 537 strConfigFile.append(strName); 538 strConfigFile.append(RTPATH_DELIMITER); 539 strConfigFile.append(strName); 540 strConfigFile.append(".vbox"); 541 542 HRESULT rc = initImpl(aParent, strConfigFile); 535 HRESULT rc = initImpl(aParent, strSettingsFilename); 543 536 if (FAILED(rc)) return rc; 544 537
Note:
See TracChangeset
for help on using the changeset viewer.