- Timestamp:
- May 28, 2010 5:14:53 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/com/Guid.h
r28800 r29873 141 141 } 142 142 143 /** 144 * Like toString, but encloses the returned string in curly brackets. 145 * @return 146 */ 147 Utf8Str toStringCurly() const 148 { 149 char buf[RTUUID_STR_LENGTH + 2] = "{"; 150 ::RTUuidToStr(&uuid, buf + 1, RTUUID_STR_LENGTH); 151 buf[sizeof(buf) - 2] = '}'; 152 buf[sizeof(buf) - 1] = '\0'; 153 return Utf8Str(buf); 154 } 155 143 156 Bstr toUtf16() const 144 157 { -
trunk/include/VBox/settings.h
r29480 r29873 93 93 94 94 com::Utf8Str makeString(const RTTIMESPEC &tm); 95 com::Utf8Str makeString(const com::Guid &guid);96 95 97 96 void readExtraData(const xml::ElementNode &elmExtraData, … … 880 879 BuildMachineXML_SkipRemovableMedia = 0x02 881 880 }; 882 void buildMachineXML(xml::ElementNode &elmMachine, uint32_t fl); 881 void buildMachineXML(xml::ElementNode &elmMachine, 882 uint32_t fl, 883 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes); 883 884 884 885 private: … … 901 902 void buildHardwareXML(xml::ElementNode &elmParent, const Hardware &hw, const Storage &strg); 902 903 void buildNetworkXML(NetworkAttachmentType_T mode, xml::ElementNode &elmParent, const NetworkAdapter &nic); 903 void buildStorageControllersXML(xml::ElementNode &elmParent, const Storage &st, bool fSkipRemovableMedia); 904 void buildStorageControllersXML(xml::ElementNode &elmParent, 905 const Storage &st, 906 bool fSkipRemovableMedia, 907 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes); 904 908 void buildSnapshotXML(xml::ElementNode &elmParent, const Snapshot &snap); 905 909 -
trunk/src/VBox/Main/ApplianceImplExport.cpp
r29389 r29873 661 661 */ 662 662 void Appliance::buildXMLForOneVirtualSystem(xml::ElementNode &elmToAddVirtualSystemsTo, 663 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes, 663 664 ComObjPtr<VirtualSystemDescription> &vsdescThis, 664 665 OVFFormat enFormat, … … 1298 1299 pConfig->buildMachineXML(*pelmVBoxMachine, 1299 1300 settings::MachineConfigFile::BuildMachineXML_WriteVboxVersionAttribute 1300 | settings::MachineConfigFile::BuildMachineXML_SkipRemovableMedia );1301 | settings::MachineConfigFile::BuildMachineXML_SkipRemovableMedia, 1301 1302 // but not BuildMachineXML_IncludeSnapshots 1303 pllElementsWithUuidAttributes); 1302 1304 delete pConfig; 1303 1305 } … … 1425 1427 pelmToAddVirtualSystemsTo = pelmRoot; // add virtual system directly under root element 1426 1428 1429 // this list receives pointers to the XML elements in the machine XML which 1430 // might have UUIDs that need fixing after we know the UUIDs of the exported images 1431 std::list<xml::ElementNode*> llElementsWithUuidAttributes; 1432 1427 1433 list< ComObjPtr<VirtualSystemDescription> >::const_iterator it; 1428 1434 /* Iterate throughs all virtual systems of that appliance */ … … 1433 1439 ComObjPtr<VirtualSystemDescription> vsdescThis = *it; 1434 1440 buildXMLForOneVirtualSystem(*pelmToAddVirtualSystemsTo, 1441 &llElementsWithUuidAttributes, 1435 1442 vsdescThis, 1436 1443 enFormat, … … 1537 1544 // capacity is reported in megabytes, so... 1538 1545 cbCapacity *= _1M; 1546 1547 Bstr uuidTarget; 1548 rc = pTargetDisk->COMGETTER(Id)(uuidTarget.asOutParam()); 1549 if (FAILED(rc)) throw rc; 1550 Guid guidTarget(uuidTarget); 1539 1551 1540 1552 // upon success, close the disk as well … … 1562 1574 // correct string as communicated to us by VMware (public bug #6612) 1563 1575 ); 1564 pelmDisk->setAttribute("vbox:uuid", Utf8StrFmt("%RTuuid", guidSource.raw()).c_str()); 1576 1577 // add the UUID of the newly created target image to the OVF disk element, but in the 1578 // vbox: namespace since it's not part of the standard 1579 pelmDisk->setAttribute("vbox:uuid", Utf8StrFmt("%RTuuid", guidTarget.raw()).c_str()); 1580 1581 // now, we might have other XML elements from vbox:Machine pointing to this image, 1582 // but those would refer to the UUID of the _source_ image (which we created the 1583 // export image from); those UUIDs need to be fixed to the export image 1584 for (std::list<xml::ElementNode*>::iterator eit = llElementsWithUuidAttributes.begin(); 1585 eit != llElementsWithUuidAttributes.end(); 1586 ++eit) 1587 { 1588 xml::ElementNode *pelmImage = *eit; 1589 // overwrite existing uuid attribute 1590 pelmImage->setAttribute("uuid", guidTarget.toStringCurly()); 1591 } 1565 1592 } 1566 1593 -
trunk/src/VBox/Main/ApplianceImplImport.cpp
r29777 r29873 50 50 51 51 /** 52 * Public method implementation. 52 * Public method implementation. This opens the OVF with ovfreader.cpp. 53 * Thread implementation is in Appliance::readImpl(). 54 * 53 55 * @param path 54 56 * @return … … 100 102 101 103 /** 102 * Public method implementation. 104 * Public method implementation. This looks at the output of ovfreader.cpp and creates 105 * VirtualSystemDescription instances. 103 106 * @return 104 107 */ … … 539 542 540 543 /** 541 * Public method implementation. 544 * Public method implementation. This creates one or more new machines according to the 545 * VirtualSystemScription instances created by Appliance::Interpret(). 546 * Thread implementation is in Appliance::importImpl(). 542 547 * @param aProgress 543 548 * @return … … 587 592 * Implementation for reading an OVF. This starts a new thread which will call 588 593 * Appliance::taskThreadImportOrExport() which will then call readFS() or readS3(). 594 * This will then open the OVF with ovfreader.cpp. 589 595 * 590 596 * This is in a separate private method because it is used from two locations: … … 635 641 /** 636 642 * Actual worker code for reading an OVF from disk. This is called from Appliance::taskThreadImportOrExport() 637 * and therefore runs on the OVF read worker thread. This runs in two contexts: 643 * and therefore runs on the OVF read worker thread. This opens the OVF with ovfreader.cpp. 644 * 645 * This runs in two contexts: 638 646 * 639 647 * 1) in a first worker thread; in that case, Appliance::Read() called Appliance::readImpl(); … … 912 920 * Appliance::taskThreadImportOrExport(). 913 921 * 922 * This creates one or more new machines according to the VirtualSystemScription instances created by 923 * Appliance::Interpret(). 924 * 914 925 * This is in a separate private method because it is used from two locations: 915 926 * … … 1072 1083 /** 1073 1084 * Actual worker code for importing OVF data into VirtualBox. This is called from Appliance::taskThreadImportOrExport() 1074 * and therefore runs on the OVF import worker thread. This runs in two contexts: 1085 * and therefore runs on the OVF import worker thread. This creates one or more new machines according to the 1086 * VirtualSystemScription instances created by Appliance::Interpret(). 1087 * 1088 * This runs in two contexts: 1075 1089 * 1076 1090 * 1) in a first worker thread; in that case, Appliance::ImportMachines() called Appliance::importImpl(); … … 1313 1327 // First open the existing disk image 1314 1328 rc = mVirtualBox->OpenHardDisk(Bstr(strSrcFilePath), 1315 AccessMode_ReadOnly,1316 false,1317 NULL,1318 false,1319 NULL,1320 pSourceHD.asOutParam());1329 AccessMode_ReadOnly, 1330 false, 1331 NULL, 1332 false, 1333 NULL, 1334 pSourceHD.asOutParam()); 1321 1335 if (FAILED(rc)) throw rc; 1322 1336 fSourceHdNeedsClosing = true; … … 1367 1381 * about what needs cleaning up (to support rollback). 1368 1382 * 1369 * @param locInfo 1370 * @param vsysThis 1371 * @param vsdescThis 1372 * @param pNewMachine 1373 * @param stack 1383 * @param vsysThis OVF virtual system (machine) to import. 1384 * @param vsdescThis Matching virtual system description (machine) to import. 1385 * @param pNewMachine out: Newly created machine. 1386 * @param stack Cleanup stack for when this throws. 1374 1387 */ 1375 1388 void Appliance::importMachineGeneric(const ovf::VirtualSystem &vsysThis, -
trunk/src/VBox/Main/include/ApplianceImpl.h
r29422 r29873 168 168 struct XMLStack; 169 169 void buildXMLForOneVirtualSystem(xml::ElementNode &elmToAddVirtualSystemsTo, 170 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes, 170 171 ComObjPtr<VirtualSystemDescription> &vsdescThis, 171 172 OVFFormat enFormat, -
trunk/src/VBox/Main/xml/Settings.cpp
r29593 r29873 427 427 (uint16_t)time.u8Minute, 428 428 (uint16_t)time.u8Second); 429 }430 431 /**432 * Helper to create a string for a GUID.433 * @param guid434 * @return435 */436 com::Utf8Str ConfigFileBase::makeString(const Guid &guid)437 {438 Utf8Str str("{");439 str.append(guid.toString());440 str.append("}");441 return str;442 429 } 443 430 … … 1162 1149 { 1163 1150 xml::ElementNode *pelmHardDisk = elmMedium.createChild("HardDisk"); 1164 pelmHardDisk->setAttribute("uuid", m akeString(mdm.uuid));1151 pelmHardDisk->setAttribute("uuid", mdm.uuid.toStringCurly()); 1165 1152 pelmHardDisk->setAttribute("location", mdm.strLocation); 1166 1153 pelmHardDisk->setAttribute("format", mdm.strFormat); … … 1222 1209 const MachineRegistryEntry &mre = *it; 1223 1210 xml::ElementNode *pelmMachineEntry = pelmMachineRegistry->createChild("MachineEntry"); 1224 pelmMachineEntry->setAttribute("uuid", m akeString(mre.uuid));1211 pelmMachineEntry->setAttribute("uuid", mre.uuid.toStringCurly()); 1225 1212 pelmMachineEntry->setAttribute("src", mre.strSettingsFile); 1226 1213 } … … 1243 1230 const Medium &mdm = *it; 1244 1231 xml::ElementNode *pelmMedium = pelmDVDImages->createChild("Image"); 1245 pelmMedium->setAttribute("uuid", m akeString(mdm.uuid));1232 pelmMedium->setAttribute("uuid", mdm.uuid.toStringCurly()); 1246 1233 pelmMedium->setAttribute("location", mdm.strLocation); 1247 1234 if (mdm.strDescription.length()) … … 1256 1243 const Medium &mdm = *it; 1257 1244 xml::ElementNode *pelmMedium = pelmFloppyImages->createChild("Image"); 1258 pelmMedium->setAttribute("uuid", m akeString(mdm.uuid));1245 pelmMedium->setAttribute("uuid", mdm.uuid.toStringCurly()); 1259 1246 pelmMedium->setAttribute("location", mdm.strLocation); 1260 1247 if (mdm.strDescription.length()) … … 3063 3050 && (!hw.uuid.isEmpty()) 3064 3051 ) 3065 pelmHardware->setAttribute("uuid", makeString(hw.uuid));3052 pelmHardware->setAttribute("uuid", hw.uuid.toStringCurly()); 3066 3053 3067 3054 xml::ElementNode *pelmCPU = pelmHardware->createChild("CPU"); … … 3297 3284 pelmDVD->setAttribute("passthrough", att.fPassThrough); 3298 3285 if (!att.uuid.isEmpty()) 3299 pelmDVD->createChild("Image")->setAttribute("uuid", makeString(att.uuid));3286 pelmDVD->createChild("Image")->setAttribute("uuid", att.uuid.toStringCurly()); 3300 3287 else if (att.strHostDriveSrc.length()) 3301 3288 pelmDVD->createChild("HostDrive")->setAttribute("src", att.strHostDriveSrc); … … 3313 3300 pelmFloppy->setAttribute("enabled", true); 3314 3301 if (!att.uuid.isEmpty()) 3315 pelmFloppy->createChild("Image")->setAttribute("uuid", makeString(att.uuid));3302 pelmFloppy->createChild("Image")->setAttribute("uuid", att.uuid.toStringCurly()); 3316 3303 else if (att.strHostDriveSrc.length()) 3317 3304 pelmFloppy->createChild("HostDrive")->setAttribute("src", att.strHostDriveSrc); … … 3653 3640 * This parameter is ignored unless the settings version is at least v1.9, which 3654 3641 * is always the case when this gets called for OVF export. 3642 * @param pllElementsWithUuidAttributes If not NULL, must point to a list of element node 3643 * pointers to which we will append all allements that we created here that contain 3644 * UUID attributes. This allows the OVF export code to quickly replace the internal 3645 * media UUIDs with the UUIDs of the media that were exported. 3655 3646 */ 3656 3647 void MachineConfigFile::buildStorageControllersXML(xml::ElementNode &elmParent, 3657 3648 const Storage &st, 3658 bool fSkipRemovableMedia) 3649 bool fSkipRemovableMedia, 3650 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes) 3659 3651 { 3660 3652 xml::ElementNode *pelmStorageControllers = elmParent.createChild("StorageControllers"); … … 3759 3751 pelmDevice->setAttribute("device", att.lDevice); 3760 3752 3753 // attached image, if any 3761 3754 if ( !att.uuid.isEmpty() 3762 3755 && ( att.deviceType == DeviceType_HardDisk … … 3764 3757 ) 3765 3758 ) 3766 pelmDevice->createChild("Image")->setAttribute("uuid", makeString(att.uuid)); 3759 { 3760 xml::ElementNode *pelmImage = pelmDevice->createChild("Image"); 3761 pelmImage->setAttribute("uuid", att.uuid.toStringCurly()); 3762 3763 // if caller wants a list of UUID elements, give it to them 3764 if (pllElementsWithUuidAttributes) 3765 pllElementsWithUuidAttributes->push_back(pelmImage); 3766 } 3767 3767 else if ( (m->sv >= SettingsVersion_v1_9) 3768 3768 && (att.strHostDriveSrc.length()) … … 3785 3785 xml::ElementNode *pelmSnapshot = elmParent.createChild("Snapshot"); 3786 3786 3787 pelmSnapshot->setAttribute("uuid", makeString(snap.uuid));3787 pelmSnapshot->setAttribute("uuid", snap.uuid.toStringCurly()); 3788 3788 pelmSnapshot->setAttribute("name", snap.strName); 3789 3789 pelmSnapshot->setAttribute("timeStamp", makeString(snap.timestamp)); … … 3798 3798 buildStorageControllersXML(*pelmSnapshot, 3799 3799 snap.storage, 3800 false /* fSkipRemovableMedia */); 3800 false /* fSkipRemovableMedia */, 3801 NULL); /* pllElementsWithUuidAttributes */ 3801 3802 // we only skip removable media for OVF, but we never get here for OVF 3802 3803 // since snapshots never get written then … … 3846 3847 * @param elmMachine XML <Machine> element to add attributes and elements to. 3847 3848 * @param fl Flags. 3849 * @param pllElementsWithUuidAttributes pointer to list that should receive UUID elements or NULL; 3850 * see buildStorageControllersXML() for details. 3848 3851 */ 3849 3852 void MachineConfigFile::buildMachineXML(xml::ElementNode &elmMachine, 3850 uint32_t fl) 3853 uint32_t fl, 3854 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes) 3851 3855 { 3852 3856 if (fl & BuildMachineXML_WriteVboxVersionAttribute) … … 3854 3858 setVersionAttribute(elmMachine); 3855 3859 3856 elmMachine.setAttribute("uuid", makeString(uuid));3860 elmMachine.setAttribute("uuid", uuid.toStringCurly()); 3857 3861 elmMachine.setAttribute("name", strName); 3858 3862 if (!fNameSync) … … 3865 3869 if ( (fl & BuildMachineXML_IncludeSnapshots) 3866 3870 && !uuidCurrentSnapshot.isEmpty()) 3867 elmMachine.setAttribute("currentSnapshot", makeString(uuidCurrentSnapshot));3871 elmMachine.setAttribute("currentSnapshot", uuidCurrentSnapshot.toStringCurly()); 3868 3872 if (strSnapshotFolder.length()) 3869 3873 elmMachine.setAttribute("snapshotFolder", strSnapshotFolder); … … 3897 3901 buildStorageControllersXML(elmMachine, 3898 3902 storageMachine, 3899 !!(fl & BuildMachineXML_SkipRemovableMedia)); 3903 !!(fl & BuildMachineXML_SkipRemovableMedia), 3904 pllElementsWithUuidAttributes); 3900 3905 } 3901 3906 … … 4085 4090 xml::ElementNode *pelmMachine = m->pelmRoot->createChild("Machine"); 4086 4091 buildMachineXML(*pelmMachine, 4087 MachineConfigFile::BuildMachineXML_IncludeSnapshots );4092 MachineConfigFile::BuildMachineXML_IncludeSnapshots, 4088 4093 // but not BuildMachineXML_WriteVboxVersionAttribute 4094 NULL); /* pllElementsWithUuidAttributes */ 4089 4095 4090 4096 // now go write the XML -
trunk/src/VBox/Runtime/r3/xml.cpp
r28800 r29873 1011 1011 AttributeNode* ElementNode::setAttribute(const char *pcszName, const char *pcszValue) 1012 1012 { 1013 AttributeNode *pattrReturn; 1013 1014 Data::AttributesMap::const_iterator it; 1014 1015 … … 1024 1025 // store 1025 1026 m->attribs[pcszKey] = pNew; 1027 pattrReturn = pNew.get(); 1026 1028 } 1027 1029 else 1028 1030 { 1029 // @todo 1030 throw LogicError("Attribute exists"); 1031 } 1032 1033 return NULL; 1031 // overwrite existing libxml attribute node 1032 xmlAttrPtr plibAttr = xmlSetProp(m_plibNode, (xmlChar*)pcszName, (xmlChar*)pcszValue); 1033 1034 // and fix our existing C++ side around it 1035 boost::shared_ptr<AttributeNode> pattr = it->second; 1036 pattr->m_plibAttr = plibAttr; // in case the xmlAttrPtr is different, I'm not sure 1037 1038 pattrReturn = pattr.get(); 1039 } 1040 1041 return pattrReturn; 1034 1042 1035 1043 }
Note:
See TracChangeset
for help on using the changeset viewer.