Fossil SCM
Convert filenames from UTF8 to MBCS on windows when checking if a file exists or checking its size, etc. Ticket [336924579dd95e7cceaeeae5].
Commit
48f5dadafd28a1ecaf0219fff0989ab87b912601
Parent
a65c97afd622bb1…
1 file changed
+12
-7
+12
-7
| --- src/file.c | ||
| +++ src/file.c | ||
| @@ -47,17 +47,19 @@ | ||
| 47 | 47 | static int getStat(const char *zFilename){ |
| 48 | 48 | int rc = 0; |
| 49 | 49 | if( zFilename==0 ){ |
| 50 | 50 | if( fileStatValid==0 ) rc = 1; |
| 51 | 51 | }else{ |
| 52 | - if( stat(zFilename, &fileStat)!=0 ){ | |
| 52 | + char *zMbcs = fossil_utf8_to_mbcs(zFilename); | |
| 53 | + if( stat(zMbcs, &fileStat)!=0 ){ | |
| 53 | 54 | fileStatValid = 0; |
| 54 | 55 | rc = 1; |
| 55 | 56 | }else{ |
| 56 | 57 | fileStatValid = 1; |
| 57 | 58 | rc = 0; |
| 58 | 59 | } |
| 60 | + fossil_mbcs_free(zMbcs); | |
| 59 | 61 | } |
| 60 | 62 | return rc; |
| 61 | 63 | } |
| 62 | 64 | |
| 63 | 65 | |
| @@ -225,11 +227,15 @@ | ||
| 225 | 227 | if( !forceFlag ) return 1; |
| 226 | 228 | file_delete(zName); |
| 227 | 229 | } |
| 228 | 230 | if( rc!=1 ){ |
| 229 | 231 | #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; | |
| 231 | 237 | #else |
| 232 | 238 | return mkdir(zName, 0755); |
| 233 | 239 | #endif |
| 234 | 240 | } |
| 235 | 241 | return 0; |
| @@ -627,17 +633,14 @@ | ||
| 627 | 633 | static const unsigned char zChars[] = |
| 628 | 634 | "abcdefghijklmnopqrstuvwxyz" |
| 629 | 635 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 630 | 636 | "0123456789"; |
| 631 | 637 | unsigned int i, j; |
| 632 | - struct stat buf; | |
| 633 | 638 | const char *zDir = "."; |
| 634 | 639 | |
| 635 | 640 | 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; | |
| 639 | 642 | zDir = azDirs[i]; |
| 640 | 643 | break; |
| 641 | 644 | } |
| 642 | 645 | |
| 643 | 646 | /* Check that the output buffer is large enough for the temporary file |
| @@ -653,11 +656,11 @@ | ||
| 653 | 656 | sqlite3_randomness(15, &zBuf[j]); |
| 654 | 657 | for(i=0; i<15; i++, j++){ |
| 655 | 658 | zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ]; |
| 656 | 659 | } |
| 657 | 660 | zBuf[j] = 0; |
| 658 | - }while( access(zBuf,0)==0 ); | |
| 661 | + }while( file_size(zBuf)<0 ); | |
| 659 | 662 | } |
| 660 | 663 | |
| 661 | 664 | |
| 662 | 665 | /* |
| 663 | 666 | ** Return true if a file named zName exists and has identical content |
| @@ -689,10 +692,11 @@ | ||
| 689 | 692 | ** Translate MBCS to UTF8. Return a pointer. Call fossil_mbcs_free() |
| 690 | 693 | ** to deallocate any memory used to store the returned pointer when done. |
| 691 | 694 | */ |
| 692 | 695 | char *fossil_mbcs_to_utf8(const char *zMbcs){ |
| 693 | 696 | #ifdef _WIN32 |
| 697 | + extern char *sqlite3_win32_mbcs_to_utf8(const char*); | |
| 694 | 698 | return sqlite3_win32_mbcs_to_utf8(zMbcs); |
| 695 | 699 | #else |
| 696 | 700 | return (char*)zMbcs; /* No-op on unix */ |
| 697 | 701 | #endif |
| 698 | 702 | } |
| @@ -701,10 +705,11 @@ | ||
| 701 | 705 | ** Translate UTF8 to MBCS. Return a pointer. Call fossil_mbcs_free() |
| 702 | 706 | ** to deallocate any memory used to store the returned pointer when done. |
| 703 | 707 | */ |
| 704 | 708 | char *fossil_utf8_to_mbcs(const char *zUtf8){ |
| 705 | 709 | #ifdef _WIN32 |
| 710 | + extern char *sqlite3_win32_utf8_to_mbcs(const char*); | |
| 706 | 711 | return sqlite3_win32_utf8_to_mbcs(zUtf8); |
| 707 | 712 | #else |
| 708 | 713 | return (char*)zUtf8; /* No-op on unix */ |
| 709 | 714 | #endif |
| 710 | 715 | } |
| 711 | 716 |
| --- 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 |