Rearrange things a bit so that writing to a zipfile does not invert the order
of objects it contains. FossilOrigin-Name: f69e8194bfa7de436c96028730ebd57f186d2e6207792e172e1aa38c7f4211c9
This commit is contained in:
parent
373dc3bb3f
commit
db0cb303ad
@ -218,7 +218,7 @@ struct ZipfileCsr {
|
||||
ZipfileLFH lfh; /* Local File Header for current entry */
|
||||
i64 iDataOff; /* Offset in zipfile to data */
|
||||
u32 mTime; /* Extended mtime value */
|
||||
int flags;
|
||||
int flags; /* Flags byte (see below for bits) */
|
||||
};
|
||||
|
||||
/*
|
||||
@ -229,9 +229,10 @@ struct ZipfileCsr {
|
||||
typedef struct ZipfileEntry ZipfileEntry;
|
||||
struct ZipfileEntry {
|
||||
char *zPath; /* Path of zipfile entry */
|
||||
i64 iRowid; /* Rowid for this value if queried */
|
||||
u8 *aCdsEntry; /* Buffer containing entire CDS entry */
|
||||
int nCdsEntry; /* Size of buffer aCdsEntry[] in bytes */
|
||||
ZipfileEntry *pNext;
|
||||
ZipfileEntry *pNext; /* Next element in in-memory CDS */
|
||||
};
|
||||
|
||||
typedef struct ZipfileTab ZipfileTab;
|
||||
@ -241,7 +242,8 @@ struct ZipfileTab {
|
||||
u8 *aBuffer; /* Temporary buffer used for various tasks */
|
||||
|
||||
/* The following are used by write transactions only */
|
||||
ZipfileEntry *pEntry; /* Linked list of all files (if pWriteFd!=0) */
|
||||
ZipfileEntry *pFirstEntry; /* Linked list of all files (if pWriteFd!=0) */
|
||||
ZipfileEntry *pLastEntry; /* Last element in pFirstEntry list */
|
||||
FILE *pWriteFd; /* File handle open on zip archive */
|
||||
i64 szCurrent; /* Current size of zip archive */
|
||||
i64 szOrig; /* Size of archive at start of transaction */
|
||||
@ -830,6 +832,22 @@ static int zipfileBestIndex(
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Add object pNew to the end of the linked list that begins at
|
||||
** ZipfileTab.pFirstEntry and ends with pLastEntry.
|
||||
*/
|
||||
static void zipfileAddEntry(ZipfileTab *pTab, ZipfileEntry *pNew){
|
||||
assert( (pTab->pFirstEntry==0)==(pTab->pLastEntry==0) );
|
||||
assert( pNew->pNext==0 );
|
||||
if( pTab->pFirstEntry==0 ){
|
||||
pTab->pFirstEntry = pTab->pLastEntry = pNew;
|
||||
}else{
|
||||
assert( pTab->pLastEntry->pNext==0 );
|
||||
pTab->pLastEntry->pNext = pNew;
|
||||
pTab->pLastEntry = pNew;
|
||||
}
|
||||
}
|
||||
|
||||
static int zipfileLoadDirectory(ZipfileTab *pTab){
|
||||
ZipfileEOCD eocd;
|
||||
int rc;
|
||||
@ -871,10 +889,9 @@ static int zipfileLoadDirectory(ZipfileTab *pTab){
|
||||
pNew->zPath[nFile] = '\0';
|
||||
pNew->aCdsEntry = (u8*)&pNew->zPath[nFile+1];
|
||||
pNew->nCdsEntry = ZIPFILE_CDS_FIXED_SZ+nFile+nExtra+nComment;
|
||||
pNew->pNext = 0;
|
||||
memcpy(pNew->aCdsEntry, aRec, pNew->nCdsEntry);
|
||||
|
||||
pNew->pNext = pTab->pEntry;
|
||||
pTab->pEntry = pNew;
|
||||
zipfileAddEntry(pTab, pNew);
|
||||
}
|
||||
|
||||
iOff += ZIPFILE_CDS_FIXED_SZ+nFile+nExtra+nComment;
|
||||
@ -908,6 +925,7 @@ static ZipfileEntry *zipfileNewEntry(
|
||||
pNew->zPath = (char*)&pNew[1];
|
||||
pNew->aCdsEntry = (u8*)&pNew->zPath[nPath+1];
|
||||
pNew->nCdsEntry = ZIPFILE_CDS_FIXED_SZ + nPath + pCds->nExtra;
|
||||
pNew->pNext = 0;
|
||||
memcpy(pNew->zPath, zPath, nPath+1);
|
||||
|
||||
aWrite = pNew->aCdsEntry;
|
||||
@ -1135,8 +1153,7 @@ static int zipfileUpdate(
|
||||
if( pNew==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
pNew->pNext = pTab->pEntry;
|
||||
pTab->pEntry = pNew;
|
||||
zipfileAddEntry(pTab, pNew);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1169,11 +1186,12 @@ static void zipfileCleanupTransaction(ZipfileTab *pTab){
|
||||
ZipfileEntry *pEntry;
|
||||
ZipfileEntry *pNext;
|
||||
|
||||
for(pEntry=pTab->pEntry; pEntry; pEntry=pNext){
|
||||
for(pEntry=pTab->pFirstEntry; pEntry; pEntry=pNext){
|
||||
pNext = pEntry->pNext;
|
||||
sqlite3_free(pEntry);
|
||||
}
|
||||
pTab->pEntry = 0;
|
||||
pTab->pFirstEntry = 0;
|
||||
pTab->pLastEntry = 0;
|
||||
fclose(pTab->pWriteFd);
|
||||
pTab->pWriteFd = 0;
|
||||
pTab->szCurrent = 0;
|
||||
@ -1189,13 +1207,13 @@ static int zipfileCommit(sqlite3_vtab *pVtab){
|
||||
int rc = SQLITE_OK;
|
||||
if( pTab->pWriteFd ){
|
||||
i64 iOffset = pTab->szCurrent;
|
||||
ZipfileEntry *pEntry;
|
||||
ZipfileEntry *p;
|
||||
ZipfileEOCD eocd;
|
||||
int nEntry = 0;
|
||||
|
||||
/* Write out all entries */
|
||||
for(pEntry=pTab->pEntry; rc==SQLITE_OK && pEntry; pEntry=pEntry->pNext){
|
||||
rc = zipfileAppendData(pTab, pEntry->aCdsEntry, pEntry->nCdsEntry);
|
||||
for(p=pTab->pFirstEntry; rc==SQLITE_OK && p; p=p->pNext){
|
||||
rc = zipfileAppendData(pTab, p->aCdsEntry, p->nCdsEntry);
|
||||
nEntry++;
|
||||
}
|
||||
|
||||
|
14
manifest
14
manifest
@ -1,5 +1,5 @@
|
||||
C Update\sext/misc/zipfile.c\sto\ssupport\screating\sand\sadding\sentries\sto\sexisting\nzip\sarchives.
|
||||
D 2017-12-29T20:19:03.196
|
||||
C Rearrange\sthings\sa\sbit\sso\sthat\swriting\sto\sa\szipfile\sdoes\snot\sinvert\sthe\sorder\nof\sobjects\sit\scontains.
|
||||
D 2017-12-30T14:26:29.195
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F Makefile.in ceb40bfcb30ebba8e1202b34c56ff7e13e112f9809e2381d99be32c2726058f5
|
||||
@ -302,7 +302,7 @@ F ext/misc/vfsstat.c bf10ef0bc51e1ad6756629e1edb142f7a8db1178
|
||||
F ext/misc/vtablog.c 31d0d8f4406795679dcd3a67917c213d3a2a5fb3ea5de35f6e773491ed7e13c9
|
||||
F ext/misc/vtshim.c 1976e6dd68dd0d64508c91a6dfab8e75f8aaf6cd
|
||||
F ext/misc/wholenumber.c 784b12543d60702ebdd47da936e278aa03076212
|
||||
F ext/misc/zipfile.c d9e0b0a4fdb4cb82ad22fd19d75563efdb1d6f812d62438bd30819781c282357
|
||||
F ext/misc/zipfile.c cf093f797331e51fa6c0358698bc89d08a88d06cdf11484ee4ea9d079145289b
|
||||
F ext/rbu/rbu.c ea7d1b7eb44c123a2a619332e19fe5313500705c4a58aaa1887905c0d83ffc2e
|
||||
F ext/rbu/rbu1.test 43836fac8c7179a358eaf38a8a1ef3d6e6285842
|
||||
F ext/rbu/rbu10.test 1846519a438697f45e9dcb246908af81b551c29e1078d0304fae83f1fed7e9ee
|
||||
@ -1596,7 +1596,7 @@ F test/wordcount.c cb589cec469a1d90add05b1f8cee75c7210338d87a5afd65260ed5c0f4bbf
|
||||
F test/writecrash.test f1da7f7adfe8d7f09ea79b42e5ca6dcc41102f27f8e334ad71539501ddd910cc
|
||||
F test/zeroblob.test 3857870fe681b8185654414a9bccfde80b62a0fa
|
||||
F test/zerodamage.test e59a56443d6298ecf7435f618f0b27654f0c849e
|
||||
F test/zipfile.test c5167d0d13ed7165b1982ac46b8aa94d65bdf41d94dd82f1d17ad2250650356c
|
||||
F test/zipfile.test 63059e59024cacd01ba4c32a445cf75aac21393ff4460bddd1dc1ef4b78dd8bc
|
||||
F tool/GetFile.cs a15e08acb5dd7539b75ba23501581d7c2b462cb5
|
||||
F tool/GetTclKit.bat 8995df40c4209808b31f24de0b58f90930239a234f7591e3675d45bfbb990c5d
|
||||
F tool/Replace.cs 02c67258801c2fb5f63231e0ac0f220b4b36ba91
|
||||
@ -1693,7 +1693,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P b64681a644c419bb98d00980a6cb56ef5a0aff5ef5321955631f0b4c88aac283
|
||||
R 407639481a191f472cd3497cc84b9ac5
|
||||
P 2dec2dec592c0726ebe87b841b9c8d493dea7074a99f278eb1bf0b744d658a9d
|
||||
R 64b99b9622049272ef5b18e73b616095
|
||||
U dan
|
||||
Z a9a0bf4010ca982b681b075b8e4b53ca
|
||||
Z 6ef5282c9c40bbaf3432c6295db23abc
|
||||
|
@ -1 +1 @@
|
||||
2dec2dec592c0726ebe87b841b9c8d493dea7074a99f278eb1bf0b744d658a9d
|
||||
f69e8194bfa7de436c96028730ebd57f186d2e6207792e172e1aa38c7f4211c9
|
@ -37,8 +37,8 @@ do_execsql_test 1.1 {
|
||||
do_execsql_test 1.2 {
|
||||
SELECT name, mtime, data FROM zipfile('test.zip');
|
||||
} {
|
||||
g.txt 1000000002 12345
|
||||
f.txt 1000000000 abcde
|
||||
g.txt 1000000002 12345
|
||||
}
|
||||
|
||||
do_execsql_test 1.3 {
|
||||
@ -51,9 +51,9 @@ do_execsql_test 1.4 {
|
||||
SELECT name, mtime, zipfile_uncompress(data, sz, method), method
|
||||
FROM zipfile('test.zip');
|
||||
} {
|
||||
h.txt 1000000004 aaaaaaaaaabbbbbbbbbb 8
|
||||
f.txt 1000000000 abcde 0
|
||||
g.txt 1000000002 12345 0
|
||||
h.txt 1000000004 aaaaaaaaaabbbbbbbbbb 8
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
Loading…
x
Reference in New Issue
Block a user