1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
|
blob_set(pPath, &zUri[i]);
}else{
blob_set(pPath, "/");
}
}
/*
** Construct a random temporary filename into pBuf starting with zPrefix.
*/
void file_tempname(Blob *pBuf, const char *zPrefix){
#if defined(_WIN32)
const char *azDirs[] = {
0, /* GetTempPath */
0, /* TEMP */
0, /* TMP */
".",
};
|
|
>
>
>
|
|
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
|
blob_set(pPath, &zUri[i]);
}else{
blob_set(pPath, "/");
}
}
/*
** 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 */
".",
};
|
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
|
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789";
unsigned int i;
const char *zDir = ".";
int cnt = 0;
char zRand[16];
#if defined(_WIN32)
wchar_t zTmpPath[MAX_PATH];
if( GetTempPathW(MAX_PATH, zTmpPath) ){
azDirs[0] = fossil_path_to_utf8(zTmpPath);
/* Removing trailing \ from the temp path */
|
>
>
|
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
|
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789";
unsigned int i;
const char *zDir = ".";
int cnt = 0;
char zRand[16];
int nBasis;
const char *zSuffix;
#if defined(_WIN32)
wchar_t zTmpPath[MAX_PATH];
if( GetTempPathW(MAX_PATH, zTmpPath) ){
azDirs[0] = fossil_path_to_utf8(zTmpPath);
/* Removing trailing \ from the temp path */
|
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
|
for(i=0; i<count(azDirs); i++){
if( azDirs[i]==0 ) continue;
if( !file_isdir(azDirs[i], ExtFILE) ) continue;
zDir = azDirs[i];
break;
}
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.txt", zDir, zPrefix ? zPrefix : "", zRand);
}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
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
|
for(i=0; i<count(azDirs); i++){
if( azDirs[i]==0 ) continue;
if( !file_isdir(azDirs[i], ExtFILE) ) continue;
zDir = azDirs[i];
break;
}
assert( zBasis!=0 );
zSuffix = 0;
for(i=0; zBasis[i]; i++){
if( zBasis[i]=='/' || zBasis[i]=='\\' ){
zBasis += i+1;
i = -1;
}else if( zBasis[i]=='.' ){
zSuffix = zBasis + i;
}
}
if( zSuffix==0 || zSuffix<=zBasis ){
zSuffix = "";
nBasis = i;
}else{
nBasis = (int)(zSuffix - zBasis);
}
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
|