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.

drh 2008-02-08 22:31 trunk
Commit 4bbb00a8c8924323d4dc61e49a24993f14682d62
1 file changed +20 -24
+20 -24
--- src/zip.c
+++ src/zip.c
@@ -265,71 +265,67 @@
265265
** object.
266266
**
267267
** If the RID object does not exist in the repository, then
268268
** pZip is zeroed.
269269
**
270
-** zSynthDir is a "synthetic" subdirectory which all zipped files get
270
+** zDir is a "synthetic" subdirectory which all zipped files get
271271
** added to as part of the zip file. It may be 0 or an empty string,
272272
** in which case it is ignored. The intention is to create a zip which
273273
** politely expands into a subdir instead of filling your current dir
274274
** with source files. For example, pass a UUID or "ProjectName".
275275
**
276276
*/
277
-void zip_of_baseline(int rid, Blob *pZip, char const * zSynthDir ){
277
+void zip_of_baseline(int rid, Blob *pZip, const char *zDir){
278278
int i;
279279
Blob mfile, file, hash;
280280
Manifest m;
281
- char const * zDir = (zSynthDir && zSynthDir[0]) ? zSynthDir : "";
281
+ Blob filename;
282
+ int nPrefix;
283
+
282284
content_get(rid, &mfile);
283285
if( blob_size(&mfile)==0 ){
284286
blob_zero(pZip);
285287
return;
286288
}
287289
blob_zero(&file);
288290
blob_zero(&hash);
289291
blob_copy(&file, &mfile);
292
+ blob_zero(&filename);
290293
zip_open();
291294
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
+
307300
if( manifest_parse(&m, &mfile) ){
308301
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);
311304
sha1sum_blob(&file, &hash);
312305
blob_reset(&file);
313306
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);
316310
blob_reset(&hash);
317311
for(i=0; i<m.nFile; i++){
318312
int fid = uuid_to_rid(m.aFile[i].zUuid, 0);
319313
if( fid ){
320314
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);
323318
blob_reset(&file);
324319
}
325320
}
326321
manifest_clear(&m);
327322
}else{
328323
blob_reset(&mfile);
329324
blob_reset(&file);
330325
}
326
+ blob_reset(&filename);
331327
zip_close(pZip);
332328
}
333329
334330
/*
335331
** COMMAND: test-baseline-zip
336332
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button