Fossil SCM

Teach fossil_utf8_to_filename() how to handle win32 paths on Cygwin. Use this function where-ever possible.

jan.nijtmans 2013-03-01 13:19 trunk
Commit caf2eb25fa2485ee7b57d3fac3e74fd0b40cb946
3 files changed +8 -11 +28 -24 +24 -1
+8 -11
--- src/db.c
+++ src/db.c
@@ -29,13 +29,10 @@
2929
**
3030
*/
3131
#include "config.h"
3232
#if ! defined(_WIN32)
3333
# include <pwd.h>
34
-# if defined(__CYGWIN__)
35
-# include <sys/cygwin.h>
36
-# endif
3734
#endif
3835
#include <sqlite3.h>
3936
#include <sys/types.h>
4037
#include <sys/stat.h>
4138
#include <unistd.h>
@@ -794,11 +791,11 @@
794791
** connection so that we can join between the various databases. In that
795792
** case, invoke this routine with useAttach as 1.
796793
*/
797794
void db_open_config(int useAttach){
798795
char *zDbName;
799
- const char *zHome;
796
+ char *zHome;
800797
if( g.configOpen ) return;
801798
#if defined(_WIN32) || defined(__CYGWIN__)
802799
zHome = fossil_getenv("LOCALAPPDATA");
803800
if( zHome==0 ){
804801
zHome = fossil_getenv("APPDATA");
@@ -808,15 +805,14 @@
808805
if( zDrive && zHome ) zHome = mprintf("%s%s", zDrive, zHome);
809806
}
810807
}
811808
#if defined(__CYGWIN__)
812809
if( zHome!=0 ){
813
- /* We now have the win32 path, but we need the Cygwin equivalent */
814
- ssize_t size = cygwin_conv_path(CCP_WIN_A_TO_POSIX, zHome, 0, 0);
815
- char *converted = fossil_malloc(size);
816
- cygwin_conv_path(CCP_WIN_A_TO_POSIX, zHome, converted, size);
817
- zHome = converted;
810
+ /* We now have the win32 path, but we need the Cygwin equivalent. */
811
+ char *zPath = fossil_utf8_to_filename(zHome);
812
+ fossil_filename_free(zHome);
813
+ zHome = zPath;
818814
}
819815
#endif
820816
if( zHome==0 ){
821817
fossil_fatal("cannot locate home directory - "
822818
"please set the LOCALAPPDATA or APPDATA or HOMEPATH "
@@ -830,12 +826,12 @@
830826
}
831827
#endif
832828
if( file_isdir(zHome)!=1 ){
833829
fossil_fatal("invalid home directory: %s", zHome);
834830
}
835
-#ifndef _WIN32
836
- if( access(zHome, W_OK) ){
831
+#if !defined(_WIN32) && !defined(__CYGWIN__)
832
+ if( file_access(zHome, W_OK) ){
837833
fossil_fatal("home directory %s must be writeable", zHome);
838834
}
839835
#endif
840836
g.zHome = mprintf("%/", zHome);
841837
#if defined(_WIN32) || defined(__CYGWIN__)
@@ -856,10 +852,11 @@
856852
g.dbConfig = db_open(zDbName);
857853
g.zConfigDbType = "configdb";
858854
}
859855
g.configOpen = 1;
860856
free(zDbName);
857
+ fossil_filename_free(zHome);
861858
}
862859
863860
864861
/*
865862
** Returns TRUE if zTable exists in the local database but lacks column
866863
--- src/db.c
+++ src/db.c
@@ -29,13 +29,10 @@
29 **
30 */
31 #include "config.h"
32 #if ! defined(_WIN32)
33 # include <pwd.h>
34 # if defined(__CYGWIN__)
35 # include <sys/cygwin.h>
36 # endif
37 #endif
38 #include <sqlite3.h>
39 #include <sys/types.h>
40 #include <sys/stat.h>
41 #include <unistd.h>
@@ -794,11 +791,11 @@
794 ** connection so that we can join between the various databases. In that
795 ** case, invoke this routine with useAttach as 1.
796 */
797 void db_open_config(int useAttach){
798 char *zDbName;
799 const char *zHome;
800 if( g.configOpen ) return;
801 #if defined(_WIN32) || defined(__CYGWIN__)
802 zHome = fossil_getenv("LOCALAPPDATA");
803 if( zHome==0 ){
804 zHome = fossil_getenv("APPDATA");
@@ -808,15 +805,14 @@
808 if( zDrive && zHome ) zHome = mprintf("%s%s", zDrive, zHome);
809 }
810 }
811 #if defined(__CYGWIN__)
812 if( zHome!=0 ){
813 /* We now have the win32 path, but we need the Cygwin equivalent */
814 ssize_t size = cygwin_conv_path(CCP_WIN_A_TO_POSIX, zHome, 0, 0);
815 char *converted = fossil_malloc(size);
816 cygwin_conv_path(CCP_WIN_A_TO_POSIX, zHome, converted, size);
817 zHome = converted;
818 }
819 #endif
820 if( zHome==0 ){
821 fossil_fatal("cannot locate home directory - "
822 "please set the LOCALAPPDATA or APPDATA or HOMEPATH "
@@ -830,12 +826,12 @@
830 }
831 #endif
832 if( file_isdir(zHome)!=1 ){
833 fossil_fatal("invalid home directory: %s", zHome);
834 }
835 #ifndef _WIN32
836 if( access(zHome, W_OK) ){
837 fossil_fatal("home directory %s must be writeable", zHome);
838 }
839 #endif
840 g.zHome = mprintf("%/", zHome);
841 #if defined(_WIN32) || defined(__CYGWIN__)
@@ -856,10 +852,11 @@
856 g.dbConfig = db_open(zDbName);
857 g.zConfigDbType = "configdb";
858 }
859 g.configOpen = 1;
860 free(zDbName);
 
