Fossil SCM

Convert filenames from UTF8 to MBCS on windows when checking if a file exists or checking its size, etc. Ticket [336924579dd95e7cceaeeae5].

drh 2011-05-03 18:32 windows-i18n
Commit 48f5dadafd28a1ecaf0219fff0989ab87b912601
1 file changed +12 -7
+12 -7
--- src/file.c
+++ src/file.c
@@ -47,17 +47,19 @@
4747
static int getStat(const char *zFilename){
4848
int rc = 0;
4949
if( zFilename==0 ){
5050
if( fileStatValid==0 ) rc = 1;
5151
}else{
52
- if( stat(zFilename, &fileStat)!=0 ){
52
+ char *zMbcs = fossil_utf8_to_mbcs(zFilename);
53
+ if( stat(zMbcs, &fileStat)!=0 ){
5354
fileStatValid = 0;
5455
rc = 1;
5556
}else{
5657
fileStatValid = 1;
5758
rc = 0;
5859
}
60
+ fossil_mbcs_free(zMbcs);
5961
}
6062
return rc;
6163
}
6264
6365
@@ -225,11 +227,15 @@
225227
if( !forceFlag ) return 1;
226228
file_delete(zName);
227229
}
228230
if( rc!=1 ){
229231
#if defined(_WIN32)
230
- return mkdir(zName);
232
+ int rc;
233
+ char *zMbcs = fossil_utf8_to_mbcs(zName);
234
+ rc = mkdir(zMbcs);
235
+ fossil_mbcs_free(zMbcs);
236
+ return rc;
231237
#else
232238
return mkdir(zName, 0755);
233239
#endif
234240
}
235241
return 0;
@@ -627,17 +633,14 @@
627633
static const unsigned char zChars[] =
628634
"abcdefghijklmnopqrstuvwxyz"
629635
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
630636
"0123456789";
631637
unsigned int i, j;
632
- struct stat buf;
633638
const char *zDir = ".";
634639
635640
for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); i++){
636
- if( stat(azDirs[i], &buf) ) continue;
637
- if( !S_ISDIR(buf.st_mode) ) continue;
638
- if( access(azDirs[i], 07) ) continue;
641
+ if( !file_isdir(azDirs[i]) ) continue;
639642
zDir = azDirs[i];
640643
break;
641644
}
642645
643646
/* Check that the output buffer is large enough for the temporary file
@@ -653,11 +656,11 @@
653656
sqlite3_randomness(15, &zBuf[j]);
654657
for(i=0; i<15; i++, j++){
655658
zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
656659
}
657660
zBuf[j] = 0;
658
- }while( access(zBuf,0)==0 );
661
+ }while( file_size(zBuf)<0 );
659662
}
660663
661664
662665
/*
663666
** Return true if a file named zName exists and has identical content
@@ -689,10 +692,11 @@
689692
** Translate MBCS to UTF8. Return a pointer. Call fossil_mbcs_free()
690693
** to deallocate any memory used to store the returned pointer when done.
691694
*/
692695
char *fossil_mbcs_to_utf8(const char *zMbcs){
693696
#ifdef _WIN32
697
+ extern char *sqlite3_win32_mbcs_to_utf8(const char*);
694698
return sqlite3_win32_mbcs_to_utf8(zMbcs);
695699
#else
696700
return (char*)zMbcs; /* No-op on unix */
697701
#endif
698702
}
@@ -701,10 +705,11 @@
701705
** Translate UTF8 to MBCS. Return a pointer. Call fossil_mbcs_free()
702706
** to deallocate any memory used to store the returned pointer when done.
703707
*/
704708
char *fossil_utf8_to_mbcs(const char *zUtf8){
705709
#ifdef _WIN32
710
+ extern char *sqlite3_win32_utf8_to_mbcs(const char*);
706711
return sqlite3_win32_utf8_to_mbcs(zUtf8);
707712
#else
708713
return (char*)zUtf8; /* No-op on unix */
709714
#endif
710715
}
711716
--- src/file.c
+++ src/file.c
@@ -47,17 +47,19 @@
47 static int getStat(const char *zFilename){
48 int rc = 0;
49 if( zFilename==0 ){
50 if( fileStatValid==0 ) rc = 1;
51 }else{
52 if( stat(zFilename, &fileStat)!=0 ){
 
53 fileStatValid = 0;
54 rc = 1;
55 }else{
56 fileStatValid = 1;
57 rc = 0;
58 }
 
59 }
60 return rc;
61 }
62
63
@@ -225,11 +227,15 @@
225 if( !forceFlag ) return 1;
226 file_delete(zName);
227 }
228 if( rc!=1 ){
229 #if defined(_WIN32)
230 return mkdir(zName);
 
 
 
 
231 #else
232 return mkdir(zName, 0755);
233 #endif
234 }
235 return 0;
@@ -627,17 +633,14 @@
627 static const unsigned char zChars[] =
628 "abcdefghijklmnopqrstuvwxyz"
629 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
630 "0123456789";
631 unsigned int i, j;
632 struct stat buf;
633 const char *zDir = ".";
634
635 for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); i++){
636 if( stat(azDirs[i], &buf) ) continue;
637 if( !S_ISDIR(buf.st_mode) ) continue;
638 if( access(azDirs[i], 07) ) continue;
639 zDir = azDirs[i];
640 break;
641 }
642
643 /* Check that the output buffer is large enough for the temporary file
@@ -653,11 +656,11 @@
653 sqlite3_randomness(15, &zBuf[j]);
654 for(i=0; i<15; i++, j++){
655 zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
656 }
657 zBuf[j] = 0;
658 }while( access(zBuf,0)==0 );
659 }
660
661
662 /*
663 ** Return true if a file named zName exists and has identical content
@@ -689,10 +692,11 @@
689 ** Translate MBCS to UTF8. Return a pointer. Call fossil_mbcs_free()
690 ** to deallocate any memory used to store the returned pointer when done.
691 */
692 char *fossil_mbcs_to_utf8(const char *zMbcs){
693 #ifdef _WIN32
 
694 return sqlite3_win32_mbcs_to_utf8(zMbcs);
695 #else
696 return (char*)zMbcs; /* No-op on unix */
697 #endif
698 }
@@ -701,10 +705,11 @@
701 ** Translate UTF8 to MBCS. Return a pointer. Call fossil_mbcs_free()
702 ** to deallocate any memory used to store the returned pointer when done.
703 */
704 char *fossil_utf8_to_mbcs(const char *zUtf8){
705 #ifdef _WIN32
 
706 return sqlite3_win32_utf8_to_mbcs(zUtf8);
707 #else
708 return (char*)zUtf8; /* No-op on unix */
709 #endif
710 }
711
--- src/file.c
+++ src/file.c
@@ -47,17 +47,19 @@
47 static int getStat(const char *zFilename){
48 int rc = 0;
49 if( zFilename==0 ){
50 if( fileStatValid==0 ) rc = 1;
51 }else{
52 char *zMbcs = fossil_utf8_to_mbcs(zFilename);
53 if( stat(zMbcs, &fileStat)!=0 ){
54 fileStatValid = 0;
55 rc = 1;
56 }else{
57 fileStatValid = 1;
58 rc = 0;
59 }
60 fossil_mbcs_free(zMbcs);
61 }
62 return rc;
63 }
64
65
@@ -225,11 +227,15 @@
227 if( !forceFlag ) return 1;
228 file_delete(zName);
229 }
230 if( rc!=1 ){
231 #if defined(_WIN32)
232 int rc;
233 char *zMbcs = fossil_utf8_to_mbcs(zName);
234 rc = mkdir(zMbcs);
235 fossil_mbcs_free(zMbcs);
236 return rc;
237 #else
238 return mkdir(zName, 0755);
239 #endif
240 }
241 return 0;
@@ -627,17 +633,14 @@
633 static const unsigned char zChars[] =
634 "abcdefghijklmnopqrstuvwxyz"
635 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
636 "0123456789";
637 unsigned int i, j;
 
