Fossil SCM

Fix the SQL archive generator so that for a check-in containing no files it generates an empty SQL archive instead of an empty file.

drh 2017-12-08 03:24 trunk
Commit 31b9822d697eaba8713ca732a4f076a78be98478158327a9089ecc55227ca3c0
1 file changed +5 -2
+5 -2
--- src/zip.c
+++ src/zip.c
@@ -274,10 +274,12 @@
274274
char zBuf[100];
275275
char zOutBuf[100000];
276276
277277
/* Fill in as much of the header as we know.
278278
*/
279
+ nameLen = (int)strlen(zName);
280
+ if( nameLen==0 ) return;
279281
nBlob = pFile ? blob_size(pFile) : 0;
280282
if( pFile ){ /* This is a file, possibly empty... */
281283
iMethod = (nBlob>0) ? 8 : 0; /* Cannot compress zero bytes. */
282284
switch( mPerm ){
283285
case PERM_LNK: iMode = 0120755; break;
@@ -286,11 +288,10 @@
286288
}
287289
}else{ /* This is a directory, no blob... */
288290
iMethod = 0;
289291
iMode = 040755;
290292
}
291
- nameLen = strlen(zName);
292293
memset(zHdr, 0, sizeof(zHdr));
293294
put32(&zHdr[0], 0x04034b50);
294295
put16(&zHdr[4], 0x000a);
295296
put16(&zHdr[6], 0x0800);
296297
put16(&zHdr[8], iMethod);
@@ -382,11 +383,11 @@
382383
Archive *p,
383384
const char *zName,
384385
const Blob *pFile,
385386
int mPerm
386387
){
387
- int nName = strlen(zName);
388
+ int nName = (int)strlen(zName);
388389
389390
if( p->db==0 ){
390391
assert( p->vfs.zName==0 );
391392
p->vfs.zName = (const char*)mprintf("archivevfs%p", (void*)p);
392393
p->vfs.iVersion = 1;
@@ -428,10 +429,11 @@
428429
429430
sqlite3_bind_int64(p->pInsert, 3, unixTime);
430431
blob_zero(p->pBlob);
431432
}
432433
434
+ if( nName==0 ) return;
433435
if( pFile==0 ){
434436
/* Directory. */
435437
if( zName[nName-1]=='/' ) nName--;
436438
sqlite3_bind_text(p->pInsert, 1, zName, nName, SQLITE_STATIC);
437439
sqlite3_bind_int(p->pInsert, 2, 040755);
@@ -701,10 +703,11 @@
701703
zip_add_file(&sArchive, zName, &tagslist, 0);
702704
blob_reset(&tagslist);
703705
}
704706
}
705707
manifest_file_rewind(pManifest);
708
+ zip_add_file(&sArchive, "", 0, 0);
706709
while( (pFile = manifest_file_next(pManifest,0))!=0 ){
707710
int fid;
708711
if( pInclude!=0 && !glob_match(pInclude, pFile->zName) ) continue;
709712
if( glob_match(pExclude, pFile->zName) ) continue;
710713
fid = uuid_to_rid(pFile->zUuid, 0);
711714
--- src/zip.c
+++ src/zip.c
@@ -274,10 +274,12 @@
274 char zBuf[100];
275 char zOutBuf[100000];
276
277 /* Fill in as much of the header as we know.
278 */
 
 
279 nBlob = pFile ? blob_size(pFile) : 0;
280 if( pFile ){ /* This is a file, possibly empty... */
281 iMethod = (nBlob>0) ? 8 : 0; /* Cannot compress zero bytes. */
282 switch( mPerm ){
283 case PERM_LNK: iMode = 0120755; break;
@@ -286,11 +288,10 @@
286 }
287 }else{ /* This is a directory, no blob... */
288 iMethod = 0;
289 iMode = 040755;
290 }
291 nameLen = strlen(zName);
292 memset(zHdr, 0, sizeof(zHdr));
293 put32(&zHdr[0], 0x04034b50);
294 put16(&zHdr[4], 0x000a);
295 put16(&zHdr[6], 0x0800);
296 put16(&zHdr[8], iMethod);
@@ -382,11 +383,11 @@
382 Archive *p,
383 const char *zName,
384 const Blob *pFile,
385 int mPerm
386 ){
387 int nName = strlen(zName);
388
389 if( p->db==0 ){
390 assert( p->vfs.zName==0 );
391 p->vfs.zName = (const char*)mprintf("archivevfs%p", (void*)p);
392 p->vfs.iVersion = 1;
@@ -428,10 +429,11 @@
428
429 sqlite3_bind_int64(p->pInsert, 3, unixTime);
430 blob_zero(p->pBlob);
431 }
432
 
433 if( pFile==0 ){
434 /* Directory. */
435 if( zName[nName-1]=='/' ) nName--;
436 sqlite3_bind_text(p->pInsert, 1, zName, nName, SQLITE_STATIC);
437 sqlite3_bind_int(p->pInsert, 2, 040755);
@@ -701,10 +703,11 @@
701 zip_add_file(&sArchive, zName, &tagslist, 0);
702 blob_reset(&tagslist);
703 }
704 }
705 manifest_file_rewind(pManifest);
 
