| ︙ | | |
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
-
+
-
-
+
|
** Fill stat buf with information received from stat() or lstat().
** lstat() is called on Unix if isWd is TRUE and allow-symlinks setting is on.
**
*/
static int fossil_stat(
const char *zFilename, /* name of file or directory to inspect. */
struct fossilStat *buf, /* pointer to buffer where info should go. */
int isWd, /* non-zero to consider look at symlink itself. */
int isWd /* non-zero to consider look at symlink itself. */
int forceWd /* non-zero to force look at symlink itself. */
){
int rc;
void *zMbcs = fossil_utf8_to_path(zFilename, 0);
#if !defined(_WIN32)
if( isWd && (forceWd || db_allow_symlinks(0)) ){
if( isWd && db_allow_symlinks() ){
rc = lstat(zMbcs, buf);
}else{
rc = stat(zMbcs, buf);
}
#else
rc = win32_stat(zMbcs, buf, isWd);
#endif
|
| ︙ | | |
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
-
+
|
** Return the number of errors. No error messages are generated.
*/
static int getStat(const char *zFilename, int isWd){
int rc = 0;
if( zFilename==0 ){
if( fileStatValid==0 ) rc = 1;
}else{
if( fossil_stat(zFilename, &fileStat, isWd, 0)!=0 ){
if( fossil_stat(zFilename, &fileStat, isWd)!=0 ){
fileStatValid = 0;
rc = 1;
}else{
fileStatValid = 1;
rc = 0;
}
}
|
| ︙ | | |
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
-
+
|
** Create symlink to file on Unix, or plain-text file with
** symlink target if "allow-symlinks" is off or we're on Windows.
**
** Arguments: target file (symlink will point to it), link file
**/
void symlink_create(const char *zTargetFile, const char *zLinkFile){
#if !defined(_WIN32)
if( db_allow_symlinks(0) ){
if( db_allow_symlinks() ){
int i, nName;
char *zName, zBuf[1000];
nName = strlen(zLinkFile);
if( nName>=sizeof(zBuf) ){
zName = mprintf("%s", zLinkFile);
}else{
|
| ︙ | | |
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
-
+
|
** - PERM_REG for all other cases (regular file, directory, fifo, etc).
*/
int file_wd_perm(const char *zFilename){
#if !defined(_WIN32)
if( !getStat(zFilename, 1) ){
if( S_ISREG(fileStat.st_mode) && ((S_IXUSR)&fileStat.st_mode)!=0 )
return PERM_EXE;
else if( db_allow_symlinks(0) && S_ISLNK(fileStat.st_mode) )
else if( db_allow_symlinks() && S_ISLNK(fileStat.st_mode) )
return PERM_LNK;
}
#endif
return PERM_REG;
}
/*
|
| ︙ | | |
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
|
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
|
-
-
-
+
-
+
-
+
|
** zFilename is a directory -OR- a symlink that points to a directory.
** Return 0 if zFilename does not exist. Return 2 if zFilename exists
** but is something other than a directory.
*/
int file_wd_isdir(const char *zFilename){
int rc;
char *zFN;
struct fossilStat dirFileStat;
zFN = mprintf("%s", zFilename);
file_simplify_name(zFN, -1, 0);
memset(&dirFileStat, 0, sizeof(struct fossilStat));
rc = fossil_stat(zFN, &dirFileStat, 1, 1);
rc = getStat(zFN, 1);
if( rc ){
rc = 0; /* It does not exist at all. */
}else if( S_ISDIR(dirFileStat.st_mode) ){
}else if( S_ISDIR(fileStat.st_mode) ){
rc = 1; /* It exists and is a real directory. */
}else if( !db_allow_symlinks(1) && S_ISLNK(dirFileStat.st_mode) ){
}else if( S_ISLNK(fileStat.st_mode) ){
Blob content;
blob_read_link(&content, zFN); /* It exists and is a link. */
rc = file_wd_isdir(blob_str(&content)); /* Points to directory? */
blob_reset(&content);
}else{
rc = 2; /* It exists and is something else. */
}
|
| ︙ | | |
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
|
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
|
-
+
|
** Set or clear the execute bit on a file. Return true if a change
** occurred and false if this routine is a no-op.
*/
int file_wd_setexe(const char *zFilename, int onoff){
int rc = 0;
#if !defined(_WIN32)
struct stat buf;
if( fossil_stat(zFilename, &buf, 1, 0)!=0 || S_ISLNK(buf.st_mode) ) return 0;
if( fossil_stat(zFilename, &buf, 1)!=0 || S_ISLNK(buf.st_mode) ) return 0;
if( onoff ){
int targetMode = (buf.st_mode & 0444)>>2;
if( (buf.st_mode & 0100)==0 ){
chmod(zFilename, buf.st_mode | targetMode);
rc = 1;
}
}else{
|
| ︙ | | |
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
|
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
|
-
+
-
+
|
file_canonical_name(zPath, &x, slash);
fossil_print("%s[%s] -> [%s]\n", raw ? "RAW " : "", zPath, blob_buffer(&x));
blob_reset(&x);
if( raw ){
int rc;
struct fossilStat testFileStat;
memset(&testFileStat, 0, sizeof(struct fossilStat));
rc = fossil_stat(zPath, &testFileStat, 0, 0);
rc = fossil_stat(zPath, &testFileStat, 0);
fossil_print(" stat_rc = %d\n", rc);
sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_size);
fossil_print(" stat_size = %s\n", zBuf);
sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_mtime);
fossil_print(" stat_mtime = %s\n", zBuf);
fossil_print(" stat_mode = %d\n", testFileStat.st_mode);
memset(&testFileStat, 0, sizeof(struct fossilStat));
rc = fossil_stat(zPath, &testFileStat, 1, 1);
rc = fossil_stat(zPath, &testFileStat, 1);
fossil_print(" l_stat_rc = %d\n", rc);
sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_size);
fossil_print(" l_stat_size = %s\n", zBuf);
sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_mtime);
fossil_print(" l_stat_mtime = %s\n", zBuf);
fossil_print(" l_stat_mode = %d\n", testFileStat.st_mode);
}else{
|
| ︙ | | |
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
|
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
|
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
+
-
-
+
-
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
|
** display file system information about the files specified, if any.
**
** Options:
**
** --open-config Open the configuration database first.
** --slash Trailing slashes, if any, are retained.
** --reset Reset cached stat() info for each file.
** --symlinks BOOLEAN Force allow-symlinks on or off
*/
void cmd_test_file_environment(void){
int i;
int slashFlag = find_option("slash",0,0)!=0;
int resetFlag = find_option("reset",0,0)!=0;
const char *forceSymlinks = find_option("symlinks",0,1);
if( find_option("open-config", 0, 0)!=0 ){
Th_OpenConfig(1);
}
if( forceSymlinks ){
if( is_truth(forceSymlinks) ) g.allowSymlinks = 1;
if( is_false(forceSymlinks) ) g.allowSymlinks = 0;
}
fossil_print("Th_IsLocalOpen() = %d\n", Th_IsLocalOpen());
fossil_print("Th_IsRepositoryOpen() = %d\n", Th_IsRepositoryOpen());
fossil_print("Th_IsConfigOpen() = %d\n", Th_IsConfigOpen());
fossil_print("filenames_are_case_sensitive() = %d\n",
filenames_are_case_sensitive());
fossil_print("db_allow_symlinks_by_default() = %d\n",
db_allow_symlinks_by_default());
fossil_print("db_allow_symlinks(0) = %d\n", db_allow_symlinks(0));
fossil_print("db_allow_symlinks() = %d\n", db_allow_symlinks());
fossil_print("db_allow_symlinks(1) = %d\n", db_allow_symlinks(1));
for(i=2; i<g.argc; i++){
emitFileStat(g.argv[i], 1, slashFlag, resetFlag);
emitFileStat(g.argv[i], 0, slashFlag, resetFlag);
}
}
/*
** COMMAND: test-canonical-name
**
** Usage: %fossil test-canonical-name FILENAME...
**
** Test the operation of the canonical name generator.
** Also test Fossil's ability to measure attributes of a file.
**
** Options:
**
** --open-config Open the configuration database first.
** --slash Trailing slashes, if any, are retained.
** --reset Reset cached stat() info for each file.
*/
void cmd_test_canonical_name(void){
int i;
Blob x;
int slashFlag = find_option("slash",0,0)!=0;
int resetFlag = find_option("reset",0,0)!=0;
if( find_option("open-config", 0, 0)!=0 ){
blob_zero(&x);
Th_OpenConfig(1);
}
for(i=2; i<g.argc; i++){
char zBuf[100];
emitFileStat(g.argv[i], 0, slashFlag, resetFlag);
const char *zName = g.argv[i];
file_canonical_name(zName, &x, slashFlag);
fossil_print("[%s] -> [%s]\n", zName, blob_buffer(&x));
blob_reset(&x);
sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_wd_size(zName));
fossil_print(" file_size = %s\n", zBuf);
sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_wd_mtime(zName));
fossil_print(" file_mtime = %s\n", zBuf);
fossil_print(" file_isfile = %d\n", file_wd_isfile(zName));
fossil_print(" file_isfile_or_link = %d\n",file_wd_isfile_or_link(zName));
fossil_print(" file_islink = %d\n", file_wd_islink(zName));
fossil_print(" file_isexe = %d\n", file_wd_isexe(zName));
fossil_print(" file_isdir = %d\n", file_wd_isdir(zName));
}
}
/*
** Return TRUE if the given filename is canonical.
**
** Canonical names are full pathnames using "/" not "\" and which
|
| ︙ | | |
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
|
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
|
-
-
-
-
|
}
}
/*
** COMMAND: test-relative-name
**
** Test the operation of the relative name generator.
**
** Options:
**
** --slash Trailing slashes, if any, are retained.
*/
void cmd_test_relative_name(void){
int i;
Blob x;
int slashFlag = find_option("slash",0,0)!=0;
blob_zero(&x);
for(i=2; i<g.argc; i++){
|
| ︙ | | |
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
|
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
|
-
|
**
** Test the operation of the tree name generator.
**
** Options:
** --absolute Return an absolute path instead of a relative one.
** --case-sensitive B Enable or disable case-sensitive filenames. B is
** a boolean: "yes", "no", "true", "false", etc.
** --no-dir-symlinks Disables support for directory symlinks.
*/
void cmd_test_tree_name(void){
int i;
Blob x;
int absoluteFlag = find_option("absolute",0,0)!=0;
db_find_and_open_repository(0,0);
blob_zero(&x);
|
| ︙ | | |