638 const char *zDir = ".";
639
640 for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); i++){
641 if( !file_isdir(azDirs[i]) ) continue;
 
 
642 zDir = azDirs[i];
643 break;
644 }
645
646 /* Check that the output buffer is large enough for the temporary file
@@ -653,11 +656,11 @@
656 sqlite3_randomness(15, &zBuf[j]);
657 for(i=0; i<15; i++, j++){
658 zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
659 }
660 zBuf[j] = 0;
661 }while( file_size(zBuf)<0 );
662 }
663
664
665 /*
666 ** Return true if a file named zName exists and has identical content
@@ -689,10 +692,11 @@
692 ** Translate MBCS to UTF8. Return a pointer. Call fossil_mbcs_free()
693 ** to deallocate any memory used to store the returned pointer when done.
694 */
695 char *fossil_mbcs_to_utf8(const char *zMbcs){
696 #ifdef _WIN32
697 extern char *sqlite3_win32_mbcs_to_utf8(const char*);
698 return sqlite3_win32_mbcs_to_utf8(zMbcs);
699 #else
700 return (char*)zMbcs; /* No-op on unix */
701 #endif
702 }
@@ -701,10 +705,11 @@
705 ** Translate UTF8 to MBCS. Return a pointer. Call fossil_mbcs_free()
706 ** to deallocate any memory used to store the returned pointer when done.
707 */
708 char *fossil_utf8_to_mbcs(const char *zUtf8){
709 #ifdef _WIN32
710 extern char *sqlite3_win32_utf8_to_mbcs(const char*);
711 return sqlite3_win32_utf8_to_mbcs(zUtf8);
712 #else
713 return (char*)zUtf8; /* No-op on unix */
714 #endif
715 }
716

Keyboard Shortcuts

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