1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
|
}
/*
** Construct a random temporary filename into pBuf where the name of
** the temporary file is derived from zBasis. The suffix on the temp
** file is the same as the suffix on zBasis, and the temp file has
** the root of zBasis in its name.
*/
void file_tempname(Blob *pBuf, const char *zBasis){
#if defined(_WIN32)
const char *azDirs[] = {
0, /* GetTempPath */
0, /* TEMP */
0, /* TMP */
".",
};
|
>
>
>
>
|
|
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
|
}
/*
** Construct a random temporary filename into pBuf where the name of
** the temporary file is derived from zBasis. The suffix on the temp
** file is the same as the suffix on zBasis, and the temp file has
** the root of zBasis in its name.
**
** If zTag is not NULL, then try to create the temp-file using zTag
** as a differentiator. If that fails, or if zTag is NULL, then use
** a bunch of random characters as the tag.
*/
void file_tempname(Blob *pBuf, const char *zBasis, const char *zTag){
#if defined(_WIN32)
const char *azDirs[] = {
0, /* GetTempPath */
0, /* TEMP */
0, /* TMP */
".",
};
|
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
|
if( nBasis==0 ){
nBasis = 6;
zBasis = "fossil";
}
do{
blob_zero(pBuf);
if( cnt++>20 ) fossil_panic("cannot generate a temporary filename");
sqlite3_randomness(15, zRand);
for(i=0; i<15; i++){
zRand[i] = (char)zChars[ ((unsigned char)zRand[i])%(sizeof(zChars)-1) ];
}
zRand[15] = 0;
blob_appendf(pBuf, "%s/%.*s~%s%s", zDir, nBasis, zBasis, zRand, zSuffix);
}while( file_size(blob_str(pBuf), ExtFILE)>=0 );
#if defined(_WIN32)
fossil_path_free((char *)azDirs[0]);
fossil_path_free((char *)azDirs[1]);
fossil_path_free((char *)azDirs[2]);
/* Change all \ characters in the windows path into / so that they can
|
>
|
|
|
|
|
>
>
|
>
|
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
|
if( nBasis==0 ){
nBasis = 6;
zBasis = "fossil";
}
do{
blob_zero(pBuf);
if( cnt++>20 ) fossil_panic("cannot generate a temporary filename");
if( zTag==0 ){
sqlite3_randomness(15, zRand);
for(i=0; i<15; i++){
zRand[i] = (char)zChars[ ((unsigned char)zRand[i])%(sizeof(zChars)-1) ];
}
zRand[15] = 0;
zTag = zRand;
}
blob_appendf(pBuf, "%s/%.*s~%s%s", zDir, nBasis, zBasis, zTag, zSuffix);
zTag = 0;
}while( file_size(blob_str(pBuf), ExtFILE)>=0 );
#if defined(_WIN32)
fossil_path_free((char *)azDirs[0]);
fossil_path_free((char *)azDirs[1]);
fossil_path_free((char *)azDirs[2]);
/* Change all \ characters in the windows path into / so that they can
|
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
|
zDir, tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec, cnt++, r%1000000, zSuffix);
}
/*
** COMMAND: test-tempname
** Usage: fossil test-name [--time SUFFIX] BASENAME ...
**
** Generate temporary filenames derived from BASENAME. Use the --time
** option to generate temp names based on the time of day.
*/
void file_test_tempname(void){
int i;
const char *zSuffix = find_option("time",0,1);
Blob x = BLOB_INITIALIZER;
char *z;
verify_all_options();
for(i=2; i<g.argc; i++){
if( zSuffix ){
z = file_time_tempname(g.argv[i], zSuffix);
fossil_print("%s\n", z);
fossil_free(z);
}else{
file_tempname(&x, g.argv[i]);
fossil_print("%s\n", blob_str(&x));
blob_reset(&x);
}
}
}
|
|
|
>
>
|
|
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
|
zDir, tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec, cnt++, r%1000000, zSuffix);
}
/*
** COMMAND: test-tempname
** Usage: fossil test-name [--time SUFFIX] [--tag NAME] BASENAME ...
**
** Generate temporary filenames derived from BASENAME. Use the --time
** option to generate temp names based on the time of day. If --tag NAME
** is specified, try to use NAME as the differentiator in the temp file.
*/
void file_test_tempname(void){
int i;
const char *zSuffix = find_option("time",0,1);
Blob x = BLOB_INITIALIZER;
char *z;
const char *zTag = find_option("tag",0,1);
verify_all_options();
for(i=2; i<g.argc; i++){
if( zSuffix ){
z = file_time_tempname(g.argv[i], zSuffix);
fossil_print("%s\n", z);
fossil_free(z);
}else{
file_tempname(&x, g.argv[i], zTag);
fossil_print("%s\n", blob_str(&x));
blob_reset(&x);
}
}
}
|