20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#include "config.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "file.h"
/*
** On Windows, include the Platform SDK header file.
*/
#ifdef _WIN32
# include <direct.h>
|
>
|
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#include "config.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include "file.h"
/*
** On Windows, include the Platform SDK header file.
*/
#ifdef _WIN32
# include <direct.h>
|
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
|
z = blob_buffer(pBuf);
for(i=0; z[i]; i++) if( z[i]=='\\' ) z[i] = '/';
#else
fossil_path_free((char *)azDirs[0]);
#endif
}
/*
** COMMAND: test-tempname
** Usage: fossil test-name BASENAME ...
**
** Generate temporary filenames derived from BASENAME
*/
void file_test_tempname(void){
int i;
Blob x = BLOB_INITIALIZER;
for(i=2; i<g.argc; i++){
file_tempname(&x, g.argv[i]);
fossil_print("%s\n", blob_str(&x));
blob_reset(&x);
}
}
/*
** Return true if a file named zName exists and has identical content
** to the blob pContent. If zName does not exist or if the content is
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>
>
>
>
>
>
>
>
>
|
|
|
>
|
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
|
z = blob_buffer(pBuf);
for(i=0; z[i]; i++) if( z[i]=='\\' ) z[i] = '/';
#else
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);
tm = gmtime(&t);
sqlite3_randomness(sizeof(r), &r);
return mprintf("%s/%04d%02d%02d%02d%02d%02d%04d%06d%s",
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;
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);
}
}
}
/*
** Return true if a file named zName exists and has identical content
** to the blob pContent. If zName does not exist or if the content is
|