Fossil SCM

Better support for unicode filenames on Win32 (Not tested on other platforms yet, will not work!)

jan.nijtmans 2012-08-24 13:15 UTC trunk
Commit d8e1431fc0f3e7a9795436d36a2d67855755efa0
3 files changed +79 -19 +9 -9 +10 -10
+79 -19
--- src/file.c
+++ src/file.c
@@ -27,10 +27,14 @@
2727
#include <sys/stat.h>
2828
#include <unistd.h>
2929
#include <string.h>
3030
#include <errno.h>
3131
#include "file.h"
32
+#if defined(_WIN32)
33
+#include <direct.h>
34
+#endif
35
+
3236
3337
/*
3438
** On Windows, include the Platform SDK header file.
3539
*/
3640
#ifdef _WIN32
@@ -68,12 +72,12 @@
6872
}else{
6973
return stat(zFilename, buf);
7074
}
7175
#else
7276
int rc = 0;
73
- char *zMbcs = fossil_utf8_to_mbcs(zFilename);
74
- rc = stat(zMbcs, buf);
77
+ wchar_t *zMbcs = fossil_utf8_to_unicode(zFilename);
78
+ rc = _wstati64(zMbcs, buf);
7579
fossil_mbcs_free(zMbcs);
7680
return rc;
7781
#endif
7882
}
7983
@@ -298,13 +302,17 @@
298302
299303
/*
300304
** Wrapper around the access() system call.
301305
*/
302306
int file_access(const char *zFilename, int flags){
303
- char *zMbcs = fossil_utf8_to_mbcs(zFilename);
304
- int rc = access(zMbcs, flags);
307
+#ifdef _WIN32
308
+ wchar_t *zMbcs = fossil_utf8_to_unicode(zFilename);
309
+ int rc = _waccess(zMbcs, flags);
305310
fossil_mbcs_free(zMbcs);
311
+#else
312
+ int rc = access(zFilename, flags);
313
+#endif
306314
return rc;
307315
}
308316
309317
/*
310318
** Find an unused filename similar to zBase with zSuffix appended.
@@ -389,13 +397,17 @@
389397
390398
/*
391399
** Delete a file.
392400
*/
393401
void file_delete(const char *zFilename){
394
- char *z = fossil_utf8_to_mbcs(zFilename);
395
- unlink(z);
402
+#ifdef _WIN32
403
+ wchar_t *z = fossil_utf8_to_unicode(zFilename);
404
+ _wunlink(z);
396405
fossil_mbcs_free(z);
406
+#else
407
+ unlink(zFilename);
408
+#endif
397409
}
398410
399411
/*
400412
** Create the directory named in the argument, if it does not already
401413
** exist. If forceFlag is 1, delete any prior non-directory object
@@ -561,24 +573,24 @@
561573
}
562574
563575
/*
564576
** Get the current working directory.
565577
**
566
-** On windows, the name is converted from MBCS to UTF8 and all '\\'
578
+** On windows, the name is converted from unicode to UTF8 and all '\\'
567579
** characters are converted to '/'. No conversions are needed on
568580
** unix.
569581
*/
570582
void file_getcwd(char *zBuf, int nBuf){
571583
#ifdef _WIN32
572584
char *zPwdUtf8;
573585
int nPwd;
574586
int i;
575
- char zPwd[2000];
576
- if( getcwd(zPwd, sizeof(zPwd)-1)==0 ){
587
+ wchar_t zPwd[2000];
588
+ if( _wgetcwd(zPwd, sizeof(zPwd)-1)==0 ){
577589
fossil_fatal("cannot find the current working directory.");
578590
}
579
- zPwdUtf8 = fossil_mbcs_to_utf8(zPwd);
591
+ zPwdUtf8 = fossil_unicode_to_utf8(zPwd);
580592
nPwd = strlen(zPwdUtf8);
581593
if( nPwd > nBuf-1 ){
582594
fossil_fatal("pwd too big: max %d\n", nBuf-1);
583595
}
584596
for(i=0; zPwdUtf8[i]; i++) if( zPwdUtf8[i]=='\\' ) zPwdUtf8[i] = '/';
@@ -928,14 +940,14 @@
928940
unsigned int i, j;
929941
const char *zDir = ".";
930942
int cnt = 0;
931943
932944
#if defined(_WIN32)
933
- char zTmpPath[MAX_PATH];
945
+ wchar_t zTmpPath[MAX_PATH];
934946
935
- if( GetTempPath(sizeof(zTmpPath), zTmpPath) ){
936
- azDirs[0] = zTmpPath;
947
+ if( GetTempPathW(MAX_PATH, zTmpPath) ){
948
+ azDirs[0] = fossil_unicode_to_utf8(zTmpPath);
937949
}
938950
939951
azDirs[1] = fossil_getenv("TEMP");
940952
azDirs[2] = fossil_getenv("TMP");
941953
#endif
@@ -1014,10 +1026,29 @@
10141026
return sqlite3_win32_mbcs_to_utf8(zMbcs);
10151027
#else
10161028
return (char*)zMbcs; /* No-op on unix */
10171029
#endif
10181030
}
1031
+
1032
+/*
1033
+** Translate Unicode to UTF8. Return a pointer to the translated text.
1034
+** Call fossil_mbcs_free() to deallocate any memory used to store the
1035
+** returned pointer when done.
1036
+*/
1037
+char *fossil_unicode_to_utf8(const void *zUnicode){
1038
+#ifdef _WIN32
1039
+ int nByte = WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, 0, 0, 0, 0);
1040
+ char *zUtf = sqlite3_malloc( nByte );
1041
+ if( zUtf==0 ){
1042
+ return 0;
1043
+ }
1044
+ WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, zUtf, nByte, 0, 0);
1045
+ return zUtf;
1046
+#else
1047
+ return (char *)zUnicode; /* No-op on unix */
1048
+#endif
1049
+}
10191050
10201051
/*
10211052
** Translate UTF8 to MBCS for use in system calls. Return a pointer to the
10221053
** translated text.. Call fossil_mbcs_free() to deallocate any memory
10231054
** used to store the returned pointer when done.
@@ -1028,18 +1059,41 @@
10281059
return sqlite3_win32_utf8_to_mbcs(zUtf8);
10291060
#else
10301061
return (char*)zUtf8; /* No-op on unix */
10311062
#endif
10321063
}
1064
+
1065
+/*
1066
+** Translate UTF8 to unicode for use in system calls. Return a pointer to the
1067
+** translated text.. Call fossil_mbcs_free() to deallocate any memory
1068
+** used to store the returned pointer when done.
1069
+*/
1070
+void *fossil_utf8_to_unicode(const char *zUtf8){
1071
+#ifdef _WIN32
1072
+ int nByte = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
1073
+ wchar_t *zUnicode = sqlite3_malloc( nByte * 2 );
1074
+ if( zUnicode==0 ){
1075
+ return 0;
1076
+ }
1077
+ MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, nByte);
1078
+ return zUnicode;
1079
+#else
1080
+ return (void *)zUtf8; /* No-op on unix */
1081
+#endif
1082
+}
10331083
10341084
/*
10351085
** Return the value of an environment variable as UTF8.
10361086
*/
10371087
char *fossil_getenv(const char *zName){
1038
- char *zValue = getenv(zName);
10391088
#ifdef _WIN32
1040
- if( zValue ) zValue = fossil_mbcs_to_utf8(zValue);
1089
+ wchar_t *uName = fossil_utf8_to_unicode(zName);
1090
+ void *zValue = _wgetenv(uName);
1091
+ fossil_mbcs_free(uName);
1092
+ if( zValue ) zValue = fossil_unicode_to_utf8(zValue);
1093
+#else
1094
+ char *zValue = getenv(zName);
10411095
#endif
10421096
return zValue;
10431097
}
10441098
10451099
/*
@@ -1085,11 +1139,11 @@
10851139
10861140
/*
10871141
** Translate MBCS to UTF8. Return a pointer. Call fossil_mbcs_free()
10881142
** to deallocate any memory used to store the returned pointer when done.
10891143
*/
1090
-void fossil_mbcs_free(char *zOld){
1144
+void fossil_mbcs_free(void *zOld){
10911145
#ifdef _WIN32
10921146
extern void sqlite3_free(void*);
10931147
sqlite3_free(zOld);
10941148
#else
10951149
/* No-op on unix */
@@ -1098,10 +1152,16 @@
10981152
10991153
/*
11001154
** Like fopen() but always takes a UTF8 argument.
11011155
*/
11021156
FILE *fossil_fopen(const char *zName, const char *zMode){
1103
- char *zMbcs = fossil_utf8_to_mbcs(zName);
1104
- FILE *f = fopen(zMbcs, zMode);
1105
- fossil_mbcs_free(zMbcs);
1157
+#ifdef _WIN32
1158
+ wchar_t *uMode = fossil_utf8_to_unicode(zMode);
1159
+ wchar_t *uName = fossil_utf8_to_unicode(zName);
1160
+ FILE *f = _wfopen(uName, uMode);
1161
+ fossil_mbcs_free(uName);
1162
+ fossil_mbcs_free(uMode);
1163
+#else
1164
+ FILE *f = fopen(zName, zMode);
1165
+#endif
11061166
return f;
11071167
}
11081168
--- src/file.c
+++ src/file.c
@@ -27,10 +27,14 @@
27 #include <sys/stat.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <errno.h>
31 #include "file.h"
 
 
 
 
32
33 /*
34 ** On Windows, include the Platform SDK header file.
35 */
36 #ifdef _WIN32
@@ -68,12 +72,12 @@
68 }else{
69 return stat(zFilename, buf);
70 }
71 #else
72 int rc = 0;
73 char *zMbcs = fossil_utf8_to_mbcs(zFilename);
74 rc = stat(zMbcs, buf);
75 fossil_mbcs_free(zMbcs);
76 return rc;
77 #endif
78 }
79
@@ -298,13 +302,17 @@
298
299 /*
300 ** Wrapper around the access() system call.
301 */
302 int file_access(const char *zFilename, int flags){
303 char *zMbcs = fossil_utf8_to_mbcs(zFilename);
304 int rc = access(zMbcs, flags);
 
305 fossil_mbcs_free(zMbcs);
 
 
 
306 return rc;
307 }
308
309 /*
310 ** Find an unused filename similar to zBase with zSuffix appended.
@@ -389,13 +397,17 @@
389
390 /*
391 ** Delete a file.
392 */
393 void file_delete(const char *zFilename){
394 char *z = fossil_utf8_to_mbcs(zFilename);
395 unlink(z);
 
396 fossil_mbcs_free(z);
 
 
 
397 }
398
399 /*
400 ** Create the directory named in the argument, if it does not already
401 ** exist. If forceFlag is 1, delete any prior non-directory object
@@ -561,24 +573,24 @@
561 }
562
563 /*
564 ** Get the current working directory.
565 **
566 ** On windows, the name is converted from MBCS to UTF8 and all '\\'
567 ** characters are converted to '/'. No conversions are needed on
568 ** unix.
569 */
570 void file_getcwd(char *zBuf, int nBuf){
571 #ifdef _WIN32
572 char *zPwdUtf8;
573 int nPwd;
574 int i;
575 char zPwd[2000];
576 if( getcwd(zPwd, sizeof(zPwd)-1)==0 ){
577 fossil_fatal("cannot find the current working directory.");
578 }
579 zPwdUtf8 = fossil_mbcs_to_utf8(zPwd);
580 nPwd = strlen(zPwdUtf8);
581 if( nPwd > nBuf-1 ){
582 fossil_fatal("pwd too big: max %d\n", nBuf-1);
583 }
584 for(i=0; zPwdUtf8[i]; i++) if( zPwdUtf8[i]=='\\' ) zPwdUtf8[i] = '/';
@@ -928,14 +940,14 @@
928 unsigned int i, j;
929 const char *zDir = ".";
930 int cnt = 0;
931
932 #if defined(_WIN32)
933 char zTmpPath[MAX_PATH];
934
935 if( GetTempPath(sizeof(zTmpPath), zTmpPath) ){
936 azDirs[0] = zTmpPath;
937 }
938
939 azDirs[1] = fossil_getenv("TEMP");
940 azDirs[2] = fossil_getenv("TMP");
941 #endif
@@ -1014,10 +1026,29 @@
1014 return sqlite3_win32_mbcs_to_utf8(zMbcs);
1015 #else
1016 return (char*)zMbcs; /* No-op on unix */
1017 #endif
1018 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1019
1020 /*
1021 ** Translate UTF8 to MBCS for use in system calls. Return a pointer to the
1022 ** translated text.. Call fossil_mbcs_free() to deallocate any memory
1023 ** used to store the returned pointer when done.
@@ -1028,18 +1059,41 @@
1028 return sqlite3_win32_utf8_to_mbcs(zUtf8);
1029 #else
1030 return (char*)zUtf8; /* No-op on unix */
1031 #endif
1032 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1033
1034 /*
1035 ** Return the value of an environment variable as UTF8.
1036 */
1037 char *fossil_getenv(const char *zName){
1038 char *zValue = getenv(zName);
1039 #ifdef _WIN32
1040 if( zValue ) zValue = fossil_mbcs_to_utf8(zValue);
 
 
 
 
 
1041 #endif
1042 return zValue;
1043 }
1044
1045 /*
@@ -1085,11 +1139,11 @@
1085
1086 /*
1087 ** Translate MBCS to UTF8. Return a pointer. Call fossil_mbcs_free()
1088 ** to deallocate any memory used to store the returned pointer when done.
1089 */
1090 void fossil_mbcs_free(char *zOld){
1091 #ifdef _WIN32
1092 extern void sqlite3_free(void*);
1093 sqlite3_free(zOld);
1094 #else
1095 /* No-op on unix */
@@ -1098,10 +1152,16 @@
1098
1099 /*
1100 ** Like fopen() but always takes a UTF8 argument.
1101 */
1102 FILE *fossil_fopen(const char *zName, const char *zMode){
1103 char *zMbcs = fossil_utf8_to_mbcs(zName);
1104 FILE *f = fopen(zMbcs, zMode);
1105 fossil_mbcs_free(zMbcs);
 
 
 
 
 
 
1106 return f;
1107 }
1108
--- src/file.c
+++ src/file.c
@@ -27,10 +27,14 @@
27 #include <sys/stat.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <errno.h>
31 #include "file.h"
32 #if defined(_WIN32)
33 #include <direct.h>
34 #endif
35
36
37 /*
38 ** On Windows, include the Platform SDK header file.
39 */
40 #ifdef _WIN32
@@ -68,12 +72,12 @@
72 }else{
73 return stat(zFilename, buf);
74 }
75 #else
76 int rc = 0;
77 wchar_t *zMbcs = fossil_utf8_to_unicode(zFilename);
78 rc = _wstati64(zMbcs, buf);
79 fossil_mbcs_free(zMbcs);
80 return rc;
81 #endif
82 }
83
@@ -298,13 +302,17 @@
302
303 /*
304 ** Wrapper around the access() system call.
305 */
306 int file_access(const char *zFilename, int flags){
307 #ifdef _WIN32
308 wchar_t *zMbcs = fossil_utf8_to_unicode(zFilename);
309 int rc = _waccess(zMbcs, flags);
310 fossil_mbcs_free(zMbcs);
311 #else
312 int rc = access(zFilename, flags);
313 #endif
314 return rc;
315 }
316
317 /*
318 ** Find an unused filename similar to zBase with zSuffix appended.
@@ -389,13 +397,17 @@
397
398 /*
399 ** Delete a file.
400 */
401 void file_delete(const char *zFilename){
402 #ifdef _WIN32
403 wchar_t *z = fossil_utf8_to_unicode(zFilename);
404 _wunlink(z);
405 fossil_mbcs_free(z);
406 #else
407 unlink(zFilename);
408 #endif
409 }
410
411 /*
412 ** Create the directory named in the argument, if it does not already
413 ** exist. If forceFlag is 1, delete any prior non-directory object
@@ -561,24 +573,24 @@
573 }
574
575 /*
576 ** Get the current working directory.
577 **
578 ** On windows, the name is converted from unicode to UTF8 and all '\\'
579 ** characters are converted to '/'. No conversions are needed on
580 ** unix.
581 */
582 void file_getcwd(char *zBuf, int nBuf){
583 #ifdef _WIN32
584 char *zPwdUtf8;
585 int nPwd;
586 int i;
587 wchar_t zPwd[2000];
588 if( _wgetcwd(zPwd, sizeof(zPwd)-1)==0 ){
589 fossil_fatal("cannot find the current working directory.");
590 }
591 zPwdUtf8 = fossil_unicode_to_utf8(zPwd);
592 nPwd = strlen(zPwdUtf8);
593 if( nPwd > nBuf-1 ){
594 fossil_fatal("pwd too big: max %d\n", nBuf-1);
595 }
596 for(i=0; zPwdUtf8[i]; i++) if( zPwdUtf8[i]=='\\' ) zPwdUtf8[i] = '/';
@@ -928,14 +940,14 @@
940 unsigned int i, j;
941 const char *zDir = ".";
942 int cnt = 0;
943
944 #if defined(_WIN32)
945 wchar_t zTmpPath[MAX_PATH];
946
947 if( GetTempPathW(MAX_PATH, zTmpPath) ){
948 azDirs[0] = fossil_unicode_to_utf8(zTmpPath);
949 }
950
951 azDirs[1] = fossil_getenv("TEMP");
952 azDirs[2] = fossil_getenv("TMP");
953 #endif
@@ -1014,10 +1026,29 @@
1026 return sqlite3_win32_mbcs_to_utf8(zMbcs);
1027 #else
1028 return (char*)zMbcs; /* No-op on unix */
1029 #endif
1030 }
1031
1032 /*
1033 ** Translate Unicode to UTF8. Return a pointer to the translated text.
1034 ** Call fossil_mbcs_free() to deallocate any memory used to store the
1035 ** returned pointer when done.
1036 */
1037 char *fossil_unicode_to_utf8(const void *zUnicode){
1038 #ifdef _WIN32
1039 int nByte = WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, 0, 0, 0, 0);
1040 char *zUtf = sqlite3_malloc( nByte );
1041 if( zUtf==0 ){
1042 return 0;
1043 }
1044 WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, zUtf, nByte, 0, 0);
1045 return zUtf;
1046 #else
1047 return (char *)zUnicode; /* No-op on unix */
1048 #endif
1049 }
1050
1051 /*
1052 ** Translate UTF8 to MBCS for use in system calls. Return a pointer to the
1053 ** translated text.. Call fossil_mbcs_free() to deallocate any memory
1054 ** used to store the returned pointer when done.
@@ -1028,18 +1059,41 @@
1059 return sqlite3_win32_utf8_to_mbcs(zUtf8);
1060 #else
1061 return (char*)zUtf8; /* No-op on unix */
1062 #endif
1063 }
1064
1065 /*
1066 ** Translate UTF8 to unicode for use in system calls. Return a pointer to the
1067 ** translated text.. Call fossil_mbcs_free() to deallocate any memory
1068 ** used to store the returned pointer when done.
1069 */
1070 void *fossil_utf8_to_unicode(const char *zUtf8){
1071 #ifdef _WIN32
1072 int nByte = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0);
1073 wchar_t *zUnicode = sqlite3_malloc( nByte * 2 );
1074 if( zUnicode==0 ){
1075 return 0;
1076 }
1077 MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, nByte);
1078 return zUnicode;
1079 #else
1080 return (void *)zUtf8; /* No-op on unix */
1081 #endif
1082 }
1083
1084 /*
1085 ** Return the value of an environment variable as UTF8.
1086 */
1087 char *fossil_getenv(const char *zName){
 
1088 #ifdef _WIN32
1089 wchar_t *uName = fossil_utf8_to_unicode(zName);
1090 void *zValue = _wgetenv(uName);
1091 fossil_mbcs_free(uName);
1092 if( zValue ) zValue = fossil_unicode_to_utf8(zValue);
1093 #else
1094 char *zValue = getenv(zName);
1095 #endif
1096 return zValue;
1097 }
1098
1099 /*
@@ -1085,11 +1139,11 @@
1139
1140 /*
1141 ** Translate MBCS to UTF8. Return a pointer. Call fossil_mbcs_free()
1142 ** to deallocate any memory used to store the returned pointer when done.
1143 */
1144 void fossil_mbcs_free(void *zOld){
1145 #ifdef _WIN32
1146 extern void sqlite3_free(void*);
1147 sqlite3_free(zOld);
1148 #else
1149 /* No-op on unix */
@@ -1098,10 +1152,16 @@
1152
1153 /*
1154 ** Like fopen() but always takes a UTF8 argument.
1155 */
1156 FILE *fossil_fopen(const char *zName, const char *zMode){
1157 #ifdef _WIN32
1158 wchar_t *uMode = fossil_utf8_to_unicode(zMode);
1159 wchar_t *uName = fossil_utf8_to_unicode(zName);
1160 FILE *f = _wfopen(uName, uMode);
1161 fossil_mbcs_free(uName);
1162 fossil_mbcs_free(uMode);
1163 #else
1164 FILE *f = fopen(zName, zMode);
1165 #endif
1166 return f;
1167 }
1168
+9 -9
--- src/rebuild.c
+++ src/rebuild.c
@@ -818,28 +818,28 @@
818818
/*
819819
** Recursively read all files from the directory zPath and install
820820
** every file read as a new artifact in the repository.
821821
*/
822822
void recon_read_dir(char *zPath){
823
- DIR *d;
824
- struct dirent *pEntry;
823
+ _WDIR *d;
824
+ struct _wdirent *pEntry;
825825
Blob aContent; /* content of the just read artifact */
826826
static int nFileRead = 0;
827
- char *zMbcsPath;
827
+ wchar_t *zMbcsPath;
828828
char *zUtf8Name;
829829
830
- zMbcsPath = fossil_utf8_to_mbcs(zPath);
831
- d = opendir(zMbcsPath);
830
+ zMbcsPath = fossil_utf8_to_unicode(zPath);
831
+ d = _wopendir(zMbcsPath);
832832
if( d ){
833
- while( (pEntry=readdir(d))!=0 ){
833
+ while( (pEntry=_wreaddir(d))!=0 ){
834834
Blob path;
835835
char *zSubpath;
836836
837
- if( pEntry->d_name[0]=='.' ){
837
+ if( pEntry->d_name[0]==L'.' ){
838838
continue;
839839
}
840
- zUtf8Name = fossil_mbcs_to_utf8(pEntry->d_name);
840
+ zUtf8Name = fossil_unicode_to_utf8(pEntry->d_name);
841841
zSubpath = mprintf("%s/%s", zPath, zUtf8Name);
842842
fossil_mbcs_free(zUtf8Name);
843843
if( file_isdir(zSubpath)==1 ){
844844
recon_read_dir(zSubpath);
845845
}
@@ -854,11 +854,11 @@
854854
blob_reset(&aContent);
855855
free(zSubpath);
856856
fossil_print("\r%d", ++nFileRead);
857857
fflush(stdout);
858858
}
859
- closedir(d);
859
+ _wclosedir(d);
860860
}else {
861861
fossil_panic("encountered error %d while trying to open \"%s\".",
862862
errno, g.argv[3]);
863863
}
864864
fossil_mbcs_free(zMbcsPath);
865865
--- src/rebuild.c
+++ src/rebuild.c
@@ -818,28 +818,28 @@
818 /*
819 ** Recursively read all files from the directory zPath and install
820 ** every file read as a new artifact in the repository.
821 */
822 void recon_read_dir(char *zPath){
823 DIR *d;
824 struct dirent *pEntry;
825 Blob aContent; /* content of the just read artifact */
826 static int nFileRead = 0;
827 char *zMbcsPath;
828 char *zUtf8Name;
829
830 zMbcsPath = fossil_utf8_to_mbcs(zPath);
831 d = opendir(zMbcsPath);
832 if( d ){
833 while( (pEntry=readdir(d))!=0 ){
834 Blob path;
835 char *zSubpath;
836
837 if( pEntry->d_name[0]=='.' ){
838 continue;
839 }
840 zUtf8Name = fossil_mbcs_to_utf8(pEntry->d_name);
841 zSubpath = mprintf("%s/%s", zPath, zUtf8Name);
842 fossil_mbcs_free(zUtf8Name);
843 if( file_isdir(zSubpath)==1 ){
844 recon_read_dir(zSubpath);
845 }
@@ -854,11 +854,11 @@
854 blob_reset(&aContent);
855 free(zSubpath);
856 fossil_print("\r%d", ++nFileRead);
857 fflush(stdout);
858 }
859 closedir(d);
860 }else {
861 fossil_panic("encountered error %d while trying to open \"%s\".",
862 errno, g.argv[3]);
863 }
864 fossil_mbcs_free(zMbcsPath);
865
--- src/rebuild.c
+++ src/rebuild.c
@@ -818,28 +818,28 @@
818 /*
819 ** Recursively read all files from the directory zPath and install
820 ** every file read as a new artifact in the repository.
821 */
822 void recon_read_dir(char *zPath){
823 _WDIR *d;
824 struct _wdirent *pEntry;
825 Blob aContent; /* content of the just read artifact */
826 static int nFileRead = 0;
827 wchar_t *zMbcsPath;
828 char *zUtf8Name;
829
830 zMbcsPath = fossil_utf8_to_unicode(zPath);
831 d = _wopendir(zMbcsPath);
832 if( d ){
833 while( (pEntry=_wreaddir(d))!=0 ){
834 Blob path;
835 char *zSubpath;
836
837 if( pEntry->d_name[0]==L'.' ){
838 continue;
839 }
840 zUtf8Name = fossil_unicode_to_utf8(pEntry->d_name);
841 zSubpath = mprintf("%s/%s", zPath, zUtf8Name);
842 fossil_mbcs_free(zUtf8Name);
843 if( file_isdir(zSubpath)==1 ){
844 recon_read_dir(zSubpath);
845 }
@@ -854,11 +854,11 @@
854 blob_reset(&aContent);
855 free(zSubpath);
856 fossil_print("\r%d", ++nFileRead);
857 fflush(stdout);
858 }
859 _wclosedir(d);
860 }else {
861 fossil_panic("encountered error %d while trying to open \"%s\".",
862 errno, g.argv[3]);
863 }
864 fossil_mbcs_free(zMbcsPath);
865
+10 -10
--- src/vfile.c
+++ src/vfile.c
@@ -381,18 +381,18 @@
381381
** Any files or directories that match the glob pattern pIgnore are
382382
** excluded from the scan. Name matching occurs after the first
383383
** nPrefix characters are elided from the filename.
384384
*/
385385
void vfile_scan(Blob *pPath, int nPrefix, int allFlag, Glob *pIgnore){
386
- DIR *d;
386
+ _WDIR *d;
387387
int origSize;
388388
const char *zDir;
389
- struct dirent *pEntry;
389
+ struct _wdirent *pEntry;
390390
int skipAll = 0;
391391
static Stmt ins;
392392
static int depth = 0;
393
- char *zMbcs;
393
+ wchar_t *zMbcs;
394394
395395
origSize = blob_size(pPath);
396396
if( pIgnore ){
397397
blob_appendf(pPath, "/");
398398
if( glob_match(pIgnore, &blob_str(pPath)[nPrefix+1]) ) skipAll = 1;
@@ -407,22 +407,22 @@
407407
);
408408
}
409409
depth++;
410410
411411
zDir = blob_str(pPath);
412
- zMbcs = fossil_utf8_to_mbcs(zDir);
413
- d = opendir(zMbcs);
412
+ zMbcs = fossil_utf8_to_unicode(zDir);
413
+ d = _wopendir(zMbcs);
414414
if( d ){
415
- while( (pEntry=readdir(d))!=0 ){
415
+ while( (pEntry=_wreaddir(d))!=0 ){
416416
char *zPath;
417417
char *zUtf8;
418
- if( pEntry->d_name[0]=='.' ){
418
+ if( pEntry->d_name[0]==L'.' ){
419419
if( !allFlag ) continue;
420420
if( pEntry->d_name[1]==0 ) continue;
421
- if( pEntry->d_name[1]=='.' && pEntry->d_name[2]==0 ) continue;
421
+ if( pEntry->d_name[1]==L'.' && pEntry->d_name[2]==0 ) continue;
422422
}
423
- zUtf8 = fossil_mbcs_to_utf8(pEntry->d_name);
423
+ zUtf8 = fossil_unicode_to_utf8(pEntry->d_name);
424424
blob_appendf(pPath, "/%s", zUtf8);
425425
fossil_mbcs_free(zUtf8);
426426
zPath = blob_str(pPath);
427427
if( glob_match(pIgnore, &zPath[nPrefix+1]) ){
428428
/* do nothing */
@@ -435,11 +435,11 @@
435435
db_step(&ins);
436436
db_reset(&ins);
437437
}
438438
blob_resize(pPath, origSize);
439439
}
440
- closedir(d);
440
+ _wclosedir(d);
441441
}
442442
fossil_mbcs_free(zMbcs);
443443
444444
depth--;
445445
if( depth==0 ){
446446
--- src/vfile.c
+++ src/vfile.c
@@ -381,18 +381,18 @@
381 ** Any files or directories that match the glob pattern pIgnore are
382 ** excluded from the scan. Name matching occurs after the first
383 ** nPrefix characters are elided from the filename.
384 */
385 void vfile_scan(Blob *pPath, int nPrefix, int allFlag, Glob *pIgnore){
386 DIR *d;
387 int origSize;
388 const char *zDir;
389 struct dirent *pEntry;
390 int skipAll = 0;
391 static Stmt ins;
392 static int depth = 0;
393 char *zMbcs;
394
395 origSize = blob_size(pPath);
396 if( pIgnore ){
397 blob_appendf(pPath, "/");
398 if( glob_match(pIgnore, &blob_str(pPath)[nPrefix+1]) ) skipAll = 1;
@@ -407,22 +407,22 @@
407 );
408 }
409 depth++;
410
411 zDir = blob_str(pPath);
412 zMbcs = fossil_utf8_to_mbcs(zDir);
413 d = opendir(zMbcs);
414 if( d ){
415 while( (pEntry=readdir(d))!=0 ){
416 char *zPath;
417 char *zUtf8;
418 if( pEntry->d_name[0]=='.' ){
419 if( !allFlag ) continue;
420 if( pEntry->d_name[1]==0 ) continue;
421 if( pEntry->d_name[1]=='.' && pEntry->d_name[2]==0 ) continue;
422 }
423 zUtf8 = fossil_mbcs_to_utf8(pEntry->d_name);
424 blob_appendf(pPath, "/%s", zUtf8);
425 fossil_mbcs_free(zUtf8);
426 zPath = blob_str(pPath);
427 if( glob_match(pIgnore, &zPath[nPrefix+1]) ){
428 /* do nothing */
@@ -435,11 +435,11 @@
435 db_step(&ins);
436 db_reset(&ins);
437 }
438 blob_resize(pPath, origSize);
439 }
440 closedir(d);
441 }
442 fossil_mbcs_free(zMbcs);
443
444 depth--;
445 if( depth==0 ){
446
--- src/vfile.c
+++ src/vfile.c
@@ -381,18 +381,18 @@
381 ** Any files or directories that match the glob pattern pIgnore are
382 ** excluded from the scan. Name matching occurs after the first
383 ** nPrefix characters are elided from the filename.
384 */
385 void vfile_scan(Blob *pPath, int nPrefix, int allFlag, Glob *pIgnore){
386 _WDIR *d;
387 int origSize;
388 const char *zDir;
389 struct _wdirent *pEntry;
390 int skipAll = 0;
391 static Stmt ins;
392 static int depth = 0;
393 wchar_t *zMbcs;
394
395 origSize = blob_size(pPath);
396 if( pIgnore ){
397 blob_appendf(pPath, "/");
398 if( glob_match(pIgnore, &blob_str(pPath)[nPrefix+1]) ) skipAll = 1;
@@ -407,22 +407,22 @@
407 );
408 }
409 depth++;
410
411 zDir = blob_str(pPath);
412 zMbcs = fossil_utf8_to_unicode(zDir);
413 d = _wopendir(zMbcs);
414 if( d ){
415 while( (pEntry=_wreaddir(d))!=0 ){
416 char *zPath;
417 char *zUtf8;
418 if( pEntry->d_name[0]==L'.' ){
419 if( !allFlag ) continue;
420 if( pEntry->d_name[1]==0 ) continue;
421 if( pEntry->d_name[1]==L'.' && pEntry->d_name[2]==0 ) continue;
422 }
423 zUtf8 = fossil_unicode_to_utf8(pEntry->d_name);
424 blob_appendf(pPath, "/%s", zUtf8);
425 fossil_mbcs_free(zUtf8);
426 zPath = blob_str(pPath);
427 if( glob_match(pIgnore, &zPath[nPrefix+1]) ){
428 /* do nothing */
@@ -435,11 +435,11 @@
435 db_step(&ins);
436 db_reset(&ins);
437 }
438 blob_resize(pPath, origSize);
439 }
440 _wclosedir(d);
441 }
442 fossil_mbcs_free(zMbcs);
443
444 depth--;
445 if( depth==0 ){
446

Keyboard Shortcuts

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