Changeset 48352 in vbox for trunk/src/VBox/Main/src-server
- Timestamp:
- Sep 6, 2013 12:10:56 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/ApplianceImplExport.cpp
r48339 r48352 2125 2125 { 2126 2126 //copy/clone CD/DVD image 2127 /* Read the ISO file into a memory buffer*/2127 /* Read the ISO file and add one to OVA/OVF package */ 2128 2128 { 2129 void *pvTmpBuf = 0; 2130 size_t cbSize = 0; 2131 2132 if (RTFileExists(strSrcFilePath.c_str())) 2133 { 2134 // open ISO file and read one into memory buffer 2135 RTFILE pFile = NULL; 2136 vrc = RTFileOpen(&pFile, strSrcFilePath.c_str(), RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE); 2137 if (RT_SUCCESS(vrc) && pFile != NULL) 2138 { 2139 uint64_t cbFile = 0; 2140 2141 vrc = RTFileGetSize(pFile, &cbFile); 2142 2143 if (RT_SUCCESS(vrc)) 2144 pvTmpBuf = RTMemAllocZ(cbFile); 2145 else 2146 throw setError(VBOX_E_FILE_ERROR, 2147 tr("Could not get size of the ISO file '%s' "), 2148 RTPathFilename(strSrcFilePath.c_str())); 2149 2150 vrc = RTFileRead(pFile, pvTmpBuf, cbFile, &cbSize); 2151 2152 if (RT_FAILURE(vrc)) 2153 { 2154 if (pvTmpBuf) 2155 RTMemFree(pvTmpBuf); 2156 throw setError(VBOX_E_FILE_ERROR, 2157 tr("Could not read the ISO file '%s' (%Rrc)"), 2158 RTPathFilename(strSrcFilePath.c_str()), vrc); 2159 } 2160 } 2161 2162 RTFileClose(pFile); 2163 } 2164 2165 /* Write the ISO file to disk. */ 2166 vrc = ShaWriteBuf(strTargetFilePath.c_str(), pvTmpBuf, cbSize, pIfIo, pStorage); 2167 RTMemFree(pvTmpBuf); 2129 void *pvStorage; 2130 RTFILE pFile = NULL; 2131 void *pvUser = pStorage; 2132 2133 vrc = pIfIo->pfnOpen(pvUser, strTargetFilePath.c_str(), 2134 RTFILE_O_OPEN_CREATE | RTFILE_O_WRITE | RTFILE_O_DENY_NONE, 2135 0, 2136 &pvStorage); 2168 2137 if (RT_FAILURE(vrc)) 2169 2138 throw setError(VBOX_E_FILE_ERROR, 2170 tr("Could not create ISOfile '%s' (%Rrc)"),2139 tr("Could not create or open file '%s' (%Rrc)"), 2171 2140 strTargetFilePath.c_str(), vrc); 2141 2142 vrc = RTFileOpen(&pFile, 2143 strSrcFilePath.c_str(), 2144 RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE); 2145 2146 if (RT_FAILURE(vrc) || pFile == NULL) 2147 { 2148 pIfIo->pfnClose(pvUser, pvStorage); 2149 throw setError(VBOX_E_FILE_ERROR, 2150 tr("Could not create or open file '%s' (%Rrc)"), 2151 strSrcFilePath.c_str(), vrc); 2152 } 2153 2154 void *pvTmpBuf = 0; 2155 uint64_t cbTmpSize = _1M; 2156 size_t cbAllWritten = 0; 2157 uint64_t cbFile = 0; 2158 uint64_t cbSize = 0; 2159 2160 vrc = RTFileGetSize(pFile, &cbFile); 2161 2162 do 2163 { 2164 pvTmpBuf = RTMemAlloc(cbTmpSize); 2165 if (!pvTmpBuf) 2166 { 2167 vrc = VERR_NO_MEMORY; 2168 break; 2169 } 2170 2171 for (;;) 2172 { 2173 // copy raw data into the buffer pvTmpBuf 2174 vrc = RTFileRead(pFile, pvTmpBuf, cbTmpSize, &cbSize); 2175 2176 if (RT_FAILURE(vrc) || cbSize == 0) 2177 break; 2178 2179 size_t cbToWrite = cbSize; 2180 size_t cbWritten = 0; 2181 2182 vrc = pIfIo->pfnWriteSync(pvUser, 2183 pvStorage, 2184 cbAllWritten, 2185 pvTmpBuf, 2186 cbToWrite,&cbWritten); 2187 2188 if (RT_FAILURE(vrc)) 2189 break; 2190 2191 cbAllWritten += cbWritten; 2192 } 2193 } while (0); 2194 2195 pIfIo->pfnClose(pvUser, pvStorage); 2196 RTFileClose(pFile); 2197 2198 if (pvTmpBuf) 2199 RTMemFree(pvTmpBuf); 2200 2201 if (RT_FAILURE(vrc)) 2202 { 2203 if (vrc == VERR_EOF) 2204 vrc = VINF_SUCCESS; 2205 else 2206 throw setError(VBOX_E_FILE_ERROR, 2207 tr("Error during copy CD/DVD image '%s' (%Rrc)"), 2208 strSrcFilePath.c_str(), vrc); 2209 } 2172 2210 } 2173 2211 }
Note:
See TracChangeset
for help on using the changeset viewer.