2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
|
**
** zFilename must, for efficiency's sake, be a
** canonicalized/normalized name, e.g. using only '/' as directory
** separators.
**
** nFilename must be the strlen of zFilename. If it is negative,
** strlen() is used to calculate it.
**
** TODO: https://fossil-scm.org/sec2020/info/972cf9c302f5413f
** TL;DR: check for the -wal, -shm, -journal suffix forms of the db
** names.
*/
int filename_is_ckout_db(const char *zFilename, int nFilename){
const char *zEnd;
if(nFilename>=0 && nFilename<8/*strlen _FOSSIL_*/) return 0;
else if(nFilename<0) nFilename = (int)strlen(zFilename);
if(nFilename<8) return 0;
zEnd = zFilename + nFilename;
switch(zEnd[-1]){
case '_': {
return fossil_strcmp("_FOSSIL_", &zEnd[-8])
? 0 : (8==nFilename ? 1 : ('/'==zEnd[-9] ? 2 : 0));
}
case 't': {
return (nFilename<9
|| '.'!=zEnd[-9]
|| fossil_strcmp(".fslckout", &zEnd[-9]))
? 0 : (9==nFilename ? 1 : ('/'==zEnd[-10] ? 2 : 0));
}
default:
return 0;
}
}
/*
** COMMAND: test-is-ckout-db
**
** Usage: %fossil test-is-ckout-db FILENAMES...
|
<
<
<
<
|
>
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>
>
|
|
>
>
|
>
|
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
|
**
** zFilename must, for efficiency's sake, be a
** canonicalized/normalized name, e.g. using only '/' as directory
** separators.
**
** nFilename must be the strlen of zFilename. If it is negative,
** strlen() is used to calculate it.
*/
int filename_is_ckout_db(const char *zFilename, int nFilename){
const char *zEnd; /* one-after-the-end of zFilename */
int gotSuffix = 0; /* length of suffix (-wal, -shm, -journal) */
assert(zFilename && "API misuse");
if(nFilename<0) nFilename = (int)strlen(zFilename);
if(nFilename<8/*strlen _FOSSIL_*/) return 0;
zEnd = zFilename + nFilename;
if(nFilename>=12/*strlen _FOSSIL_-(shm|wal)*/){
/* Check for (-wal, -shm, -journal) suffixes, with an eye towards
** runtime speed. */
if('-'==zEnd[-4]){
if(fossil_stricmp("wal", &zEnd[-3])
&& fossil_stricmp("shm", &zEnd[-3])){
return 0;
}
gotSuffix = 4;
}else if(nFilename>=16/*strlen _FOSSIL_-journal*/ && '-'==zEnd[-8]){
if(fossil_stricmp("journal",&zEnd[-7])){
return 0;
}
gotSuffix = 8;
}
if(gotSuffix){
assert(4==gotSuffix || 8==gotSuffix);
zEnd -= gotSuffix;
nFilename -= gotSuffix;
gotSuffix = 1;
}
assert(nFilename>=8 && "strlen _FOSSIL_");
assert(gotSuffix==0 || gotSuffix==1);
}
switch(zEnd[-1]){
case '_': {
return fossil_strnicmp("_FOSSIL_", &zEnd[-8], 8)
? 0 : (8==nFilename
? 1
: ('/'==zEnd[-9] ? 2 : gotSuffix));
}
case 't': {
return (nFilename<9
|| '.'!=zEnd[-9]
|| fossil_strnicmp(".fslckout", &zEnd[-9], 9))
? 0 : (9==nFilename
? 1
: ('/'==zEnd[-10] ? 2 : gotSuffix));
}
default: {
return 0;
}
}
}
/*
** COMMAND: test-is-ckout-db
**
** Usage: %fossil test-is-ckout-db FILENAMES...
|