Fossil SCM
Change zip archiver to make use of blob.c mechanisms for adding prefixes to file names. Remove C constructs that are not commonly supported.
Commit
4bbb00a8c8924323d4dc61e49a24993f14682d62
Parent
091499ec1a4002f…
1 file changed
+20
-24
+20
-24
| --- src/zip.c | ||
| +++ src/zip.c | ||
| @@ -265,71 +265,67 @@ | ||
| 265 | 265 | ** object. |
| 266 | 266 | ** |
| 267 | 267 | ** If the RID object does not exist in the repository, then |
| 268 | 268 | ** pZip is zeroed. |
| 269 | 269 | ** |
| 270 | -** zSynthDir is a "synthetic" subdirectory which all zipped files get | |
| 270 | +** zDir is a "synthetic" subdirectory which all zipped files get | |
| 271 | 271 | ** added to as part of the zip file. It may be 0 or an empty string, |
| 272 | 272 | ** in which case it is ignored. The intention is to create a zip which |
| 273 | 273 | ** politely expands into a subdir instead of filling your current dir |
| 274 | 274 | ** with source files. For example, pass a UUID or "ProjectName". |
| 275 | 275 | ** |
| 276 | 276 | */ |
| 277 | -void zip_of_baseline(int rid, Blob *pZip, char const * zSynthDir ){ | |
| 277 | +void zip_of_baseline(int rid, Blob *pZip, const char *zDir){ | |
| 278 | 278 | int i; |
| 279 | 279 | Blob mfile, file, hash; |
| 280 | 280 | Manifest m; |
| 281 | - char const * zDir = (zSynthDir && zSynthDir[0]) ? zSynthDir : ""; | |
| 281 | + Blob filename; | |
| 282 | + int nPrefix; | |
| 283 | + | |
| 282 | 284 | content_get(rid, &mfile); |
| 283 | 285 | if( blob_size(&mfile)==0 ){ |
| 284 | 286 | blob_zero(pZip); |
| 285 | 287 | return; |
| 286 | 288 | } |
| 287 | 289 | blob_zero(&file); |
| 288 | 290 | blob_zero(&hash); |
| 289 | 291 | blob_copy(&file, &mfile); |
| 292 | + blob_zero(&filename); | |
| 290 | 293 | zip_open(); |
| 291 | 294 | |
| 292 | - const int dirLen = strlen(zDir); | |
| 293 | - char zPrefix[dirLen+2]; | |
| 294 | - memset(zPrefix, 0, sizeof(zPrefix)); | |
| 295 | - if( zDir[0] ){ | |
| 296 | - snprintf( zPrefix, sizeof(zPrefix), "%s/", zDir ); | |
| 297 | - } | |
| 298 | - const int bufsize = 512; | |
| 299 | - char aSBuf[bufsize]; | |
| 300 | - int prxLen = strlen(zPrefix); | |
| 301 | - memcpy(aSBuf, zPrefix, prxLen); | |
| 302 | - char * zHead = aSBuf + prxLen; | |
| 303 | - /* Rather than use a lot of mprintf()s here, we reuse aSBuf as a | |
| 304 | - ** buffer for the prefix + current file name. zHead keeps track | |
| 305 | - ** of where we should write file names to this buffer. | |
| 306 | - */ | |
| 295 | + if( zDir && zDir[0] ){ | |
| 296 | + blob_appendf(&filename, "%s/", zDir); | |
| 297 | + } | |
| 298 | + nPrefix = blob_size(&filename); | |
| 299 | + | |
| 307 | 300 | if( manifest_parse(&m, &mfile) ){ |
| 308 | 301 | zip_set_timedate(m.rDate); |
| 309 | - snprintf( zHead, bufsize-prxLen, "manifest" ); | |
| 310 | - zip_add_file(aSBuf, &file); | |
| 302 | + blob_append(&filename, "manifest", -1); | |
| 303 | + zip_add_file(blob_str(&filename), &file); | |
| 311 | 304 | sha1sum_blob(&file, &hash); |
| 312 | 305 | blob_reset(&file); |
| 313 | 306 | blob_append(&hash, "\n", 1); |
| 314 | - snprintf( zHead, bufsize-prxLen, "manifest.uuid" ); | |
| 315 | - zip_add_file(aSBuf, &hash); | |
| 307 | + blob_resize(&filename, nPrefix); | |
| 308 | + blob_append(&filename, "manifest.uuid", -1); | |
| 309 | + zip_add_file(blob_str(&filename), &hash); | |
| 316 | 310 | blob_reset(&hash); |
| 317 | 311 | for(i=0; i<m.nFile; i++){ |
| 318 | 312 | int fid = uuid_to_rid(m.aFile[i].zUuid, 0); |
| 319 | 313 | if( fid ){ |
| 320 | 314 | content_get(fid, &file); |
| 321 | - snprintf( zHead, bufsize-prxLen, "%s", m.aFile[i].zName ); | |
| 322 | - zip_add_file( aSBuf, &file); | |
| 315 | + blob_resize(&filename, nPrefix); | |
| 316 | + blob_append(&filename, m.aFile[i].zName, -1); | |
| 317 | + zip_add_file(blob_str(&filename), &file); | |
| 323 | 318 | blob_reset(&file); |
| 324 | 319 | } |
| 325 | 320 | } |
| 326 | 321 | manifest_clear(&m); |
| 327 | 322 | }else{ |
| 328 | 323 | blob_reset(&mfile); |
| 329 | 324 | blob_reset(&file); |
| 330 | 325 | } |
| 326 | + blob_reset(&filename); | |
| 331 | 327 | zip_close(pZip); |
| 332 | 328 | } |
| 333 | 329 | |
| 334 | 330 | /* |
| 335 | 331 | ** COMMAND: test-baseline-zip |
| 336 | 332 |
| --- src/zip.c | |
| +++ src/zip.c | |
| @@ -265,71 +265,67 @@ | |
| 265 | ** object. |
| 266 | ** |
| 267 | ** If the RID object does not exist in the repository, then |
| 268 | ** pZip is zeroed. |
| 269 | ** |
| 270 | ** zSynthDir is a "synthetic" subdirectory which all zipped files get |
| 271 | ** added to as part of the zip file. It may be 0 or an empty string, |
| 272 | ** in which case it is ignored. The intention is to create a zip which |
| 273 | ** politely expands into a subdir instead of filling your current dir |
| 274 | ** with source files. For example, pass a UUID or "ProjectName". |
| 275 | ** |
| 276 | */ |
| 277 | void zip_of_baseline(int rid, Blob *pZip, char const * zSynthDir ){ |
| 278 | int i; |
| 279 | Blob mfile, file, hash; |
| 280 | Manifest m; |
| 281 | char const * zDir = (zSynthDir && zSynthDir[0]) ? zSynthDir : ""; |
| 282 | content_get(rid, &mfile); |
| 283 | if( blob_size(&mfile)==0 ){ |
| 284 | blob_zero(pZip); |
| 285 | return; |
| 286 | } |
| 287 | blob_zero(&file); |
| 288 | blob_zero(&hash); |
| 289 | blob_copy(&file, &mfile); |
| 290 | zip_open(); |
| 291 | |
| 292 | const int dirLen = strlen(zDir); |
| 293 | char zPrefix[dirLen+2]; |
| 294 | memset(zPrefix, 0, sizeof(zPrefix)); |
| 295 | if( zDir[0] ){ |
| 296 | snprintf( zPrefix, sizeof(zPrefix), "%s/", zDir ); |
| 297 | } |
| 298 | const int bufsize = 512; |
| 299 | char aSBuf[bufsize]; |
| 300 | int prxLen = strlen(zPrefix); |
| 301 | memcpy(aSBuf, zPrefix, prxLen); |
| 302 | char * zHead = aSBuf + prxLen; |
| 303 | /* Rather than use a lot of mprintf()s here, we reuse aSBuf as a |
| 304 | ** buffer for the prefix + current file name. zHead keeps track |
| 305 | ** of where we should write file names to this buffer. |
| 306 | */ |
| 307 | if( manifest_parse(&m, &mfile) ){ |
| 308 | zip_set_timedate(m.rDate); |
| 309 | snprintf( zHead, bufsize-prxLen, "manifest" ); |
| 310 | zip_add_file(aSBuf, &file); |
| 311 | sha1sum_blob(&file, &hash); |
| 312 | blob_reset(&file); |
| 313 | blob_append(&hash, "\n", 1); |
| 314 | snprintf( zHead, bufsize-prxLen, "manifest.uuid" ); |
| 315 | zip_add_file(aSBuf, &hash); |
| 316 | blob_reset(&hash); |
| 317 | for(i=0; i<m.nFile; i++){ |
| 318 | int fid = uuid_to_rid(m.aFile[i].zUuid, 0); |
| 319 | if( fid ){ |
| 320 | content_get(fid, &file); |
| 321 | snprintf( zHead, bufsize-prxLen, "%s", m.aFile[i].zName ); |
| 322 | zip_add_file( aSBuf, &file); |
| 323 | blob_reset(&file); |
| 324 | } |
| 325 | } |
| 326 | manifest_clear(&m); |
| 327 | }else{ |
| 328 | blob_reset(&mfile); |
| 329 | blob_reset(&file); |
| 330 | } |
| 331 | zip_close(pZip); |
| 332 | } |
| 333 | |
| 334 | /* |
| 335 | ** COMMAND: test-baseline-zip |
| 336 |
| --- src/zip.c | |
| +++ src/zip.c | |
| @@ -265,71 +265,67 @@ | |
| 265 | ** object. |
| 266 | ** |
| 267 | ** If the RID object does not exist in the repository, then |
| 268 | ** pZip is zeroed. |
| 269 | ** |
| 270 | ** zDir is a "synthetic" subdirectory which all zipped files get |
| 271 | ** added to as part of the zip file. It may be 0 or an empty string, |
| 272 | ** in which case it is ignored. The intention is to create a zip which |
| 273 | ** politely expands into a subdir instead of filling your current dir |
| 274 | ** with source files. For example, pass a UUID or "ProjectName". |
| 275 | ** |
| 276 | */ |
| 277 | void zip_of_baseline(int rid, Blob *pZip, const char *zDir){ |
| 278 | int i; |
| 279 | Blob mfile, file, hash; |
| 280 | Manifest m; |
| 281 | Blob filename; |
| 282 | int nPrefix; |
| 283 | |
| 284 | content_get(rid, &mfile); |
| 285 | if( blob_size(&mfile)==0 ){ |
| 286 | blob_zero(pZip); |
| 287 | return; |
| 288 | } |
| 289 | blob_zero(&file); |
| 290 | blob_zero(&hash); |
| 291 | blob_copy(&file, &mfile); |
| 292 | blob_zero(&filename); |
| 293 | zip_open(); |
| 294 | |
| 295 | if( zDir && zDir[0] ){ |
| 296 | blob_appendf(&filename, "%s/", zDir); |
| 297 | } |
| 298 | nPrefix = blob_size(&filename); |
| 299 | |
| 300 | if( manifest_parse(&m, &mfile) ){ |
| 301 | zip_set_timedate(m.rDate); |
| 302 | blob_append(&filename, "manifest", -1); |
| 303 | zip_add_file(blob_str(&filename), &file); |
| 304 | sha1sum_blob(&file, &hash); |
| 305 | blob_reset(&file); |
| 306 | blob_append(&hash, "\n", 1); |
| 307 | blob_resize(&filename, nPrefix); |
| 308 | blob_append(&filename, "manifest.uuid", -1); |
| 309 | zip_add_file(blob_str(&filename), &hash); |
| 310 | blob_reset(&hash); |
| 311 | for(i=0; i<m.nFile; i++){ |
| 312 | int fid = uuid_to_rid(m.aFile[i].zUuid, 0); |
| 313 | if( fid ){ |
| 314 | content_get(fid, &file); |
| 315 | blob_resize(&filename, nPrefix); |
| 316 | blob_append(&filename, m.aFile[i].zName, -1); |
| 317 | zip_add_file(blob_str(&filename), &file); |
| 318 | blob_reset(&file); |
| 319 | } |
| 320 | } |
| 321 | manifest_clear(&m); |
| 322 | }else{ |
| 323 | blob_reset(&mfile); |
| 324 | blob_reset(&file); |
| 325 | } |
| 326 | blob_reset(&filename); |
| 327 | zip_close(pZip); |
| 328 | } |
| 329 | |
| 330 | /* |
| 331 | ** COMMAND: test-baseline-zip |
| 332 |