861 }
862
863
864 /*
865 ** Returns TRUE if zTable exists in the local database but lacks column
866
--- src/db.c
+++ src/db.c
@@ -29,13 +29,10 @@
29 **
30 */
31 #include "config.h"
32 #if ! defined(_WIN32)
33 # include <pwd.h>
 
 
 
34 #endif
35 #include <sqlite3.h>
36 #include <sys/types.h>
37 #include <sys/stat.h>
38 #include <unistd.h>
@@ -794,11 +791,11 @@
791 ** connection so that we can join between the various databases. In that
792 ** case, invoke this routine with useAttach as 1.
793 */
794 void db_open_config(int useAttach){
795 char *zDbName;
796 char *zHome;
797 if( g.configOpen ) return;
798 #if defined(_WIN32) || defined(__CYGWIN__)
799 zHome = fossil_getenv("LOCALAPPDATA");
800 if( zHome==0 ){
801 zHome = fossil_getenv("APPDATA");
@@ -808,15 +805,14 @@
805 if( zDrive && zHome ) zHome = mprintf("%s%s", zDrive, zHome);
806 }
807 }
808 #if defined(__CYGWIN__)
809 if( zHome!=0 ){
810 /* We now have the win32 path, but we need the Cygwin equivalent. */
811 char *zPath = fossil_utf8_to_filename(zHome);
812 fossil_filename_free(zHome);
813 zHome = zPath;
 
814 }
815 #endif
816 if( zHome==0 ){
817 fossil_fatal("cannot locate home directory - "
818 "please set the LOCALAPPDATA or APPDATA or HOMEPATH "
@@ -830,12 +826,12 @@
826 }
827 #endif
828 if( file_isdir(zHome)!=1 ){
829 fossil_fatal("invalid home directory: %s", zHome);
830 }
831 #if !defined(_WIN32) && !defined(__CYGWIN__)
832 if( file_access(zHome, W_OK) ){
833 fossil_fatal("home directory %s must be writeable", zHome);
834 }
835 #endif
836 g.zHome = mprintf("%/", zHome);
837 #if defined(_WIN32) || defined(__CYGWIN__)
@@ -856,10 +852,11 @@
852 g.dbConfig = db_open(zDbName);
853 g.zConfigDbType = "configdb";
854 }
855 g.configOpen = 1;
856 free(zDbName);
857 fossil_filename_free(zHome);
858 }
859
860
861 /*
862 ** Returns TRUE if zTable exists in the local database but lacks column
863
+28 -24
--- src/file.c
+++ src/file.c
@@ -64,23 +64,24 @@
6464
** Fill stat buf with information received from stat() or lstat().
6565
** lstat() is called on Unix if isWd is TRUE and allow-symlinks setting is on.
6666
**
6767
*/
6868
static int fossil_stat(const char *zFilename, struct stat *buf, int isWd){
69
+ int rc;
6970
#if !defined(_WIN32)
71
+ char *zMbcs = fossil_utf8_to_filename(zFilename);
7072
if( isWd && g.allowSymlinks ){
71
- return lstat(zFilename, buf);
73
+ rc = lstat(zMbcs, buf);
7274
}else{
73
- return stat(zFilename, buf);
75
+ rc = stat(zMbcs, buf);
7476
}
7577
#else
76
- int rc = 0;
7778
wchar_t *zMbcs = fossil_utf8_to_filename(zFilename);
7879
rc = _wstati64(zMbcs, buf);
80
+#endif
7981
fossil_filename_free(zMbcs);
8082
return rc;
81
-#endif
8283
}
8384
8485
/*
8586
** Fill in the fileStat variable for the file named zFilename.
8687
** If zFilename==0, then use the previous value of fileStat if
@@ -305,14 +306,15 @@
305306
*/
306307
int file_access(const char *zFilename, int flags){
307308
#ifdef _WIN32
308309
wchar_t *zMbcs = fossil_utf8_to_filename(zFilename);
309310
int rc = _waccess(zMbcs, flags);
310
- fossil_filename_free(zMbcs);
311311
#else
312
- int rc = access(zFilename, flags);
312
+ char *zMbcs = fossil_utf8_to_filename(zFilename);
313
+ int rc = access(zMbcs, flags);
313314
#endif
315
+ fossil_filename_free(zMbcs);
314316
return rc;
315317
}
316318
317319
/*
318320
** Find an unused filename similar to zBase with zSuffix appended.
@@ -402,19 +404,20 @@
402404
#if !defined(_WIN32)
403405
struct timeval tv[2];
404406
memset(tv, 0, sizeof(tv[0])*2);
405407
tv[0].tv_sec = newMTime;
406408
tv[1].tv_sec = newMTime;
407
- utimes(zFilename, tv);
409
+ char *zMbcs = fossil_utf8_to_filename(zFilename);
410
+ utimes(zMbcs, tv);
408411
#else
409412
struct _utimbuf tb;
410413
wchar_t *zMbcs = fossil_utf8_to_filename(zFilename);
411414
tb.actime = newMTime;
412415
tb.modtime = newMTime;
413416
_wutime(zMbcs, &tb);
414
- fossil_filename_free(zMbcs);
415417
#endif
418
+ fossil_filename_free(zMbcs);
416419
}
417420
418421
/*
419422
** COMMAND: test-set-mtime
420423
**
@@ -443,14 +446,15 @@
443446
*/
444447
void file_delete(const char *zFilename){
445448
#ifdef _WIN32
446449
wchar_t *z = fossil_utf8_to_filename(zFilename);
447450
_wunlink(z);
448
- fossil_filename_free(z);
449451
#else
452
+ char *z = fossil_utf8_to_filename(zFilename);
450453
unlink(zFilename);
451454
#endif
455
+ fossil_filename_free(z);
452456
}
453457
454458
/*
455459
** Create the directory named in the argument, if it does not already
456460
** exist. If forceFlag is 1, delete any prior non-directory object
@@ -464,18 +468,18 @@
464468
if( !forceFlag ) return 1;
465469
file_delete(zName);
466470
}
467471
if( rc!=1 ){
468472
#if defined(_WIN32)
469
- int rc;
470473
wchar_t *zMbcs = fossil_utf8_to_filename(zName);
471474
rc = _wmkdir(zMbcs);
475
+#else
476
+ char *zMbcs = fossil_utf8_to_filename(zName);
477
+ rc = mkdir(zName, 0755);
478
+#endif
472479
fossil_filename_free(zMbcs);
473480
return rc;
474
-#else
475
- return mkdir(zName, 0755);
476
-#endif
477481
}
478482
return 0;
479483
}
480484
481485
/*
@@ -580,11 +584,11 @@
580584
}
581585
582586
/*
583587
** Simplify a filename by
584588
**
585
-** * Convert all \ into / on windows
589
+** * Convert all \ into / on windows and cygwin
586590
** * removing any trailing and duplicate /
587591
** * removing /./
588592
** * removing /A/../
589593
**
590594
** Changes are made in-place. Return the new name length.
@@ -705,13 +709,13 @@
705709
** Return true if zPath is an absolute pathname. Return false
706710
** if it is relative.
707711
*/
708712
int file_is_absolute_path(const char *zPath){
709713
if( zPath[0]=='/'
710
-#if defined(_WIN32)
714
+#if defined(_WIN32) || defined(__CYGWIN__)
711715
|| zPath[0]=='\\'
712
- || (strlen(zPath)>3 && zPath[1]==':'
716
+ || (fossil_isalpha(zPath[0]) && zPath[1]==':'
713717
&& (zPath[2]=='\\' || zPath[2]=='/'))
714718
#endif
715719
){
716720
return 1;
717721
}else{
@@ -728,21 +732,21 @@
728732
** If the slash parameter is non-zero, the trailing slash, if any,
729733
** is retained.
730734
*/
731735
void file_canonical_name(const char *zOrigName, Blob *pOut, int slash){
732736
if( file_is_absolute_path(zOrigName) ){
733
-#if defined(_WIN32)
737
+#if defined(_WIN32) || defined(__CYGWIN__)
734738
char *zOut;
735739
#endif
736740
blob_set(pOut, zOrigName);
737741
blob_materialize(pOut);
738
-#if defined(_WIN32)
742
+#if defined(_WIN32) || defined(__CYGWIN__)
739743
/*
740
- ** On Windows, normalize the drive letter to upper case.
744
+ ** On Windows/cygwin, normalize the drive letter to upper case.
741745
*/
742746
zOut = blob_str(pOut);
743
- if( fossil_isalpha(zOut[0]) && zOut[1]==':' ){
747
+ if( fossil_islower(zOut[0]) && zOut[1]==':' ){
744748
zOut[0] = fossil_toupper(zOut[0]);
745749
}
746750
#endif
747751
}else{
748752
char zPwd[2000];
@@ -749,11 +753,11 @@
749753
file_getcwd(zPwd, sizeof(zPwd)-strlen(zOrigName));
750754
#if defined(_WIN32)
751755
/*
752756
** On Windows, normalize the drive letter to upper case.
753757
*/
754
- if( fossil_isalpha(zPwd[0]) && zPwd[1]==':' ){
758
+ if( fossil_islower(zPwd[0]) && zPwd[1]==':' ){
755759
zPwd[0] = fossil_toupper(zPwd[0]);
756760
}
757761
#endif
758762
blob_zero(pOut);
759763
blob_appendf(pOut, "%//%/", zPwd, zOrigName);
@@ -798,12 +802,12 @@
798802
** contain no "/./" or "/../" terms.
799803
*/
800804
int file_is_canonical(const char *z){
801805
int i;
802806
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]!='/')
805809
#endif
806810
) return 0;
807811
808812
for(i=0; z[i]; i++){
809813
if( z[i]=='\\' ) return 0;
@@ -1019,11 +1023,11 @@
10191023
0, /* TEMP */
10201024
0, /* TMP */
10211025
".",
10221026
};
10231027
#else
1024
- static const char *azDirs[] = {
1028
+ static const char *const azDirs[] = {
10251029
"/var/tmp",
10261030
"/usr/tmp",
10271031
"/tmp",
10281032
"/temp",
10291033
".",
10301034
--- src/file.c
+++ src/file.c
@@ -64,23 +64,24 @@
64 ** Fill stat buf with information received from stat() or lstat().
65 ** lstat() is called on Unix if isWd is TRUE and allow-symlinks setting is on.
66 **
67 */
68 static int fossil_stat(const char *zFilename, struct stat *buf, int isWd){
 
69 #if !defined(_WIN32)
 
70 if( isWd && g.allowSymlinks ){
71 return lstat(zFilename, buf);
72 }else{
73 return stat(zFilename, buf);
74 }
75 #else
76 int rc = 0;
77 wchar_t *zMbcs = fossil_utf8_to_filename(zFilename);
78 rc = _wstati64(zMbcs, buf);
 
79 fossil_filename_free(zMbcs);
80 return rc;
81 #endif
82 }
83
84 /*
85 ** Fill in the fileStat variable for the file named zFilename.
86 ** If zFilename==0, then use the previous value of fileStat if
@@ -305,14 +306,15 @@
305 */
306 int file_access(const char *zFilename, int flags){
307 #ifdef _WIN32
308 wchar_t *zMbcs = fossil_utf8_to_filename(zFilename);
309 int rc = _waccess(zMbcs, flags);
310 fossil_filename_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.
@@ -402,19 +404,20 @@
402 #if !defined(_WIN32)
403 struct timeval tv[2];
404 memset(tv, 0, sizeof(tv[0])*2);
405 tv[0].tv_sec = newMTime;
406 tv[1].tv_sec = newMTime;
407 utimes(zFilename, tv);
 
408 #else
409 struct _utimbuf tb;
410 wchar_t *zMbcs = fossil_utf8_to_filename(zFilename);
411 tb.actime = newMTime;
412 tb.modtime = newMTime;
413 _wutime(zMbcs, &tb);
414 fossil_filename_free(zMbcs);
415 #endif
 
416 }
417
418 /*
419 ** COMMAND: test-set-mtime
420 **
@@ -443,14 +446,15 @@
443 */
444 void file_delete(const char *zFilename){
445 #ifdef _WIN32
446 wchar_t *z = fossil_utf8_to_filename(zFilename);
447 _wunlink(z);
448 fossil_filename_free(z);
449 #else
 
450 unlink(zFilename);
451 #endif
 
452 }
453
454 /*
455 ** Create the directory named in the argument, if it does not already
456 ** exist. If forceFlag is 1, delete any prior non-directory object
@@ -464,18 +468,18 @@
464 if( !forceFlag ) return 1;
465 file_delete(zName);
466 }
467 if( rc!=1 ){
468 #if defined(_WIN32)
469 int rc;
470 wchar_t *zMbcs = fossil_utf8_to_filename(zName);
471 rc = _wmkdir(zMbcs);
 
 
 
 
472 fossil_filename_free(zMbcs);
473 return rc;
474 #else
475 return mkdir(zName, 0755);
476 #endif
477 }
478 return 0;
479 }
480
481 /*
@@ -580,11 +584,11 @@
580 }
581
582 /*
583 ** Simplify a filename by
584 **
585 ** * Convert all \ into / on windows
586 ** * removing any trailing and duplicate /
587 ** * removing /./
588 ** * removing /A/../
589 **
590 ** Changes are made in-place. Return the new name length.
@@ -705,13 +709,13 @@
705 ** Return true if zPath is an absolute pathname. Return false
706 ** if it is relative.
707 */
708 int file_is_absolute_path(const char *zPath){
709 if( zPath[0]=='/'
710 #if defined(_WIN32)
711 || zPath[0]=='\\'
712 || (strlen(zPath)>3 && zPath[1]==':'
713 && (zPath[2]=='\\' || zPath[2]=='/'))
714 #endif
715 ){
716 return 1;
717 }else{
@@ -728,21 +732,21 @@
728 ** If the slash parameter is non-zero, the trailing slash, if any,
729 ** is retained.
730 */
731 void file_canonical_name(const char *zOrigName, Blob *pOut, int slash){
732 if( file_is_absolute_path(zOrigName) ){
733 #if defined(_WIN32)
734 char *zOut;
735 #endif
736 blob_set(pOut, zOrigName);
737 blob_materialize(pOut);
738 #if defined(_WIN32)
739 /*
740 ** On Windows, normalize the drive letter to upper case.
741 */
742 zOut = blob_str(pOut);
743 if( fossil_isalpha(zOut[0]) && zOut[1]==':' ){
744 zOut[0] = fossil_toupper(zOut[0]);
745 }
746 #endif
747 }else{
748 char zPwd[2000];
@@ -749,11 +753,11 @@
749 file_getcwd(zPwd, sizeof(zPwd)-strlen(zOrigName));
750 #if defined(_WIN32)
751 /*
752 ** On Windows, normalize the drive letter to upper case.
753 */
754 if( fossil_isalpha(zPwd[0]) && zPwd[1]==':' ){
755 zPwd[0] = fossil_toupper(zPwd[0]);
756 }
757 #endif
758 blob_zero(pOut);
759 blob_appendf(pOut, "%//%/", zPwd, zOrigName);
@@ -798,12 +802,12 @@
798 ** contain no "/./" or "/../" terms.
799 */
800 int file_is_canonical(const char *z){
801 int i;
802 if( z[0]!='/'
803 #if defined(_WIN32)
804 && (z[0]==0 || z[1]!=':' || z[2]!='/')
805 #endif
806 ) return 0;
807
808 for(i=0; z[i]; i++){
809 if( z[i]=='\\' ) return 0;
@@ -1019,11 +1023,11 @@
1019 0, /* TEMP */
1020 0, /* TMP */
1021 ".",
1022 };
1023 #else
1024 static const char *azDirs[] = {
1025 "/var/tmp",
1026 "/usr/tmp",
1027 "/tmp",
1028 "/temp",
1029 ".",
1030
--- src/file.c
+++ src/file.c
@@ -64,23 +64,24 @@
64 ** Fill stat buf with information received from stat() or lstat().
65 ** lstat() is called on Unix if isWd is TRUE and allow-symlinks setting is on.
66 **
67 */
68 static int fossil_stat(const char *zFilename, struct stat *buf, int isWd){
69 int rc;
70 #if !defined(_WIN32)
71 char *zMbcs = fossil_utf8_to_filename(zFilename);
72 if( isWd && g.allowSymlinks ){
73 rc = lstat(zMbcs, buf);
74 }else{
75 rc = stat(zMbcs, buf);
76 }
77 #else
 
78 wchar_t *zMbcs = fossil_utf8_to_filename(zFilename);
79 rc = _wstati64(zMbcs, buf);
80 #endif
81 fossil_filename_free(zMbcs);
82 return rc;
 
83 }
84
85 /*
86 ** Fill in the fileStat variable for the file named zFilename.
87 ** If zFilename==0, then use the previous value of fileStat if
@@ -305,14 +306,15 @@
306 */
307 int file_access(const char *zFilename, int flags){
308 #ifdef _WIN32
309 wchar_t *zMbcs = fossil_utf8_to_filename(zFilename);
310 int rc = _waccess(zMbcs, flags);
 
311 #else
312 char *zMbcs = fossil_utf8_to_filename(zFilename);
313 int rc = access(zMbcs, flags);
314 #endif
315 fossil_filename_free(zMbcs);
316 return rc;
317 }
318
319 /*
320 ** Find an unused filename similar to zBase with zSuffix appended.
@@ -402,19 +404,20 @@
404 #if !defined(_WIN32)
405 struct timeval tv[2];
406 memset(tv, 0, sizeof(tv[0])*2);
407 tv[0].tv_sec = newMTime;
408 tv[1].tv_sec = newMTime;
409 char *zMbcs = fossil_utf8_to_filename(zFilename);
410 utimes(zMbcs, tv);
411 #else
412 struct _utimbuf tb;
413 wchar_t *zMbcs = fossil_utf8_to_filename(zFilename);
414 tb.actime = newMTime;
415 tb.modtime = newMTime;
416 _wutime(zMbcs, &tb);
 
417 #endif
418 fossil_filename_free(zMbcs);
419 }
420
421 /*
422 ** COMMAND: test-set-mtime
423 **
@@ -443,14 +446,15 @@
446 */
447 void file_delete(const char *zFilename){
448 #ifdef _WIN32
449 wchar_t *z = fossil_utf8_to_filename(zFilename);
450 _wunlink(z);
 
451 #else
452 char *z = fossil_utf8_to_filename(zFilename);
453 unlink(zFilename);
454 #endif
455 fossil_filename_free(z);
456 }
457
458 /*
459 ** Create the directory named in the argument, if it does not already
460 ** exist. If forceFlag is 1, delete any prior non-directory object
@@ -464,18 +468,18 @@
468 if( !forceFlag ) return 1;
469 file_delete(zName);
470 }
471 if( rc!=1 ){
472 #if defined(_WIN32)
 
473 wchar_t *zMbcs = fossil_utf8_to_filename(zName);
474 rc = _wmkdir(zMbcs);
475 #else
476 char *zMbcs = fossil_utf8_to_filename(zName);
477 rc = mkdir(zName, 0755);
478 #endif
479 fossil_filename_free(zMbcs);
480 return rc;
 
 
 
481 }
482 return 0;
483 }
484
485 /*
@@ -580,11 +584,11 @@
584 }
585
586 /*
587 ** Simplify a filename by
588 **
589 ** * Convert all \ into / on windows and cygwin
590 ** * removing any trailing and duplicate /
591 ** * removing /./
592 ** * removing /A/../
593 **
594 ** Changes are made in-place. Return the new name length.
@@ -705,13 +709,13 @@
709 ** Return true if zPath is an absolute pathname. Return false
710 ** if it is relative.
711 */
712 int file_is_absolute_path(const char *zPath){
713 if( zPath[0]=='/'
714 #if defined(_WIN32) || defined(__CYGWIN__)
715 || zPath[0]=='\\'
716 || (fossil_isalpha(zPath[0]) && zPath[1]==':'
717 && (zPath[2]=='\\' || zPath[2]=='/'))
718 #endif
719 ){
720 return 1;
721 }else{
@@ -728,21 +732,21 @@
732 ** If the slash parameter is non-zero, the trailing slash, if any,
733 ** is retained.
734 */
735 void file_canonical_name(const char *zOrigName, Blob *pOut, int slash){
736 if( file_is_absolute_path(zOrigName) ){
737 #if defined(_WIN32) || defined(__CYGWIN__)
738 char *zOut;
739 #endif
740 blob_set(pOut, zOrigName);
741 blob_materialize(pOut);
742 #if defined(_WIN32) || defined(__CYGWIN__)
743 /*
744 ** On Windows/cygwin, normalize the drive letter to upper case.
745 */
746 zOut = blob_str(pOut);
747 if( fossil_islower(zOut[0]) && zOut[1]==':' ){
748 zOut[0] = fossil_toupper(zOut[0]);
749 }
750 #endif
751 }else{
752 char zPwd[2000];
@@ -749,11 +753,11 @@
753 file_getcwd(zPwd, sizeof(zPwd)-strlen(zOrigName));
754 #if defined(_WIN32)
755 /*
756 ** On Windows, normalize the drive letter to upper case.
757 */
758 if( fossil_islower(zPwd[0]) && zPwd[1]==':' ){
759 zPwd[0] = fossil_toupper(zPwd[0]);
760 }
761 #endif
762 blob_zero(pOut);
763 blob_appendf(pOut, "%//%/", zPwd, zOrigName);
@@ -798,12 +802,12 @@
802 ** contain no "/./" or "/../" terms.
803 */
804 int file_is_canonical(const char *z){
805 int i;
806 if( z[0]!='/'
807 #if defined(_WIN32) || defined(__CYGWIN__)
808 && (!fossil_isupper(z[0]) || z[1]!=':' || z[2]!='/')
809 #endif
810 ) return 0;
811
812 for(i=0; z[i]; i++){
813 if( z[i]=='\\' ) return 0;
@@ -1019,11 +1023,11 @@
1023 0, /* TEMP */
1024 0, /* TMP */
1025 ".",
1026 };
1027 #else
1028 static const char *const azDirs[] = {
1029 "/var/tmp",
1030 "/usr/tmp",
1031 "/tmp",
1032 "/temp",
1033 ".",
1034
+24 -1
--- src/utf8.c
+++ src/utf8.c
@@ -118,10 +118,14 @@
118118
if( zUtf==0 ){
119119
return 0;
120120
}
121121
WideCharToMultiByte(CP_UTF8, 0, zFilename, -1, zUtf, nByte, 0, 0);
122122
return zUtf;
123
+#elif defined(__CYGWIN__)
124
+ char *zOut;
125
+ zOut = fossil_strdup(zFilename);
126
+ return zOut;
123127
#elif defined(__APPLE__) && !defined(WITHOUT_ICONV)
124128
char *zIn = (char*)zFilename;
125129
char *zOut;
126130
iconv_t cd;
127131
size_t n, x;
@@ -170,10 +174,29 @@
170174
*wUnicode = '\\';
171175
}
172176
++wUnicode;
173177
}
174178
return zUnicode;
179
+#elif defined(__CYGWIN__)
180
+ char *zPath, *p;
181
+ if( fossil_isalpha(zUtf8[0]) && (zUtf8[1]==':')
182
+ && (zUtf8[2]=='\\' || zUtf8[2]=='/')) {
183
+ int n = strlen(zUtf8);
184
+ zPath = fossil_malloc( n+10 );
185
+ memcpy(zPath, "/cygdrive/", 10);
186
+ zPath[10] = zUtf8[0];
187
+ memcpy(zPath+11, zUtf8+2, n-1);
188
+ } else {
189
+ zPath = fossil_strdup(zUtf8);
190
+ }
191
+ zUtf8 = p = zPath;
192
+ while( (*p = *zUtf8++) != 0){
193
+ if (*p++ == '\\' ) {
194
+ p[-1] = '/';
195
+ }
196
+ }
197
+ return zPath;
175198
#elif defined(__APPLE__) && !defined(WITHOUT_ICONV)
176199
return fossil_strdup(zUtf8);
177200
#else
178201
return (void *)zUtf8; /* No-op on unix */
179202
#endif
@@ -184,11 +207,11 @@
184207
** fossil_filename_to_utf8() or fossil_utf8_to_filename().
185208
*/
186209
void fossil_filename_free(void *pOld){
187210
#if defined(_WIN32)
188211
sqlite3_free(pOld);
189
-#elif defined(__APPLE__) && !defined(WITHOUT_ICONV)
212
+#elif (defined(__APPLE__) && !defined(WITHOUT_ICONV)) || defined(__CYGWIN__)
190213
fossil_free(pOld);
191214
#else
192215
/* No-op on all other unix */
193216
#endif
194217
}
195218
--- src/utf8.c
+++ src/utf8.c
@@ -118,10 +118,14 @@
118 if( zUtf==0 ){
119 return 0;
120 }
121 WideCharToMultiByte(CP_UTF8, 0, zFilename, -1, zUtf, nByte, 0, 0);
122 return zUtf;
 
 
 
 
123 #elif defined(__APPLE__) && !defined(WITHOUT_ICONV)
124 char *zIn = (char*)zFilename;
125 char *zOut;
126 iconv_t cd;
127 size_t n, x;
@@ -170,10 +174,29 @@
170 *wUnicode = '\\';
171 }
172 ++wUnicode;
173 }
174 return zUnicode;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175 #elif defined(__APPLE__) && !defined(WITHOUT_ICONV)
176 return fossil_strdup(zUtf8);
177 #else
178 return (void *)zUtf8; /* No-op on unix */
179 #endif
@@ -184,11 +207,11 @@
184 ** fossil_filename_to_utf8() or fossil_utf8_to_filename().
185 */
186 void fossil_filename_free(void *pOld){
187 #if defined(_WIN32)
188 sqlite3_free(pOld);
189 #elif defined(__APPLE__) && !defined(WITHOUT_ICONV)
190 fossil_free(pOld);
191 #else
192 /* No-op on all other unix */
193 #endif
194 }
195
--- src/utf8.c
+++ src/utf8.c
@@ -118,10 +118,14 @@
118 if( zUtf==0 ){
119 return 0;
120 }
121 WideCharToMultiByte(CP_UTF8, 0, zFilename, -1, zUtf, nByte, 0, 0);
122 return zUtf;
123 #elif defined(__CYGWIN__)
124 char *zOut;
125 zOut = fossil_strdup(zFilename);
126 return zOut;
127 #elif defined(__APPLE__) && !defined(WITHOUT_ICONV)
128 char *zIn = (char*)zFilename;
129 char *zOut;
130 iconv_t cd;
131 size_t n, x;
@@ -170,10 +174,29 @@
174 *wUnicode = '\\';
175 }
176 ++wUnicode;
177 }
178 return zUnicode;
179 #elif defined(__CYGWIN__)
180 char *zPath, *p;
181 if( fossil_isalpha(zUtf8[0]) && (zUtf8[1]==':')
182 && (zUtf8[2]=='\\' || zUtf8[2]=='/')) {
183 int n = strlen(zUtf8);
184 zPath = fossil_malloc( n+10 );
185 memcpy(zPath, "/cygdrive/", 10);
186 zPath[10] = zUtf8[0];
187 memcpy(zPath+11, zUtf8+2, n-1);
188 } else {
189 zPath = fossil_strdup(zUtf8);
190 }
191 zUtf8 = p = zPath;
192 while( (*p = *zUtf8++) != 0){
193 if (*p++ == '\\' ) {
194 p[-1] = '/';
195 }
196 }
197 return zPath;
198 #elif defined(__APPLE__) && !defined(WITHOUT_ICONV)
199 return fossil_strdup(zUtf8);
200 #else
201 return (void *)zUtf8; /* No-op on unix */
202 #endif
@@ -184,11 +207,11 @@
207 ** fossil_filename_to_utf8() or fossil_utf8_to_filename().
208 */
209 void fossil_filename_free(void *pOld){
210 #if defined(_WIN32)
211 sqlite3_free(pOld);
212 #elif (defined(__APPLE__) && !defined(WITHOUT_ICONV)) || defined(__CYGWIN__)
213 fossil_free(pOld);
214 #else
215 /* No-op on all other unix */
216 #endif
217 }
218

Keyboard Shortcuts

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