- Timestamp:
- Jan 24, 2014 12:10:01 AM (11 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/ApplianceImpl.h
r50200 r50203 173 173 PVDINTERFACEIO pCallbacks, 174 174 PSHASTORAGE pStorage); 175 HRESULT i_readTarFileToBuf( 176 #ifdef USE_RTTAR_FOR_READING 177 RTTAR tar, 178 #else 179 struct FSSRDONLYINTERFACEIO *pTarIo, 180 #endif 175 HRESULT i_readTarFileToBuf(struct FSSRDONLYINTERFACEIO *pTarIo, 181 176 const Utf8Str &strFile, 182 177 void **ppvBuf, -
trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp
r50200 r50203 786 786 RTCString &availableImage) 787 787 { 788 #ifdef USE_RTTAR_FOR_READING789 RTTAR tar = (RTTAR)pSHAStorage->pVDImageIfaces->pvUser;790 char *pszFilename = 0;791 792 int vrc = RTTarCurrentFile(tar, &pszFilename);793 if (RT_FAILURE(vrc))794 throw setError(VBOX_E_FILE_ERROR,795 tr("Could not open the current file in the OVA package (%Rrc)"), vrc);796 if (vrc == VINF_TAR_DIR_PATH)797 {798 HRESULT hrc = setError(VBOX_E_FILE_ERROR,799 tr("Empty directory folder (%s) isn't allowed in the OVA package (%Rrc)"),800 pszFilename, vrc);801 RTStrFree(pszFilename);802 throw hrc;803 }804 805 availableImage = pszFilename;806 return S_OK;807 808 #else809 788 PFSSRDONLYINTERFACEIO pTarIo = (PFSSRDONLYINTERFACEIO)pSHAStorage->pVDImageIfaces->pvUser; 810 789 const char *pszFilename; … … 823 802 824 803 throw setError(VBOX_E_FILE_ERROR, tr("Could not open the current file in the OVA package (%Rrc)"), vrc); 825 #endif826 804 } 827 805 … … 1064 1042 LogFlowFuncEnter(); 1065 1043 1066 #ifdef USE_RTTAR_FOR_READING1067 RTTAR tar;1068 HRESULT rc = S_OK;1069 int vrc = 0;1070 PVDINTERFACEIO pShaIo = 0;1071 PVDINTERFACEIO pTarIo = 0;1072 char *pszFilename = 0;1073 SHASTORAGE storage;1074 1075 RT_ZERO(storage);1076 1077 vrc = RTTarOpen(&tar, pTask->locInfo.strPath.c_str(), RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE, true);1078 if (RT_FAILURE(vrc))1079 rc = setError(VBOX_E_FILE_ERROR,1080 tr("Could not open the OVA file '%s' (%Rrc)"),1081 pTask->locInfo.strPath.c_str(), vrc);1082 else1083 {1084 do1085 {1086 vrc = RTTarCurrentFile(tar, &pszFilename);1087 if (RT_FAILURE(vrc))1088 {1089 rc = VBOX_E_FILE_ERROR;1090 break;1091 }1092 1093 Utf8Str suffix(RTPathSuffix(pszFilename));1094 1095 if (!suffix.endsWith(".ovf",Utf8Str::CaseInsensitive))1096 {1097 vrc = VERR_FILE_NOT_FOUND;1098 rc = setError(VBOX_E_FILE_ERROR,1099 tr("First file in the OVA package must have the extension 'ovf'. "1100 "But the file '%s' has a different extension (%Rrc)"),1101 pszFilename,1102 vrc);1103 break;1104 }1105 1106 pTarIo = TarCreateInterface();1107 if (!pTarIo)1108 {1109 rc = E_OUTOFMEMORY;1110 break;1111 }1112 1113 pShaIo = ShaCreateInterface();1114 if (!pShaIo)1115 {1116 rc = E_OUTOFMEMORY;1117 break ;1118 }1119 1120 Utf8Str name = i_applianceIOName(applianceIOTar);1121 1122 vrc = VDInterfaceAdd(&pTarIo->Core, name.c_str(),1123 VDINTERFACETYPE_IO, tar, sizeof(VDINTERFACEIO),1124 &storage.pVDImageIfaces);1125 if (RT_FAILURE(vrc))1126 {1127 rc = setError(VBOX_E_IPRT_ERROR, "Creation of the VD interface failed (%Rrc)", vrc);1128 break;1129 }1130 1131 rc = i_readFSImpl(pTask, pszFilename, pShaIo, &storage);1132 if (FAILED(rc))1133 break;1134 1135 } while (0);1136 1137 RTTarClose(tar);1138 }1139 1140 /* Cleanup */1141 if (pszFilename)1142 RTStrFree(pszFilename);1143 if (pShaIo)1144 RTMemFree(pShaIo);1145 if (pTarIo)1146 RTMemFree(pTarIo);1147 1148 LogFlowFunc(("rc=%Rhrc\n", rc));1149 LogFlowFuncLeave();1150 1151 return rc;1152 1153 #else1154 1044 /* 1155 1045 * Open the tar file and get a VD I/O interface for it. … … 1210 1100 LogFlowFuncLeave(); 1211 1101 return hrc; 1212 #endif1213 1102 } 1214 1103 … … 1604 1493 storage.fCreateDigest = true; 1605 1494 1606 size_t cbMf Size = 0;1495 size_t cbMfFile = 0; 1607 1496 1608 1497 /* Now import the appliance. */ … … 1611 1500 /* Add the ovf file to the digest list. */ 1612 1501 stack.llSrcDisksDigest.push_front(STRPAIR(pTask->locInfo.strPath, m->strOVFSHADigest)); 1613 rc = i_readFileToBuf(strMfFile, &pvMfBuf, &cbMf Size, true, pShaIo, &storage);1502 rc = i_readFileToBuf(strMfFile, &pvMfBuf, &cbMfFile, true, pShaIo, &storage); 1614 1503 if (FAILED(rc)) throw rc; 1615 rc = i_verifyManifestFile(strMfFile, stack, pvMfBuf, cbMf Size);1504 rc = i_verifyManifestFile(strMfFile, stack, pvMfBuf, cbMfFile); 1616 1505 if (FAILED(rc)) throw rc; 1617 1506 1618 size_t cbCert Size = 0;1507 size_t cbCertFile = 0; 1619 1508 1620 1509 /* Save the SHA digest of the manifest file for the next validation */ … … 1624 1513 if (RTFileExists(strCertFile.c_str())) 1625 1514 { 1626 rc = i_readFileToBuf(strCertFile, &pvCertBuf, &cbCert Size, false, pShaIo, &storage);1515 rc = i_readFileToBuf(strCertFile, &pvCertBuf, &cbCertFile, false, pShaIo, &storage); 1627 1516 if (FAILED(rc)) throw rc; 1628 1517 … … 1687 1576 * Open the OVA (TAR) file. 1688 1577 */ 1689 #ifdef USE_RTTAR_FOR_READING1690 PVDINTERFACEIO pTarIo = 0;1691 RTTAR tar;1692 int vrc = RTTarOpen(&tar,1693 pTask->locInfo.strPath.c_str(),1694 RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE, true);1695 #else1696 1578 PFSSRDONLYINTERFACEIO pTarIo; 1697 1579 int vrc = fssRdOnlyCreateInterfaceForTarFile(pTask->locInfo.strPath.c_str(), &pTarIo); 1698 PFSSRDONLYINTERFACEIO tar = pTarIo; /* temporary hack */1699 #endif1700 1580 if (RT_FAILURE(vrc)) 1701 1581 return setError(VBOX_E_FILE_ERROR, … … 1705 1585 1706 1586 PVDINTERFACEIO pShaIo = 0; 1707 #ifdef USE_RTTAR_FOR_READING 1708 char *pszFilename = 0; 1709 #endif 1710 void *pvMfBuf = 0; 1711 void *pvCertBuf = 0; 1587 void *pvMfBuf = NULL; 1588 void *pvCertBuf = NULL; 1712 1589 Utf8Str OVFfilename; 1713 1590 … … 1723 1600 if (!pShaIo) 1724 1601 throw setError(E_OUTOFMEMORY); 1725 #ifdef USE_RTTAR_FOR_READING 1726 pTarIo = TarCreateInterface(); 1727 if (!pTarIo) 1728 throw setError(E_OUTOFMEMORY); 1729 #endif 1730 1602 1603 Utf8Str nameTar = i_applianceIOName(applianceIOTar); 1731 1604 SHASTORAGE storage; 1732 1605 RT_ZERO(storage); 1733 1734 Utf8Str nameTar = i_applianceIOName(applianceIOTar);1735 1736 #ifdef USE_RTTAR_FOR_READING1737 vrc = VDInterfaceAdd(&pTarIo->Core, nameTar.c_str(),1738 VDINTERFACETYPE_IO, tar, sizeof(VDINTERFACEIO),1739 &storage.pVDImageIfaces);1740 #else1741 1606 vrc = VDInterfaceAdd((PVDINTERFACE)pTarIo, nameTar.c_str(), 1742 1607 VDINTERFACETYPE_IO, pTarIo, sizeof(VDINTERFACEIO), 1743 1608 &storage.pVDImageIfaces); 1744 #endif1745 1609 if (RT_FAILURE(vrc)) 1746 1610 throw setError(VBOX_E_IPRT_ERROR, 1747 1611 tr("Creation of the VD interface failed (%Rrc)"), vrc); 1748 1612 1613 /* Fill out interface descriptor. */ 1749 1614 Utf8Str nameSha = i_applianceIOName(applianceIOSha); 1750 /* Fill out interface descriptor. */1751 1615 pShaIo->Core.u32Magic = VDINTERFACE_MAGIC; 1752 1616 pShaIo->Core.cbSize = sizeof(VDINTERFACEIO); … … 1762 1626 * are named. 1763 1627 */ 1764 #ifdef USE_RTTAR_FOR_READING1765 vrc = RTTarCurrentFile(tar, &pszFilename);1766 #else1767 1628 const char *pszFilename; 1768 1629 vrc = fssRdOnlyGetCurrentName(pTarIo, &pszFilename); 1769 #endif1770 1630 if (RT_FAILURE(vrc)) 1771 1631 throw setError(VBOX_E_IPRT_ERROR, … … 1778 1638 /* save original OVF filename */ 1779 1639 OVFfilename = pszFilename; 1780 size_t cbMfSize = 0;1781 size_t cbCertSize = 0;1782 1640 Utf8Str strMfFile = (Utf8Str(pszFilename)).stripSuffix().append(".mf"); 1783 1641 Utf8Str strCertFile = (Utf8Str(pszFilename)).stripSuffix().append(".cert"); 1784 1642 1785 1643 /* Skip the OVF file, cause this was read in IAppliance::Read already. */ 1786 #ifdef USE_RTTAR_FOR_READING1787 vrc = RTTarSeekNextFile(tar);1788 if ( RT_FAILURE(vrc)1789 && vrc != VERR_TAR_END_OF_FILE)1790 throw setError(VBOX_E_IPRT_ERROR,1791 tr("Seeking within the archive failed (%Rrc)"), vrc);1792 RTStrFree(pszFilename);1793 pszFilename = NULL;1794 RTTarCurrentFile(tar, &pszFilename);1795 if (vrc == VINF_TAR_DIR_PATH)1796 throw setError(VBOX_E_FILE_ERROR,1797 tr("Empty directory folder (%s) isn't allowed in the OVA package (%Rrc)"),1798 pszFilename, vrc);1799 #else1800 1644 vrc = fssRdOnlySkipCurrent(pTarIo); 1801 1645 if (RT_SUCCESS(vrc)) … … 1804 1648 && vrc != VERR_EOF) 1805 1649 throw setError(VBOX_E_IPRT_ERROR, tr("Seeking within the archive failed (%Rrc)"), vrc); 1806 #endif1807 1650 1808 1651 PVDINTERFACEIO pCallbacks = pShaIo; … … 1826 1669 * If it fails here, we will try it again after all disks where read. 1827 1670 */ 1828 rc = i_readTarFileToBuf(tar, strMfFile, &pvMfBuf, &cbMfSize, true, pCallbacks, pStorage); 1671 size_t cbMfFile = 0; 1672 rc = i_readTarFileToBuf(pTarIo, strMfFile, &pvMfBuf, &cbMfFile, true, pCallbacks, pStorage); 1829 1673 if (FAILED(rc)) 1830 1674 throw rc; … … 1836 1680 * there is a manifest file. 1837 1681 */ 1838 #ifdef USE_RTTAR_FOR_READING 1839 vrc = RTTarCurrentFile(tar, &pszFilename); 1840 #else 1682 size_t cbCertFile = 0; 1841 1683 vrc = fssRdOnlyGetCurrentName(pTarIo, &pszFilename); 1842 #endif1843 1684 if (RT_SUCCESS(vrc)) 1844 1685 { … … 1847 1688 if (strCertFile.compare(pszFilename) == 0) 1848 1689 { 1849 rc = i_readTarFileToBuf( tar, strCertFile, &pvCertBuf, &cbCertSize, false, pCallbacks, pStorage);1690 rc = i_readTarFileToBuf(pTarIo, strCertFile, &pvCertBuf, &cbCertFile, false, pCallbacks, pStorage); 1850 1691 if (FAILED(rc)) throw rc; 1851 1692 … … 1872 1713 * File #N-1 - The manifest file, optional. 1873 1714 */ 1874 rc = i_readTarFileToBuf( tar, strMfFile, &pvMfBuf, &cbMfSize, true, pCallbacks, pStorage);1715 rc = i_readTarFileToBuf(pTarIo, strMfFile, &pvMfBuf, &cbMfFile, true, pCallbacks, pStorage); 1875 1716 if (FAILED(rc)) throw rc; 1876 1717 … … 1880 1721 /* Add the ovf file to the digest list. */ 1881 1722 stack.llSrcDisksDigest.push_front(STRPAIR(OVFfilename, m->strOVFSHADigest)); 1882 rc = i_verifyManifestFile(strMfFile, stack, pvMfBuf, cbMf Size);1723 rc = i_verifyManifestFile(strMfFile, stack, pvMfBuf, cbMfFile); 1883 1724 if (FAILED(rc)) throw rc; 1884 1725 … … 1887 1728 * (Requires mainfest, as mention before.) 1888 1729 */ 1889 #ifdef USE_RTTAR_FOR_READING1890 RTStrFree(pszFilename);1891 pszFilename = NULL;1892 vrc = RTTarCurrentFile(tar, &pszFilename);1893 #else1894 1730 vrc = fssRdOnlyGetCurrentName(pTarIo, &pszFilename); 1895 #endif1896 1731 if (RT_SUCCESS(vrc)) 1897 1732 { 1898 1733 if (strCertFile.compare(pszFilename) == 0) 1899 1734 { 1900 rc = i_readTarFileToBuf( tar, strCertFile, &pvCertBuf, &cbCertSize, false, pCallbacks, pStorage);1735 rc = i_readTarFileToBuf(pTarIo, strCertFile, &pvCertBuf, &cbCertFile, false, pCallbacks, pStorage); 1901 1736 if (FAILED(rc)) throw rc; 1902 1737 … … 1909 1744 } 1910 1745 } 1746 /** @todo else: Verify the manifest! */ 1911 1747 } 1912 1748 catch (HRESULT rc2) … … 1921 1757 * won't be used anymore. 1922 1758 */ 1923 { 1924 ErrorInfoKeeper eik; /* paranoia */ 1925 list< ComObjPtr<VirtualSystemDescription> >::const_iterator itvsd; 1926 /* Iterate through all virtual systems of that appliance */ 1927 for (itvsd = m->virtualSystemDescriptions.begin(); 1928 itvsd != m->virtualSystemDescriptions.end(); 1929 ++itvsd) 1930 { 1931 ComObjPtr<VirtualSystemDescription> vsdescThis = (*itvsd); 1932 settings::MachineConfigFile *pConfig = vsdescThis->m->pConfig; 1933 if(vsdescThis->m->pConfig!=NULL) 1934 stack.restoreOriginalUUIDOfAttachedDevice(pConfig); 1935 } 1759 ErrorInfoKeeper eik; /* paranoia */ 1760 list< ComObjPtr<VirtualSystemDescription> >::const_iterator itvsd; 1761 /* Iterate through all virtual systems of that appliance */ 1762 for (itvsd = m->virtualSystemDescriptions.begin(); 1763 itvsd != m->virtualSystemDescriptions.end(); 1764 ++itvsd) 1765 { 1766 ComObjPtr<VirtualSystemDescription> vsdescThis = (*itvsd); 1767 settings::MachineConfigFile *pConfig = vsdescThis->m->pConfig; 1768 if(vsdescThis->m->pConfig!=NULL) 1769 stack.restoreOriginalUUIDOfAttachedDevice(pConfig); 1936 1770 } 1937 1771 } 1938 1772 writeLock.acquire(); 1939 1773 1940 #ifdef USE_RTTAR_FOR_READING 1941 RTTarClose(tar); 1942 #else 1774 /* Cleanup */ 1943 1775 fssRdOnlyDestroyInterface(pTarIo); 1944 #endif1945 1946 /* Cleanup */1947 #ifdef USE_RTTAR_FOR_READING1948 if (pszFilename)1949 RTStrFree(pszFilename);1950 #endif1951 1776 if (pvMfBuf) 1952 1777 RTMemFree(pvMfBuf); 1953 1778 if (pShaIo) 1954 1779 RTMemFree(pShaIo); 1955 #ifdef USE_RTTAR_FOR_READING1956 if (pTarIo)1957 RTMemFree(pTarIo);1958 #endif1959 1780 if (pvCertBuf) 1960 1781 RTMemFree(pvCertBuf); … … 2184 2005 } 2185 2006 2186 HRESULT Appliance::i_readTarFileToBuf( 2187 #ifdef USE_RTTAR_FOR_READING 2188 RTTAR tar, 2189 #else 2190 PFSSRDONLYINTERFACEIO pTarIo, 2191 #endif 2007 HRESULT Appliance::i_readTarFileToBuf(PFSSRDONLYINTERFACEIO pTarIo, 2192 2008 const Utf8Str &strFile, 2193 2009 void **ppvBuf, … … 2199 2015 HRESULT rc = S_OK; 2200 2016 2201 #ifdef USE_RTTAR_FOR_READING2202 char *pszCurFile;2203 int vrc = RTTarCurrentFile(tar, &pszCurFile);2204 #else2205 2017 const char *pszCurFile; 2206 2018 int vrc = fssRdOnlyGetCurrentName(pTarIo, &pszCurFile); 2207 #endif2208 2019 if (RT_SUCCESS(vrc)) 2209 2020 { … … 2217 2028 tr("Empty directory folder (%s) isn't allowed in the OVA package (%Rrc)"), 2218 2029 pszCurFile, vrc); 2219 #ifdef USE_RTTAR_FOR_READING 2220 RTStrFree(pszCurFile); 2221 #endif 2222 } 2223 #ifdef USE_RTTAR_FOR_READING 2224 else if (vrc != VERR_TAR_END_OF_FILE) 2225 #else 2030 } 2226 2031 else if (vrc != VERR_EOF) 2227 #endif2228 2032 rc = setError(VBOX_E_IPRT_ERROR, "Seeking within the archive failed (%Rrc)", vrc); 2229 2033
Note:
See TracChangeset
for help on using the changeset viewer.