| ︙ | | | ︙ | |
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
|
** 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.
**
** Dangerous characters in zBasis are changed.
*/
void file_tempname(Blob *pBuf, const char *zBasis, const char *zTag){
#if defined(_WIN32)
const char *azDirs[] = {
0, /* GetTempPath */
0, /* TEMP */
0, /* TMP */
|
>
>
|
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
|
** 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.
**
** Dangerous characters in zBasis are changed.
**
** See also fossil_temp_filename() and file_time_tempname();
*/
void file_tempname(Blob *pBuf, const char *zBasis, const char *zTag){
#if defined(_WIN32)
const char *azDirs[] = {
0, /* GetTempPath */
0, /* TEMP */
0, /* TMP */
|
| ︙ | | | ︙ | |
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
|
nBasis = 6;
zBasis = "fossil";
}
do{
blob_zero(pBuf);
if( cnt++>20 ) fossil_fatal("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;
for(z=blob_str(pBuf); z!=0 && (z=strpbrk(z,"'\"`;|$&"))!=0; z++){
z[0] = '_';
}
|
>
|
|
|
|
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
|
nBasis = 6;
zBasis = "fossil";
}
do{
blob_zero(pBuf);
if( cnt++>20 ) fossil_fatal("cannot generate a temporary filename");
if( zTag==0 ){
const int nRand = sizeof(zRand)-1;
sqlite3_randomness(nRand, zRand);
for(i=0; i<nRand; i++){
zRand[i] = (char)zChars[ ((unsigned char)zRand[i])%(sizeof(zChars)-1) ];
}
zRand[nRand] = 0;
zTag = zRand;
}
blob_appendf(pBuf, "%s/%.*s~%s%s", zDir, nBasis, zBasis, zTag, zSuffix);
zTag = 0;
for(z=blob_str(pBuf); z!=0 && (z=strpbrk(z,"'\"`;|$&"))!=0; z++){
z[0] = '_';
}
|
| ︙ | | | ︙ | |
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
|
fossil_path_free((char *)azDirs[0]);
#endif
}
/*
** Compute a temporary filename in zDir. The filename is based on
** the current time.
*/
char *file_time_tempname(const char *zDir, const char *zSuffix){
struct tm *tm;
unsigned int r;
static unsigned int cnt = 0;
time_t t;
t = time(0);
|
>
>
|
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
|
fossil_path_free((char *)azDirs[0]);
#endif
}
/*
** Compute a temporary filename in zDir. The filename is based on
** the current time.
**
** See also fossil_temp_filename() and file_tempname();
*/
char *file_time_tempname(const char *zDir, const char *zSuffix){
struct tm *tm;
unsigned int r;
static unsigned int cnt = 0;
time_t t;
t = time(0);
|
| ︙ | | | ︙ | |
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
|
/*
** 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);
|
>
>
>
>
>
>
>
>
>
|
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
|
/*
** 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.
**
** If --time is used, file_time_tempname() generates the filename.
** If BASENAME is present, file_tempname() generates the filename.
** Without --time or BASENAME, fossil_temp_filename() generates the filename.
*/
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();
if( g.argc<=2 ){
z = fossil_temp_filename();
fossil_print("%s\n", z);
sqlite3_free(z);
}
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);
|
| ︙ | | | ︙ | |