| ︙ | | |
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
-
+
|
return 512;
}
static int archiveDeviceCharacteristics(sqlite3_file *pFile){
return 0;
}
static int archiveOpen(
sqlite3_vfs *pVfs, const char *zName,
sqlite3_vfs *pVfs, const char *zName,
sqlite3_file *pFile, int flags, int *pOutFlags
){
static struct sqlite3_io_methods methods = {
1, /* iVersion */
archiveClose,
archiveRead,
archiveWrite,
|
| ︙ | | |
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
-
-
+
+
|
** Append a single file to a growing ZIP archive.
**
** pFile is the file to be appended. zName is the name
** that the file should be saved as.
*/
static void zip_add_file_to_zip(
Archive *p,
const char *zName,
const Blob *pFile,
const char *zName,
const Blob *pFile,
int mPerm
){
z_stream stream;
int nameLen;
int toOut = 0;
int iStart;
unsigned long iCRC = 0;
|
| ︙ | | |
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
|
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
|
-
-
+
+
-
+
-
+
-
-
+
+
|
put16(&zExTime[2], 5);
blob_append(&toc, zExTime, 9);
nEntry++;
}
static void zip_add_file_to_sqlar(
Archive *p,
const char *zName,
const Blob *pFile,
const char *zName,
const Blob *pFile,
int mPerm
){
int nName = (int)strlen(zName);
if( p->db==0 ){
assert( p->vfs.zName==0 );
p->vfs.zName = (const char*)mprintf("archivevfs%p", (void*)p);
p->vfs.iVersion = 1;
p->vfs.szOsFile = sizeof(ArchiveFile);
p->vfs.mxPathname = 512;
p->vfs.pAppData = (void*)p->pBlob;
p->vfs.xOpen = archiveOpen;
p->vfs.xDelete = archiveDelete;
p->vfs.xAccess = archiveAccess;
p->vfs.xFullPathname = archiveFullPathname;
p->vfs.xRandomness = archiveRandomness;
p->vfs.xSleep = archiveSleep;
p->vfs.xCurrentTime = archiveCurrentTime;
p->vfs.xGetLastError = archiveGetLastError;
sqlite3_vfs_register(&p->vfs, 0);
sqlite3_open_v2("file:xyz.db", &p->db,
sqlite3_open_v2("file:xyz.db", &p->db,
SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE, p->vfs.zName
);
assert( p->db );
blob_zero(&p->tmp);
sqlite3_exec(p->db,
sqlite3_exec(p->db,
"PRAGMA page_size=512;"
"PRAGMA journal_mode = off;"
"PRAGMA cache_spill = off;"
"BEGIN;"
"CREATE TABLE sqlar("
"name TEXT PRIMARY KEY, -- name of the file\n"
"mode INT, -- access permissions\n"
"mtime INT, -- last modification time\n"
"sz INT, -- original file size\n"
"data BLOB -- compressed content\n"
");", 0, 0, 0
);
sqlite3_prepare(p->db,
"INSERT INTO sqlar VALUES(?, ?, ?, ?, ?)", -1,
sqlite3_prepare(p->db,
"INSERT INTO sqlar VALUES(?, ?, ?, ?, ?)", -1,
&p->pInsert, 0
);
assert( p->pInsert );
sqlite3_bind_int64(p->pInsert, 3, unixTime);
blob_zero(p->pBlob);
}
|
| ︙ | | |
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
|
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
|
-
+
-
+
-
+
-
-
+
+
|
sqlite3_bind_int(p->pInsert, 4, 0);
sqlite3_bind_null(p->pInsert, 5);
}else{
sqlite3_bind_text(p->pInsert, 1, zName, nName, SQLITE_STATIC);
if( mPerm==PERM_LNK ){
sqlite3_bind_int(p->pInsert, 2, 0120755);
sqlite3_bind_int(p->pInsert, 4, -1);
sqlite3_bind_text(p->pInsert, 5,
sqlite3_bind_text(p->pInsert, 5,
blob_buffer(pFile), blob_size(pFile), SQLITE_STATIC
);
}else{
unsigned int nIn = blob_size(pFile);
unsigned long int nOut = nIn;
sqlite3_bind_int(p->pInsert, 2, mPerm==PERM_EXE ? 0100755 : 0100644);
sqlite3_bind_int(p->pInsert, 4, nIn);
zip_blob_minsize(&p->tmp, nIn);
compress( (unsigned char*)
blob_buffer(&p->tmp), &nOut, (unsigned char*)blob_buffer(pFile), nIn
);
if( nOut>=(unsigned long)nIn ){
sqlite3_bind_blob(p->pInsert, 5,
sqlite3_bind_blob(p->pInsert, 5,
blob_buffer(pFile), blob_size(pFile), SQLITE_STATIC
);
}else{
sqlite3_bind_blob(p->pInsert, 5,
sqlite3_bind_blob(p->pInsert, 5,
blob_buffer(&p->tmp), nOut, SQLITE_STATIC
);
}
}
}
sqlite3_step(p->pInsert);
sqlite3_reset(p->pInsert);
}
static void zip_add_file(
Archive *p,
const char *zName,
const Blob *pFile,
const char *zName,
const Blob *pFile,
int mPerm
){
if( p->eType==ARCHIVE_ZIP ){
zip_add_file_to_zip(p, zName, pFile, mPerm);
}else{
zip_add_file_to_sqlar(p, zName, pFile, mPerm);
}
|
| ︙ | | |
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
|
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
|
-
+
|
" || substr(blob.uuid, 1, 10)"
" FROM event, blob"
" WHERE event.objid=%d"
" AND blob.rid=%d",
db_get("project-name", "unnamed"), rid, rid
);
}
zip_of_checkin(eType, rid, zOut ? &zip : 0,
zip_of_checkin(eType, rid, zOut ? &zip : 0,
zName, pInclude, pExclude, listFlag);
glob_free(pInclude);
glob_free(pExclude);
if( zOut ){
blob_write_to_file(&zip, zOut);
blob_reset(&zip);
}
|
| ︙ | | |
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
|
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
|
-
+
-
+
|
zInclude = P("in");
if( zInclude ) pInclude = glob_create(zInclude);
zExclude = P("ex");
if( zExclude ) pExclude = glob_create(zExclude);
if( zInclude==0 && zExclude==0 ){
etag_check_for_invariant_name(z);
}
if( eType==ARCHIVE_ZIP
if( eType==ARCHIVE_ZIP
&& nName>4
&& fossil_strcmp(&zName[nName-4], ".zip")==0
){
/* Special case: Remove the ".zip" suffix. */
nName -= 4;
zName[nName] = 0;
}else if( eType==ARCHIVE_SQLAR
}else if( eType==ARCHIVE_SQLAR
&& nName>6
&& fossil_strcmp(&zName[nName-6], ".sqlar")==0
){
/* Special case: Remove the ".sqlar" suffix. */
nName -= 6;
zName[nName] = 0;
}else{
|
| ︙ | | |