706 while( (pFile = manifest_file_next(pManifest,0))!=0 ){
707 int fid;
708 if( pInclude!=0 && !glob_match(pInclude, pFile->zName) ) continue;
709 if( glob_match(pExclude, pFile->zName) ) continue;
710 fid = uuid_to_rid(pFile->zUuid, 0);
711
--- src/zip.c
+++ src/zip.c
@@ -274,10 +274,12 @@
274 char zBuf[100];
275 char zOutBuf[100000];
276
277 /* Fill in as much of the header as we know.
278 */
279 nameLen = (int)strlen(zName);
280 if( nameLen==0 ) return;
281 nBlob = pFile ? blob_size(pFile) : 0;
282 if( pFile ){ /* This is a file, possibly empty... */
283 iMethod = (nBlob>0) ? 8 : 0; /* Cannot compress zero bytes. */
284 switch( mPerm ){
285 case PERM_LNK: iMode = 0120755; break;
@@ -286,11 +288,10 @@
288 }
289 }else{ /* This is a directory, no blob... */
290 iMethod = 0;
291 iMode = 040755;
292 }
 
293 memset(zHdr, 0, sizeof(zHdr));
294 put32(&zHdr[0], 0x04034b50);
295 put16(&zHdr[4], 0x000a);
296 put16(&zHdr[6], 0x0800);
297 put16(&zHdr[8], iMethod);
@@ -382,11 +383,11 @@
383 Archive *p,
384 const char *zName,
385 const Blob *pFile,
386 int mPerm
387 ){
388 int nName = (int)strlen(zName);
389
390 if( p->db==0 ){
391 assert( p->vfs.zName==0 );
392 p->vfs.zName = (const char*)mprintf("archivevfs%p", (void*)p);
393 p->vfs.iVersion = 1;
@@ -428,10 +429,11 @@
429
430 sqlite3_bind_int64(p->pInsert, 3, unixTime);
431 blob_zero(p->pBlob);
432 }
433
434 if( nName==0 ) return;
435 if( pFile==0 ){
436 /* Directory. */
437 if( zName[nName-1]=='/' ) nName--;
438 sqlite3_bind_text(p->pInsert, 1, zName, nName, SQLITE_STATIC);
439 sqlite3_bind_int(p->pInsert, 2, 040755);
@@ -701,10 +703,11 @@
703 zip_add_file(&sArchive, zName, &tagslist, 0);
704 blob_reset(&tagslist);
705 }
706 }
707 manifest_file_rewind(pManifest);
708 zip_add_file(&sArchive, "", 0, 0);
709 while( (pFile = manifest_file_next(pManifest,0))!=0 ){
710 int fid;
711 if( pInclude!=0 && !glob_match(pInclude, pFile->zName) ) continue;
712 if( glob_match(pExclude, pFile->zName) ) continue;
713 fid = uuid_to_rid(pFile->zUuid, 0);
714

Keyboard Shortcuts

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