| | @@ -64,23 +64,24 @@ |
| 64 | 64 | ** Fill stat buf with information received from stat() or lstat(). |
| 65 | 65 | ** lstat() is called on Unix if isWd is TRUE and allow-symlinks setting is on. |
| 66 | 66 | ** |
| 67 | 67 | */ |
| 68 | 68 | static int fossil_stat(const char *zFilename, struct stat *buf, int isWd){ |
| 69 | + int rc; |
| 69 | 70 | #if !defined(_WIN32) |
| 71 | + char *zMbcs = fossil_utf8_to_filename(zFilename); |
| 70 | 72 | if( isWd && g.allowSymlinks ){ |
| 71 | | - return lstat(zFilename, buf); |
| 73 | + rc = lstat(zMbcs, buf); |
| 72 | 74 | }else{ |
| 73 | | - return stat(zFilename, buf); |
| 75 | + rc = stat(zMbcs, buf); |
| 74 | 76 | } |
| 75 | 77 | #else |
| 76 | | - int rc = 0; |
| 77 | 78 | wchar_t *zMbcs = fossil_utf8_to_filename(zFilename); |
| 78 | 79 | rc = _wstati64(zMbcs, buf); |
| 80 | +#endif |
| 79 | 81 | fossil_filename_free(zMbcs); |
| 80 | 82 | return rc; |
| 81 | | -#endif |
| 82 | 83 | } |
| 83 | 84 | |
| 84 | 85 | /* |
| 85 | 86 | ** Fill in the fileStat variable for the file named zFilename. |
| 86 | 87 | ** If zFilename==0, then use the previous value of fileStat if |
| | @@ -305,14 +306,15 @@ |
| 305 | 306 | */ |
| 306 | 307 | int file_access(const char *zFilename, int flags){ |
| 307 | 308 | #ifdef _WIN32 |
| 308 | 309 | wchar_t *zMbcs = fossil_utf8_to_filename(zFilename); |
| 309 | 310 | int rc = _waccess(zMbcs, flags); |
| 310 | | - fossil_filename_free(zMbcs); |
| 311 | 311 | #else |
| 312 | | - int rc = access(zFilename, flags); |
| 312 | + char *zMbcs = fossil_utf8_to_filename(zFilename); |
| 313 | + int rc = access(zMbcs, flags); |
| 313 | 314 | #endif |
| 315 | + fossil_filename_free(zMbcs); |
| 314 | 316 | return rc; |
| 315 | 317 | } |
| 316 | 318 | |
| 317 | 319 | /* |
| 318 | 320 | ** Find an unused filename similar to zBase with zSuffix appended. |
| | @@ -402,19 +404,20 @@ |
| 402 | 404 | #if !defined(_WIN32) |
| 403 | 405 | struct timeval tv[2]; |
| 404 | 406 | memset(tv, 0, sizeof(tv[0])*2); |
| 405 | 407 | tv[0].tv_sec = newMTime; |
| 406 | 408 | tv[1].tv_sec = newMTime; |
| 407 | | - utimes(zFilename, tv); |
| 409 | + char *zMbcs = fossil_utf8_to_filename(zFilename); |
| 410 | + utimes(zMbcs, tv); |
| 408 | 411 | #else |
| 409 | 412 | struct _utimbuf tb; |
| 410 | 413 | wchar_t *zMbcs = fossil_utf8_to_filename(zFilename); |
| 411 | 414 | tb.actime = newMTime; |
| 412 | 415 | tb.modtime = newMTime; |
| 413 | 416 | _wutime(zMbcs, &tb); |
| 414 | | - fossil_filename_free(zMbcs); |
| 415 | 417 | #endif |
| 418 | + fossil_filename_free(zMbcs); |
| 416 | 419 | } |
| 417 | 420 | |
| 418 | 421 | /* |
| 419 | 422 | ** COMMAND: test-set-mtime |
| 420 | 423 | ** |
| | @@ -443,14 +446,15 @@ |
| 443 | 446 | */ |
| 444 | 447 | void file_delete(const char *zFilename){ |
| 445 | 448 | #ifdef _WIN32 |
| 446 | 449 | wchar_t *z = fossil_utf8_to_filename(zFilename); |
| 447 | 450 | _wunlink(z); |
| 448 | | - fossil_filename_free(z); |
| 449 | 451 | #else |
| 452 | + char *z = fossil_utf8_to_filename(zFilename); |
| 450 | 453 | unlink(zFilename); |
| 451 | 454 | #endif |
| 455 | + fossil_filename_free(z); |
| 452 | 456 | } |
| 453 | 457 | |
| 454 | 458 | /* |
| 455 | 459 | ** Create the directory named in the argument, if it does not already |
| 456 | 460 | ** exist. If forceFlag is 1, delete any prior non-directory object |
| | @@ -464,18 +468,18 @@ |
| 464 | 468 | if( !forceFlag ) return 1; |
| 465 | 469 | file_delete(zName); |
| 466 | 470 | } |
| 467 | 471 | if( rc!=1 ){ |
| 468 | 472 | #if defined(_WIN32) |
| 469 | | - int rc; |
| 470 | 473 | wchar_t *zMbcs = fossil_utf8_to_filename(zName); |
| 471 | 474 | rc = _wmkdir(zMbcs); |
| 475 | +#else |
| 476 | + char *zMbcs = fossil_utf8_to_filename(zName); |
| 477 | + rc = mkdir(zName, 0755); |
| 478 | +#endif |
| 472 | 479 | fossil_filename_free(zMbcs); |
| 473 | 480 | return rc; |
| 474 | | -#else |
| 475 | | - return mkdir(zName, 0755); |
| 476 | | -#endif |
| 477 | 481 | } |
| 478 | 482 | return 0; |
| 479 | 483 | } |
| 480 | 484 | |
| 481 | 485 | /* |
| | @@ -580,11 +584,11 @@ |
| 580 | 584 | } |
| 581 | 585 | |
| 582 | 586 | /* |
| 583 | 587 | ** Simplify a filename by |
| 584 | 588 | ** |
| 585 | | -** * Convert all \ into / on windows |
| 589 | +** * Convert all \ into / on windows and cygwin |
| 586 | 590 | ** * removing any trailing and duplicate / |
| 587 | 591 | ** * removing /./ |
| 588 | 592 | ** * removing /A/../ |
| 589 | 593 | ** |
| 590 | 594 | ** Changes are made in-place. Return the new name length. |
| | @@ -705,13 +709,13 @@ |
| 705 | 709 | ** Return true if zPath is an absolute pathname. Return false |
| 706 | 710 | ** if it is relative. |
| 707 | 711 | */ |
| 708 | 712 | int file_is_absolute_path(const char *zPath){ |
| 709 | 713 | if( zPath[0]=='/' |
| 710 | | -#if defined(_WIN32) |
| 714 | +#if defined(_WIN32) || defined(__CYGWIN__) |
| 711 | 715 | || zPath[0]=='\\' |
| 712 | | - || (strlen(zPath)>3 && zPath[1]==':' |
| 716 | + || (fossil_isalpha(zPath[0]) && zPath[1]==':' |
| 713 | 717 | && (zPath[2]=='\\' || zPath[2]=='/')) |
| 714 | 718 | #endif |
| 715 | 719 | ){ |
| 716 | 720 | return 1; |
| 717 | 721 | }else{ |
| | @@ -728,21 +732,21 @@ |
| 728 | 732 | ** If the slash parameter is non-zero, the trailing slash, if any, |
| 729 | 733 | ** is retained. |
| 730 | 734 | */ |
| 731 | 735 | void file_canonical_name(const char *zOrigName, Blob *pOut, int slash){ |
| 732 | 736 | if( file_is_absolute_path(zOrigName) ){ |
| 733 | | -#if defined(_WIN32) |
| 737 | +#if defined(_WIN32) || defined(__CYGWIN__) |
| 734 | 738 | char *zOut; |
| 735 | 739 | #endif |
| 736 | 740 | blob_set(pOut, zOrigName); |
| 737 | 741 | blob_materialize(pOut); |
| 738 | | -#if defined(_WIN32) |
| 742 | +#if defined(_WIN32) || defined(__CYGWIN__) |
| 739 | 743 | /* |
| 740 | | - ** On Windows, normalize the drive letter to upper case. |
| 744 | + ** On Windows/cygwin, normalize the drive letter to upper case. |
| 741 | 745 | */ |
| 742 | 746 | zOut = blob_str(pOut); |
| 743 | | - if( fossil_isalpha(zOut[0]) && zOut[1]==':' ){ |
| 747 | + if( fossil_islower(zOut[0]) && zOut[1]==':' ){ |
| 744 | 748 | zOut[0] = fossil_toupper(zOut[0]); |
| 745 | 749 | } |
| 746 | 750 | #endif |
| 747 | 751 | }else{ |
| 748 | 752 | char zPwd[2000]; |
| | @@ -749,11 +753,11 @@ |
| 749 | 753 | file_getcwd(zPwd, sizeof(zPwd)-strlen(zOrigName)); |
| 750 | 754 | #if defined(_WIN32) |
| 751 | 755 | /* |
| 752 | 756 | ** On Windows, normalize the drive letter to upper case. |
| 753 | 757 | */ |
| 754 | | - if( fossil_isalpha(zPwd[0]) && zPwd[1]==':' ){ |
| 758 | + if( fossil_islower(zPwd[0]) && zPwd[1]==':' ){ |
| 755 | 759 | zPwd[0] = fossil_toupper(zPwd[0]); |
| 756 | 760 | } |
| 757 | 761 | #endif |
| 758 | 762 | blob_zero(pOut); |
| 759 | 763 | blob_appendf(pOut, "%//%/", zPwd, zOrigName); |
| | @@ -798,12 +802,12 @@ |
| 798 | 802 | ** contain no "/./" or "/../" terms. |
| 799 | 803 | */ |
| 800 | 804 | int file_is_canonical(const char *z){ |
| 801 | 805 | int i; |
| 802 | 806 | if( z[0]!='/' |
| 803 | | -#if defined(_WIN32) |
| 804 | | - && (z[0]==0 || z[1]!=':' || z[2]!='/') |
| 807 | +#if defined(_WIN32) || defined(__CYGWIN__) |
| 808 | + && (!fossil_isupper(z[0]) || z[1]!=':' || z[2]!='/') |
| 805 | 809 | #endif |
| 806 | 810 | ) return 0; |
| 807 | 811 | |
| 808 | 812 | for(i=0; z[i]; i++){ |
| 809 | 813 | if( z[i]=='\\' ) return 0; |
| | @@ -1019,11 +1023,11 @@ |
| 1019 | 1023 | 0, /* TEMP */ |
| 1020 | 1024 | 0, /* TMP */ |
| 1021 | 1025 | ".", |
| 1022 | 1026 | }; |
| 1023 | 1027 | #else |
| 1024 | | - static const char *azDirs[] = { |
| 1028 | + static const char *const azDirs[] = { |
| 1025 | 1029 | "/var/tmp", |
| 1026 | 1030 | "/usr/tmp", |
| 1027 | 1031 | "/tmp", |
| 1028 | 1032 | "/temp", |
| 1029 | 1033 | ".", |
| 1030 | 1034 | |