Fossil SCM
Fix the ZIP archive generator so that it works correctly with the OS X Archive Tool. Ticket [923a912309].
Commit
d78835d2ffb6672e214f470af6caeb9cccd9d8c0
Parent
232d10b7365e2d0…
1 file changed
+5
-22
+5
-22
| --- src/zip.c | ||
| +++ src/zip.c | ||
| @@ -126,12 +126,11 @@ | ||
| 126 | 126 | ** that the file should be saved as. |
| 127 | 127 | */ |
| 128 | 128 | void zip_add_file(const char *zName, const Blob *pFile){ |
| 129 | 129 | z_stream stream; |
| 130 | 130 | int nameLen; |
| 131 | - int skip; | |
| 132 | - int toOut; | |
| 131 | + int toOut = 0; | |
| 133 | 132 | int iStart; |
| 134 | 133 | int iCRC = 0; |
| 135 | 134 | int nByte = 0; |
| 136 | 135 | int nByteCompr = 0; |
| 137 | 136 | int nBlob; /* Size of the blob */ |
| @@ -177,53 +176,37 @@ | ||
| 177 | 176 | blob_append(&body, zHdr, 30); |
| 178 | 177 | blob_append(&body, zName, nameLen); |
| 179 | 178 | blob_append(&body, zExTime, 13); |
| 180 | 179 | |
| 181 | 180 | if( nBlob>0 ){ |
| 182 | - /* The first two bytes that come out of the deflate compressor are | |
| 183 | - ** some kind of header that ZIP does not use. So skip the first two | |
| 184 | - ** output bytes. | |
| 185 | - */ | |
| 186 | - skip = 2; | |
| 187 | - | |
| 188 | 181 | /* Write the compressed file. Compute the CRC as we progress. |
| 189 | 182 | */ |
| 190 | 183 | stream.zalloc = (alloc_func)0; |
| 191 | 184 | stream.zfree = (free_func)0; |
| 192 | 185 | stream.opaque = 0; |
| 193 | 186 | stream.avail_in = blob_size(pFile); |
| 194 | 187 | stream.next_in = (unsigned char*)blob_buffer(pFile); |
| 195 | 188 | stream.avail_out = sizeof(zOutBuf); |
| 196 | 189 | stream.next_out = (unsigned char*)zOutBuf; |
| 197 | - deflateInit(&stream, 9); | |
| 190 | + deflateInit2(&stream, 9, Z_DEFLATED, -MAX_WBITS, 8, Z_DEFAULT_STRATEGY); | |
| 198 | 191 | iCRC = crc32(0, stream.next_in, stream.avail_in); |
| 199 | 192 | while( stream.avail_in>0 ){ |
| 200 | 193 | deflate(&stream, 0); |
| 201 | 194 | toOut = sizeof(zOutBuf) - stream.avail_out; |
| 202 | - if( toOut>skip ){ | |
| 203 | - blob_append(&body, &zOutBuf[skip], toOut - skip); | |
| 204 | - skip = 0; | |
| 205 | - }else{ | |
| 206 | - skip -= toOut; | |
| 207 | - } | |
| 195 | + blob_append(&body, zOutBuf, toOut); | |
| 208 | 196 | stream.avail_out = sizeof(zOutBuf); |
| 209 | 197 | stream.next_out = (unsigned char*)zOutBuf; |
| 210 | 198 | } |
| 211 | 199 | do{ |
| 212 | 200 | stream.avail_out = sizeof(zOutBuf); |
| 213 | 201 | stream.next_out = (unsigned char*)zOutBuf; |
| 214 | 202 | deflate(&stream, Z_FINISH); |
| 215 | 203 | toOut = sizeof(zOutBuf) - stream.avail_out; |
| 216 | - if( toOut>skip ){ | |
| 217 | - blob_append(&body, &zOutBuf[skip], toOut - skip); | |
| 218 | - skip = 0; | |
| 219 | - }else{ | |
| 220 | - skip -= toOut; | |
| 221 | - } | |
| 204 | + blob_append(&body, zOutBuf, toOut); | |
| 222 | 205 | }while( stream.avail_out==0 ); |
| 223 | 206 | nByte = stream.total_in; |
| 224 | - nByteCompr = stream.total_out - 2; | |
| 207 | + nByteCompr = stream.total_out; | |
| 225 | 208 | deflateEnd(&stream); |
| 226 | 209 | |
| 227 | 210 | /* Go back and write the header, now that we know the compressed file size. |
| 228 | 211 | */ |
| 229 | 212 | z = &blob_buffer(&body)[iStart]; |
| 230 | 213 |
| --- src/zip.c | |
| +++ src/zip.c | |
| @@ -126,12 +126,11 @@ | |
| 126 | ** that the file should be saved as. |
| 127 | */ |
| 128 | void zip_add_file(const char *zName, const Blob *pFile){ |
| 129 | z_stream stream; |
| 130 | int nameLen; |
| 131 | int skip; |
| 132 | int toOut; |
| 133 | int iStart; |
| 134 | int iCRC = 0; |
| 135 | int nByte = 0; |
| 136 | int nByteCompr = 0; |
| 137 | int nBlob; /* Size of the blob */ |
| @@ -177,53 +176,37 @@ | |
| 177 | blob_append(&body, zHdr, 30); |
| 178 | blob_append(&body, zName, nameLen); |
| 179 | blob_append(&body, zExTime, 13); |
| 180 | |
| 181 | if( nBlob>0 ){ |
| 182 | /* The first two bytes that come out of the deflate compressor are |
| 183 | ** some kind of header that ZIP does not use. So skip the first two |
| 184 | ** output bytes. |
| 185 | */ |
| 186 | skip = 2; |
| 187 | |
| 188 | /* Write the compressed file. Compute the CRC as we progress. |
| 189 | */ |
| 190 | stream.zalloc = (alloc_func)0; |
| 191 | stream.zfree = (free_func)0; |
| 192 | stream.opaque = 0; |
| 193 | stream.avail_in = blob_size(pFile); |
| 194 | stream.next_in = (unsigned char*)blob_buffer(pFile); |
| 195 | stream.avail_out = sizeof(zOutBuf); |
| 196 | stream.next_out = (unsigned char*)zOutBuf; |
| 197 | deflateInit(&stream, 9); |
| 198 | iCRC = crc32(0, stream.next_in, stream.avail_in); |
| 199 | while( stream.avail_in>0 ){ |
| 200 | deflate(&stream, 0); |
| 201 | toOut = sizeof(zOutBuf) - stream.avail_out; |
| 202 | if( toOut>skip ){ |
| 203 | blob_append(&body, &zOutBuf[skip], toOut - skip); |
| 204 | skip = 0; |
| 205 | }else{ |
| 206 | skip -= toOut; |
| 207 | } |
| 208 | stream.avail_out = sizeof(zOutBuf); |
| 209 | stream.next_out = (unsigned char*)zOutBuf; |
| 210 | } |
| 211 | do{ |
| 212 | stream.avail_out = sizeof(zOutBuf); |
| 213 | stream.next_out = (unsigned char*)zOutBuf; |
| 214 | deflate(&stream, Z_FINISH); |
| 215 | toOut = sizeof(zOutBuf) - stream.avail_out; |
| 216 | if( toOut>skip ){ |
| 217 | blob_append(&body, &zOutBuf[skip], toOut - skip); |
| 218 | skip = 0; |
| 219 | }else{ |
| 220 | skip -= toOut; |
| 221 | } |
| 222 | }while( stream.avail_out==0 ); |
| 223 | nByte = stream.total_in; |
| 224 | nByteCompr = stream.total_out - 2; |
| 225 | deflateEnd(&stream); |
| 226 | |
| 227 | /* Go back and write the header, now that we know the compressed file size. |
| 228 | */ |
| 229 | z = &blob_buffer(&body)[iStart]; |
| 230 |
| --- src/zip.c | |
| +++ src/zip.c | |
| @@ -126,12 +126,11 @@ | |
| 126 | ** that the file should be saved as. |
| 127 | */ |
| 128 | void zip_add_file(const char *zName, const Blob *pFile){ |
| 129 | z_stream stream; |
| 130 | int nameLen; |
| 131 | int toOut = 0; |
| 132 | int iStart; |
| 133 | int iCRC = 0; |
| 134 | int nByte = 0; |
| 135 | int nByteCompr = 0; |
| 136 | int nBlob; /* Size of the blob */ |
| @@ -177,53 +176,37 @@ | |
| 176 | blob_append(&body, zHdr, 30); |
| 177 | blob_append(&body, zName, nameLen); |
| 178 | blob_append(&body, zExTime, 13); |
| 179 | |
| 180 | if( nBlob>0 ){ |
| 181 | /* Write the compressed file. Compute the CRC as we progress. |
| 182 | */ |
| 183 | stream.zalloc = (alloc_func)0; |
| 184 | stream.zfree = (free_func)0; |
| 185 | stream.opaque = 0; |
| 186 | stream.avail_in = blob_size(pFile); |
| 187 | stream.next_in = (unsigned char*)blob_buffer(pFile); |
| 188 | stream.avail_out = sizeof(zOutBuf); |
| 189 | stream.next_out = (unsigned char*)zOutBuf; |
| 190 | deflateInit2(&stream, 9, Z_DEFLATED, -MAX_WBITS, 8, Z_DEFAULT_STRATEGY); |
| 191 | iCRC = crc32(0, stream.next_in, stream.avail_in); |
| 192 | while( stream.avail_in>0 ){ |
| 193 | deflate(&stream, 0); |
| 194 | toOut = sizeof(zOutBuf) - stream.avail_out; |
| 195 | blob_append(&body, zOutBuf, toOut); |
| 196 | stream.avail_out = sizeof(zOutBuf); |
| 197 | stream.next_out = (unsigned char*)zOutBuf; |
| 198 | } |
| 199 | do{ |
| 200 | stream.avail_out = sizeof(zOutBuf); |
| 201 | stream.next_out = (unsigned char*)zOutBuf; |
| 202 | deflate(&stream, Z_FINISH); |
| 203 | toOut = sizeof(zOutBuf) - stream.avail_out; |
| 204 | blob_append(&body, zOutBuf, toOut); |
| 205 | }while( stream.avail_out==0 ); |
| 206 | nByte = stream.total_in; |
| 207 | nByteCompr = stream.total_out; |
| 208 | deflateEnd(&stream); |
| 209 | |
| 210 | /* Go back and write the header, now that we know the compressed file size. |
| 211 | */ |
| 212 | z = &blob_buffer(&body)[iStart]; |
| 213 |