Fossil SCM

Add a wrapper around all calls to access() that translates UTF8 to MBCS.

drh 2011-05-04 11:13 windows-i18n
Commit 850d3df44e03f4c5f1257a6a6bc4d5532b5b6174
+1 -1
--- src/add.c
+++ src/add.c
@@ -215,11 +215,11 @@
215215
isDir = file_isdir(zName);
216216
if( isDir==1 ){
217217
vfile_scan(&fullName, nRoot-1, includeDotFiles, pIgnore);
218218
}else if( isDir==0 ){
219219
fossil_fatal("not found: %s", zName);
220
- }else if( access(zName, R_OK) ){
220
+ }else if( file_access(zName, R_OK) ){
221221
fossil_fatal("cannot open %s", zName);
222222
}else{
223223
char *zTreeName = &zName[nRoot];
224224
db_multi_exec(
225225
"INSERT OR IGNORE INTO sfile(x)"
226226
--- src/add.c
+++ src/add.c
@@ -215,11 +215,11 @@
215 isDir = file_isdir(zName);
216 if( isDir==1 ){
217 vfile_scan(&fullName, nRoot-1, includeDotFiles, pIgnore);
218 }else if( isDir==0 ){
219 fossil_fatal("not found: %s", zName);
220 }else if( access(zName, R_OK) ){
221 fossil_fatal("cannot open %s", zName);
222 }else{
223 char *zTreeName = &zName[nRoot];
224 db_multi_exec(
225 "INSERT OR IGNORE INTO sfile(x)"
226
--- src/add.c
+++ src/add.c
@@ -215,11 +215,11 @@
215 isDir = file_isdir(zName);
216 if( isDir==1 ){
217 vfile_scan(&fullName, nRoot-1, includeDotFiles, pIgnore);
218 }else if( isDir==0 ){
219 fossil_fatal("not found: %s", zName);
220 }else if( file_access(zName, R_OK) ){
221 fossil_fatal("cannot open %s", zName);
222 }else{
223 char *zTreeName = &zName[nRoot];
224 db_multi_exec(
225 "INSERT OR IGNORE INTO sfile(x)"
226
+2 -2
--- src/allrepo.c
+++ src/allrepo.c
@@ -129,11 +129,11 @@
129129
" FROM global_config"
130130
" WHERE substr(name, 1, 5)=='repo:' ORDER BY 1"
131131
);
132132
while( db_step(&q)==SQLITE_ROW ){
133133
const char *zFilename = db_column_text(&q, 0);
134
- if( access(zFilename, 0) ){
134
+ if( file_access(zFilename, 0) ){
135135
nMissing++;
136136
continue;
137137
}
138138
if( !file_is_canonical(zFilename) ) nMissing++;
139139
if( zCmd[0]=='l' ){
@@ -159,11 +159,11 @@
159159
if( nMissing ){
160160
db_begin_transaction();
161161
db_reset(&q);
162162
while( db_step(&q)==SQLITE_ROW ){
163163
const char *zFilename = db_column_text(&q, 0);
164
- if( access(zFilename, 0) ){
164
+ if( file_access(zFilename, 0) ){
165165
char *zRepo = mprintf("repo:%s", zFilename);
166166
db_unset(zRepo, 1);
167167
free(zRepo);
168168
}else if( !file_is_canonical(zFilename) ){
169169
Blob cname;
170170
--- src/allrepo.c
+++ src/allrepo.c
@@ -129,11 +129,11 @@
129 " FROM global_config"
130 " WHERE substr(name, 1, 5)=='repo:' ORDER BY 1"
131 );
132 while( db_step(&q)==SQLITE_ROW ){
133 const char *zFilename = db_column_text(&q, 0);
134 if( access(zFilename, 0) ){
135 nMissing++;
136 continue;
137 }
138 if( !file_is_canonical(zFilename) ) nMissing++;
139 if( zCmd[0]=='l' ){
@@ -159,11 +159,11 @@
159 if( nMissing ){
160 db_begin_transaction();
161 db_reset(&q);
162 while( db_step(&q)==SQLITE_ROW ){
163 const char *zFilename = db_column_text(&q, 0);
164 if( access(zFilename, 0) ){
165 char *zRepo = mprintf("repo:%s", zFilename);
166 db_unset(zRepo, 1);
167 free(zRepo);
168 }else if( !file_is_canonical(zFilename) ){
169 Blob cname;
170
--- src/allrepo.c
+++ src/allrepo.c
@@ -129,11 +129,11 @@
129 " FROM global_config"
130 " WHERE substr(name, 1, 5)=='repo:' ORDER BY 1"
131 );
132 while( db_step(&q)==SQLITE_ROW ){
133 const char *zFilename = db_column_text(&q, 0);
134 if( file_access(zFilename, 0) ){
135 nMissing++;
136 continue;
137 }
138 if( !file_is_canonical(zFilename) ) nMissing++;
139 if( zCmd[0]=='l' ){
@@ -159,11 +159,11 @@
159 if( nMissing ){
160 db_begin_transaction();
161 db_reset(&q);
162 while( db_step(&q)==SQLITE_ROW ){
163 const char *zFilename = db_column_text(&q, 0);
164 if( file_access(zFilename, 0) ){
165 char *zRepo = mprintf("repo:%s", zFilename);
166 db_unset(zRepo, 1);
167 free(zRepo);
168 }else if( !file_is_canonical(zFilename) ){
169 Blob cname;
170
+2 -2
--- src/checkin.c
+++ src/checkin.c
@@ -54,11 +54,11 @@
5454
char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
5555
blob_append(report, zPrefix, nPrefix);
5656
if( isDeleted ){
5757
blob_appendf(report, "DELETED %s\n", zPathname);
5858
}else if( !file_isfile(zFullName) ){
59
- if( access(zFullName, 0)==0 ){
59
+ if( file_access(zFullName, 0)==0 ){
6060
blob_appendf(report, "NOT_A_FILE %s\n", zPathname);
6161
if( missingIsFatal ){
6262
fossil_warning("not a file: %s", zPathname);
6363
nErr++;
6464
}
@@ -182,11 +182,11 @@
182182
}else if( isNew ){
183183
fossil_print("ADDED %s\n", zPathname);
184184
}else if( isDeleted ){
185185
fossil_print("DELETED %s\n", zPathname);
186186
}else if( !file_isfile(zFullName) ){
187
- if( access(zFullName, 0)==0 ){
187
+ if( file_access(zFullName, 0)==0 ){
188188
fossil_print("NOT_A_FILE %s\n", zPathname);
189189
}else{
190190
fossil_print("MISSING %s\n", zPathname);
191191
}
192192
}else if( chnged ){
193193
--- src/checkin.c
+++ src/checkin.c
@@ -54,11 +54,11 @@
54 char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
55 blob_append(report, zPrefix, nPrefix);
56 if( isDeleted ){
57 blob_appendf(report, "DELETED %s\n", zPathname);
58 }else if( !file_isfile(zFullName) ){
59 if( access(zFullName, 0)==0 ){
60 blob_appendf(report, "NOT_A_FILE %s\n", zPathname);
61 if( missingIsFatal ){
62 fossil_warning("not a file: %s", zPathname);
63 nErr++;
64 }
@@ -182,11 +182,11 @@
182 }else if( isNew ){
183 fossil_print("ADDED %s\n", zPathname);
184 }else if( isDeleted ){
185 fossil_print("DELETED %s\n", zPathname);
186 }else if( !file_isfile(zFullName) ){
187 if( access(zFullName, 0)==0 ){
188 fossil_print("NOT_A_FILE %s\n", zPathname);
189 }else{
190 fossil_print("MISSING %s\n", zPathname);
191 }
192 }else if( chnged ){
193
--- src/checkin.c
+++ src/checkin.c
@@ -54,11 +54,11 @@
54 char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
55 blob_append(report, zPrefix, nPrefix);
56 if( isDeleted ){
57 blob_appendf(report, "DELETED %s\n", zPathname);
58 }else if( !file_isfile(zFullName) ){
59 if( file_access(zFullName, 0)==0 ){
60 blob_appendf(report, "NOT_A_FILE %s\n", zPathname);
61 if( missingIsFatal ){
62 fossil_warning("not a file: %s", zPathname);
63 nErr++;
64 }
@@ -182,11 +182,11 @@
182 }else if( isNew ){
183 fossil_print("ADDED %s\n", zPathname);
184 }else if( isDeleted ){
185 fossil_print("DELETED %s\n", zPathname);
186 }else if( !file_isfile(zFullName) ){
187 if( file_access(zFullName, 0)==0 ){
188 fossil_print("NOT_A_FILE %s\n", zPathname);
189 }else{
190 fossil_print("MISSING %s\n", zPathname);
191 }
192 }else if( chnged ){
193
+6 -6
--- src/db.c
+++ src/db.c
@@ -728,11 +728,11 @@
728728
static int isValidLocalDb(const char *zDbName){
729729
i64 lsize;
730730
int rc;
731731
sqlite3_stmt *pStmt;
732732
733
- if( access(zDbName, F_OK) ) return 0;
733
+ if( file_access(zDbName, F_OK) ) return 0;
734734
lsize = file_size(zDbName);
735735
if( lsize%1024!=0 || lsize<4096 ) return 0;
736736
db_open_or_attach(zDbName, "localdb");
737737
g.localOpen = 1;
738738
db_open_config(0);
@@ -803,11 +803,11 @@
803803
n = strlen(zPwd);
804804
zPwdConv = mprintf("%/", zPwd);
805805
strncpy(zPwd, zPwdConv, 2000-20);
806806
free(zPwdConv);
807807
while( n>0 ){
808
- if( access(zPwd, W_OK) ) break;
808
+ if( file_access(zPwd, W_OK) ) break;
809809
for(i=0; i<sizeof(aDbName)/sizeof(aDbName[0]); i++){
810810
sqlite3_snprintf(sizeof(zPwd)-n, &zPwd[n], "%s", aDbName[i]);
811811
if( isValidLocalDb(zPwd) ){
812812
/* Found a valid checkout database file */
813813
zPwd[n] = 0;
@@ -841,15 +841,15 @@
841841
}
842842
if( zDbName==0 ){
843843
db_err("unable to find the name of a repository database");
844844
}
845845
}
846
- if( access(zDbName, R_OK) || file_size(zDbName)<1024 ){
847
- if( access(zDbName, 0) ){
846
+ if( file_access(zDbName, R_OK) || file_size(zDbName)<1024 ){
847
+ if( file_access(zDbName, 0) ){
848848
fossil_panic("repository does not exist or"
849849
" is in an unreadable directory: %s", zDbName);
850
- }else if( access(zDbName, R_OK) ){
850
+ }else if( file_access(zDbName, R_OK) ){
851851
fossil_panic("read permission denied for repository %s", zDbName);
852852
}else{
853853
fossil_panic("not a valid repository: %s", zDbName);
854854
}
855855
}
@@ -952,11 +952,11 @@
952952
fossil_fatal("not in a local checkout");
953953
return;
954954
}
955955
file_canonical_name(g.argv[2], &repo);
956956
zRepo = blob_str(&repo);
957
- if( access(zRepo, 0) ){
957
+ if( file_access(zRepo, 0) ){
958958
fossil_fatal("no such file: %s", zRepo);
959959
}
960960
db_open_or_attach(zRepo, "test_repo");
961961
db_lset("repository", blob_str(&repo));
962962
db_close(1);
963963
--- src/db.c
+++ src/db.c
@@ -728,11 +728,11 @@
728 static int isValidLocalDb(const char *zDbName){
729 i64 lsize;
730 int rc;
731 sqlite3_stmt *pStmt;
732
733 if( access(zDbName, F_OK) ) return 0;
734 lsize = file_size(zDbName);
735 if( lsize%1024!=0 || lsize<4096 ) return 0;
736 db_open_or_attach(zDbName, "localdb");
737 g.localOpen = 1;
738 db_open_config(0);
@@ -803,11 +803,11 @@
803 n = strlen(zPwd);
804 zPwdConv = mprintf("%/", zPwd);
805 strncpy(zPwd, zPwdConv, 2000-20);
806 free(zPwdConv);
807 while( n>0 ){
808 if( access(zPwd, W_OK) ) break;
809 for(i=0; i<sizeof(aDbName)/sizeof(aDbName[0]); i++){
810 sqlite3_snprintf(sizeof(zPwd)-n, &zPwd[n], "%s", aDbName[i]);
811 if( isValidLocalDb(zPwd) ){
812 /* Found a valid checkout database file */
813 zPwd[n] = 0;
@@ -841,15 +841,15 @@
841 }
842 if( zDbName==0 ){
843 db_err("unable to find the name of a repository database");
844 }
845 }
846 if( access(zDbName, R_OK) || file_size(zDbName)<1024 ){
847 if( access(zDbName, 0) ){
848 fossil_panic("repository does not exist or"
849 " is in an unreadable directory: %s", zDbName);
850 }else if( access(zDbName, R_OK) ){
851 fossil_panic("read permission denied for repository %s", zDbName);
852 }else{
853 fossil_panic("not a valid repository: %s", zDbName);
854 }
855 }
@@ -952,11 +952,11 @@
952 fossil_fatal("not in a local checkout");
953 return;
954 }
955 file_canonical_name(g.argv[2], &repo);
956 zRepo = blob_str(&repo);
957 if( access(zRepo, 0) ){
958 fossil_fatal("no such file: %s", zRepo);
959 }
960 db_open_or_attach(zRepo, "test_repo");
961 db_lset("repository", blob_str(&repo));
962 db_close(1);
963
--- src/db.c
+++ src/db.c
@@ -728,11 +728,11 @@
728 static int isValidLocalDb(const char *zDbName){
729 i64 lsize;
730 int rc;
731 sqlite3_stmt *pStmt;
732
733 if( file_access(zDbName, F_OK) ) return 0;
734 lsize = file_size(zDbName);
735 if( lsize%1024!=0 || lsize<4096 ) return 0;
736 db_open_or_attach(zDbName, "localdb");
737 g.localOpen = 1;
738 db_open_config(0);
@@ -803,11 +803,11 @@
803 n = strlen(zPwd);
804 zPwdConv = mprintf("%/", zPwd);
805 strncpy(zPwd, zPwdConv, 2000-20);
806 free(zPwdConv);
807 while( n>0 ){
808 if( file_access(zPwd, W_OK) ) break;
809 for(i=0; i<sizeof(aDbName)/sizeof(aDbName[0]); i++){
810 sqlite3_snprintf(sizeof(zPwd)-n, &zPwd[n], "%s", aDbName[i]);
811 if( isValidLocalDb(zPwd) ){
812 /* Found a valid checkout database file */
813 zPwd[n] = 0;
@@ -841,15 +841,15 @@
841 }
842 if( zDbName==0 ){
843 db_err("unable to find the name of a repository database");
844 }
845 }
846 if( file_access(zDbName, R_OK) || file_size(zDbName)<1024 ){
847 if( file_access(zDbName, 0) ){
848 fossil_panic("repository does not exist or"
849 " is in an unreadable directory: %s", zDbName);
850 }else if( file_access(zDbName, R_OK) ){
851 fossil_panic("read permission denied for repository %s", zDbName);
852 }else{
853 fossil_panic("not a valid repository: %s", zDbName);
854 }
855 }
@@ -952,11 +952,11 @@
952 fossil_fatal("not in a local checkout");
953 return;
954 }
955 file_canonical_name(g.argv[2], &repo);
956 zRepo = blob_str(&repo);
957 if( file_access(zRepo, 0) ){
958 fossil_fatal("no such file: %s", zRepo);
959 }
960 db_open_or_attach(zRepo, "test_repo");
961 db_lset("repository", blob_str(&repo));
962 db_close(1);
963
+2 -2
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -100,11 +100,11 @@
100100
** zFile2 */
101101
blob_zero(&nameFile1);
102102
do{
103103
blob_reset(&nameFile1);
104104
blob_appendf(&nameFile1, "%s~%d", zFile2, cnt++);
105
- }while( access(blob_str(&nameFile1),0)==0 );
105
+ }while( file_access(blob_str(&nameFile1),0)==0 );
106106
blob_write_to_file(pFile1, blob_str(&nameFile1));
107107
108108
/* Construct the external diff command */
109109
blob_zero(&cmd);
110110
blob_appendf(&cmd, "%s ", zDiffCmd);
@@ -263,11 +263,11 @@
263263
char *zToFree = zFullName;
264264
int showDiff = 1;
265265
if( isDeleted ){
266266
diff_printf("DELETED %s\n", zPathname);
267267
if( !asNewFile ){ showDiff = 0; zFullName = "/dev/null"; }
268
- }else if( access(zFullName, 0) ){
268
+ }else if( file_access(zFullName, 0) ){
269269
diff_printf("MISSING %s\n", zPathname);
270270
if( !asNewFile ){ showDiff = 0; }
271271
}else if( isNew ){
272272
diff_printf("ADDED %s\n", zPathname);
273273
srcid = 0;
274274
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -100,11 +100,11 @@
100 ** zFile2 */
101 blob_zero(&nameFile1);
102 do{
103 blob_reset(&nameFile1);
104 blob_appendf(&nameFile1, "%s~%d", zFile2, cnt++);
105 }while( access(blob_str(&nameFile1),0)==0 );
106 blob_write_to_file(pFile1, blob_str(&nameFile1));
107
108 /* Construct the external diff command */
109 blob_zero(&cmd);
110 blob_appendf(&cmd, "%s ", zDiffCmd);
@@ -263,11 +263,11 @@
263 char *zToFree = zFullName;
264 int showDiff = 1;
265 if( isDeleted ){
266 diff_printf("DELETED %s\n", zPathname);
267 if( !asNewFile ){ showDiff = 0; zFullName = "/dev/null"; }
268 }else if( access(zFullName, 0) ){
269 diff_printf("MISSING %s\n", zPathname);
270 if( !asNewFile ){ showDiff = 0; }
271 }else if( isNew ){
272 diff_printf("ADDED %s\n", zPathname);
273 srcid = 0;
274
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -100,11 +100,11 @@
100 ** zFile2 */
101 blob_zero(&nameFile1);
102 do{
103 blob_reset(&nameFile1);
104 blob_appendf(&nameFile1, "%s~%d", zFile2, cnt++);
105 }while( file_access(blob_str(&nameFile1),0)==0 );
106 blob_write_to_file(pFile1, blob_str(&nameFile1));
107
108 /* Construct the external diff command */
109 blob_zero(&cmd);
110 blob_appendf(&cmd, "%s ", zDiffCmd);
@@ -263,11 +263,11 @@
263 char *zToFree = zFullName;
264 int showDiff = 1;
265 if( isDeleted ){
266 diff_printf("DELETED %s\n", zPathname);
267 if( !asNewFile ){ showDiff = 0; zFullName = "/dev/null"; }
268 }else if( file_access(zFullName, 0) ){
269 diff_printf("MISSING %s\n", zPathname);
270 if( !asNewFile ){ showDiff = 0; }
271 }else if( isNew ){
272 diff_printf("ADDED %s\n", zPathname);
273 srcid = 0;
274
+10
--- src/file.c
+++ src/file.c
@@ -122,10 +122,20 @@
122122
}else{
123123
rc = getStat(0);
124124
}
125125
return rc ? 0 : (S_ISDIR(fileStat.st_mode) ? 1 : 2);
126126
}
127
+
128
+/*
129
+** Wrapper around the access() system call.
130
+*/
131
+int file_access(const char *zFilename, int flags){
132
+ char *zMbcs = fossil_utf8_to_mbcs(zFilename);
133
+ int rc = access(zMbcs, flags);
134
+ fossil_mbcs_free(zMbcs);
135
+ return rc;
136
+}
127137
128138
/*
129139
** Find an unused filename similar to zBase with zSuffix appended.
130140
**
131141
** Make the name relative to the working directory if relFlag is true.
132142
--- src/file.c
+++ src/file.c
@@ -122,10 +122,20 @@
122 }else{
123 rc = getStat(0);
124 }
125 return rc ? 0 : (S_ISDIR(fileStat.st_mode) ? 1 : 2);
126 }
 
 
 
 
 
 
 
 
 
 
127
128 /*
129 ** Find an unused filename similar to zBase with zSuffix appended.
130 **
131 ** Make the name relative to the working directory if relFlag is true.
132
--- src/file.c
+++ src/file.c
@@ -122,10 +122,20 @@
122 }else{
123 rc = getStat(0);
124 }
125 return rc ? 0 : (S_ISDIR(fileStat.st_mode) ? 1 : 2);
126 }
127
128 /*
129 ** Wrapper around the access() system call.
130 */
131 int file_access(const char *zFilename, int flags){
132 char *zMbcs = fossil_utf8_to_mbcs(zFilename);
133 int rc = access(zMbcs, flags);
134 fossil_mbcs_free(zMbcs);
135 return rc;
136 }
137
138 /*
139 ** Find an unused filename similar to zBase with zSuffix appended.
140 **
141 ** Make the name relative to the working directory if relFlag is true.
142
+1 -1
--- src/main.c
+++ src/main.c
@@ -1332,11 +1332,11 @@
13321332
int bExists;
13331333
while( zPath && zPath[0] ){
13341334
while( zPath[0]==':' ) zPath++;
13351335
for(i=0; zPath[i] && zPath[i]!=':'; i++){}
13361336
zFull = mprintf("%.*s/%s", i, zPath, zBinary);
1337
- bExists = access(zFull, X_OK);
1337
+ bExists = file_access(zFull, X_OK);
13381338
free(zFull);
13391339
if( bExists==0 ) return 1;
13401340
zPath += i;
13411341
}
13421342
return 0;
13431343
--- src/main.c
+++ src/main.c
@@ -1332,11 +1332,11 @@
1332 int bExists;
1333 while( zPath && zPath[0] ){
1334 while( zPath[0]==':' ) zPath++;
1335 for(i=0; zPath[i] && zPath[i]!=':'; i++){}
1336 zFull = mprintf("%.*s/%s", i, zPath, zBinary);
1337 bExists = access(zFull, X_OK);
1338 free(zFull);
1339 if( bExists==0 ) return 1;
1340 zPath += i;
1341 }
1342 return 0;
1343
--- src/main.c
+++ src/main.c
@@ -1332,11 +1332,11 @@
1332 int bExists;
1333 while( zPath && zPath[0] ){
1334 while( zPath[0]==':' ) zPath++;
1335 for(i=0; zPath[i] && zPath[i]!=':'; i++){}
1336 zFull = mprintf("%.*s/%s", i, zPath, zBinary);
1337 bExists = file_access(zFull, X_OK);
1338 free(zFull);
1339 if( bExists==0 ) return 1;
1340 zPath += i;
1341 }
1342 return 0;
1343
+1 -1
--- src/rebuild.c
+++ src/rebuild.c
@@ -911,11 +911,11 @@
911911
}else{
912912
fossil_fatal("N(%s) is not a a valid prefix length!",zPrefixOpt);
913913
}
914914
}
915915
#ifndef _WIN32
916
- if( access(zDestDir, W_OK) ){
916
+ if( file_access(zDestDir, W_OK) ){
917917
fossil_fatal("DESTINATION(%s) is not writeable!",zDestDir);
918918
}
919919
#else
920920
/* write access on windows is not checked, errors will be
921921
** dected on blob_write_to_file
922922
--- src/rebuild.c
+++ src/rebuild.c
@@ -911,11 +911,11 @@
911 }else{
912 fossil_fatal("N(%s) is not a a valid prefix length!",zPrefixOpt);
913 }
914 }
915 #ifndef _WIN32
916 if( access(zDestDir, W_OK) ){
917 fossil_fatal("DESTINATION(%s) is not writeable!",zDestDir);
918 }
919 #else
920 /* write access on windows is not checked, errors will be
921 ** dected on blob_write_to_file
922
--- src/rebuild.c
+++ src/rebuild.c
@@ -911,11 +911,11 @@
911 }else{
912 fossil_fatal("N(%s) is not a a valid prefix length!",zPrefixOpt);
913 }
914 }
915 #ifndef _WIN32
916 if( file_access(zDestDir, W_OK) ){
917 fossil_fatal("DESTINATION(%s) is not writeable!",zDestDir);
918 }
919 #else
920 /* write access on windows is not checked, errors will be
921 ** dected on blob_write_to_file
922

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button