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.
Commit
31b9822d697eaba8713ca732a4f076a78be98478158327a9089ecc55227ca3c0
Parent
3e2b5c4630aaf66…
1 file changed
+5
-2
+5
-2
| --- src/zip.c | ||
| +++ src/zip.c | ||
| @@ -274,10 +274,12 @@ | ||
| 274 | 274 | char zBuf[100]; |
| 275 | 275 | char zOutBuf[100000]; |
| 276 | 276 | |
| 277 | 277 | /* Fill in as much of the header as we know. |
| 278 | 278 | */ |
| 279 | + nameLen = (int)strlen(zName); | |
| 280 | + if( nameLen==0 ) return; | |
| 279 | 281 | nBlob = pFile ? blob_size(pFile) : 0; |
| 280 | 282 | if( pFile ){ /* This is a file, possibly empty... */ |
| 281 | 283 | iMethod = (nBlob>0) ? 8 : 0; /* Cannot compress zero bytes. */ |
| 282 | 284 | switch( mPerm ){ |
| 283 | 285 | case PERM_LNK: iMode = 0120755; break; |
| @@ -286,11 +288,10 @@ | ||
| 286 | 288 | } |
| 287 | 289 | }else{ /* This is a directory, no blob... */ |
| 288 | 290 | iMethod = 0; |
| 289 | 291 | iMode = 040755; |
| 290 | 292 | } |
| 291 | - nameLen = strlen(zName); | |
| 292 | 293 | memset(zHdr, 0, sizeof(zHdr)); |
| 293 | 294 | put32(&zHdr[0], 0x04034b50); |
| 294 | 295 | put16(&zHdr[4], 0x000a); |
| 295 | 296 | put16(&zHdr[6], 0x0800); |
| 296 | 297 | put16(&zHdr[8], iMethod); |
| @@ -382,11 +383,11 @@ | ||
| 382 | 383 | Archive *p, |
| 383 | 384 | const char *zName, |
| 384 | 385 | const Blob *pFile, |
| 385 | 386 | int mPerm |
| 386 | 387 | ){ |
| 387 | - int nName = strlen(zName); | |
| 388 | + int nName = (int)strlen(zName); | |
| 388 | 389 | |
| 389 | 390 | if( p->db==0 ){ |
| 390 | 391 | assert( p->vfs.zName==0 ); |
| 391 | 392 | p->vfs.zName = (const char*)mprintf("archivevfs%p", (void*)p); |
| 392 | 393 | p->vfs.iVersion = 1; |
| @@ -428,10 +429,11 @@ | ||
| 428 | 429 | |
| 429 | 430 | sqlite3_bind_int64(p->pInsert, 3, unixTime); |
| 430 | 431 | blob_zero(p->pBlob); |
| 431 | 432 | } |
| 432 | 433 | |
| 434 | + if( nName==0 ) return; | |
| 433 | 435 | if( pFile==0 ){ |
| 434 | 436 | /* Directory. */ |
| 435 | 437 | if( zName[nName-1]=='/' ) nName--; |
| 436 | 438 | sqlite3_bind_text(p->pInsert, 1, zName, nName, SQLITE_STATIC); |
| 437 | 439 | sqlite3_bind_int(p->pInsert, 2, 040755); |
| @@ -701,10 +703,11 @@ | ||
| 701 | 703 | zip_add_file(&sArchive, zName, &tagslist, 0); |
| 702 | 704 | blob_reset(&tagslist); |
| 703 | 705 | } |
| 704 | 706 | } |
| 705 | 707 | manifest_file_rewind(pManifest); |
| 708 | + zip_add_file(&sArchive, "", 0, 0); | |
| 706 | 709 | while( (pFile = manifest_file_next(pManifest,0))!=0 ){ |
| 707 | 710 | int fid; |
| 708 | 711 | if( pInclude!=0 && !glob_match(pInclude, pFile->zName) ) continue; |
| 709 | 712 | if( glob_match(pExclude, pFile->zName) ) continue; |
| 710 | 713 | fid = uuid_to_rid(pFile->zUuid, 0); |
| 711 | 714 |
| --- 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 |