| | @@ -981,15 +981,15 @@ |
| 981 | 981 | ** operations which hold an exclusive transaction. In a few cases, though, |
| 982 | 982 | ** it is convenient for the ~/.fossil to be attached to the main database |
| 983 | 983 | ** connection so that we can join between the various databases. In that |
| 984 | 984 | ** case, invoke this routine with useAttach as 1. |
| 985 | 985 | */ |
| 986 | | -void db_open_config(int useAttach){ |
| 986 | +int db_open_config(int useAttach, int isOptional){ |
| 987 | 987 | char *zDbName; |
| 988 | 988 | char *zHome; |
| 989 | 989 | if( g.zConfigDbName ){ |
| 990 | | - if( useAttach==g.useAttach ) return; |
| 990 | + if( useAttach==g.useAttach ) return 1; /* Already open. */ |
| 991 | 991 | db_close_config(); |
| 992 | 992 | } |
| 993 | 993 | zHome = fossil_getenv("FOSSIL_HOME"); |
| 994 | 994 | #if defined(_WIN32) || defined(__CYGWIN__) |
| 995 | 995 | if( zHome==0 ){ |
| | @@ -1002,24 +1002,27 @@ |
| 1002 | 1002 | if( zDrive && zPath ) zHome = mprintf("%s%s", zDrive, zPath); |
| 1003 | 1003 | } |
| 1004 | 1004 | } |
| 1005 | 1005 | } |
| 1006 | 1006 | if( zHome==0 ){ |
| 1007 | + if( isOptional ) return 0; |
| 1007 | 1008 | fossil_fatal("cannot locate home directory - please set the " |
| 1008 | 1009 | "FOSSIL_HOME, LOCALAPPDATA, APPDATA, or HOMEPATH " |
| 1009 | 1010 | "environment variables"); |
| 1010 | 1011 | } |
| 1011 | 1012 | #else |
| 1012 | 1013 | if( zHome==0 ){ |
| 1013 | 1014 | zHome = fossil_getenv("HOME"); |
| 1014 | 1015 | } |
| 1015 | 1016 | if( zHome==0 ){ |
| 1017 | + if( isOptional ) return 0; |
| 1016 | 1018 | fossil_fatal("cannot locate home directory - please set the " |
| 1017 | 1019 | "FOSSIL_HOME or HOME environment variables"); |
| 1018 | 1020 | } |
| 1019 | 1021 | #endif |
| 1020 | 1022 | if( file_isdir(zHome)!=1 ){ |
| 1023 | + if( isOptional ) return 0; |
| 1021 | 1024 | fossil_fatal("invalid home directory: %s", zHome); |
| 1022 | 1025 | } |
| 1023 | 1026 | #if defined(_WIN32) || defined(__CYGWIN__) |
| 1024 | 1027 | /* . filenames give some window systems problems and many apps problems */ |
| 1025 | 1028 | zDbName = mprintf("%//_fossil", zHome); |
| | @@ -1026,15 +1029,17 @@ |
| 1026 | 1029 | #else |
| 1027 | 1030 | zDbName = mprintf("%s/.fossil", zHome); |
| 1028 | 1031 | #endif |
| 1029 | 1032 | if( file_size(zDbName)<1024*3 ){ |
| 1030 | 1033 | if( file_access(zHome, W_OK) ){ |
| 1034 | + if( isOptional ) return 0; |
| 1031 | 1035 | fossil_fatal("home directory %s must be writeable", zHome); |
| 1032 | 1036 | } |
| 1033 | 1037 | db_init_database(zDbName, zConfigSchema, (char*)0); |
| 1034 | 1038 | } |
| 1035 | 1039 | if( file_access(zDbName, W_OK) ){ |
| 1040 | + if( isOptional ) return 0; |
| 1036 | 1041 | fossil_fatal("configuration file %s must be writeable", zDbName); |
| 1037 | 1042 | } |
| 1038 | 1043 | if( useAttach ){ |
| 1039 | 1044 | db_open_or_attach(zDbName, "configdb", &g.useAttach); |
| 1040 | 1045 | g.dbConfig = 0; |
| | @@ -1043,10 +1048,11 @@ |
| 1043 | 1048 | g.useAttach = 0; |
| 1044 | 1049 | g.dbConfig = db_open(zDbName); |
| 1045 | 1050 | g.zConfigDbType = "configdb"; |
| 1046 | 1051 | } |
| 1047 | 1052 | g.zConfigDbName = zDbName; |
| 1053 | + return 1; |
| 1048 | 1054 | } |
| 1049 | 1055 | |
| 1050 | 1056 | /* |
| 1051 | 1057 | ** Return TRUE if zTable exists. |
| 1052 | 1058 | */ |
| | @@ -1156,20 +1162,22 @@ |
| 1156 | 1162 | n = strlen(zPwd); |
| 1157 | 1163 | while( n>0 ){ |
| 1158 | 1164 | for(i=0; i<count(aDbName); i++){ |
| 1159 | 1165 | sqlite3_snprintf(sizeof(zPwd)-n, &zPwd[n], "/%s", aDbName[i]); |
| 1160 | 1166 | if( isValidLocalDb(zPwd) ){ |
| 1167 | + if( db_open_config(0, 1)==0 ){ |
| 1168 | + return 0; /* Configuration could not be opened */ |
| 1169 | + } |
| 1161 | 1170 | /* Found a valid checkout database file */ |
| 1162 | 1171 | g.zLocalDbName = mprintf("%s", zPwd); |
| 1163 | 1172 | zPwd[n] = 0; |
| 1164 | 1173 | while( n>0 && zPwd[n-1]=='/' ){ |
| 1165 | 1174 | n--; |
| 1166 | 1175 | zPwd[n] = 0; |
| 1167 | 1176 | } |
| 1168 | 1177 | g.zLocalRoot = mprintf("%s/", zPwd); |
| 1169 | 1178 | g.localOpen = 1; |
| 1170 | | - db_open_config(0); |
| 1171 | 1179 | db_open_repository(zDbName); |
| 1172 | 1180 | return 1; |
| 1173 | 1181 | } |
| 1174 | 1182 | } |
| 1175 | 1183 | n--; |
| | @@ -1730,11 +1738,11 @@ |
| 1730 | 1738 | fossil_fatal("file already exists: %s", g.argv[2]); |
| 1731 | 1739 | } |
| 1732 | 1740 | |
| 1733 | 1741 | db_create_repository(g.argv[2]); |
| 1734 | 1742 | db_open_repository(g.argv[2]); |
| 1735 | | - db_open_config(0); |
| 1743 | + db_open_config(0, 0); |
| 1736 | 1744 | if( zTemplate ) db_attach(zTemplate, "settingSrc"); |
| 1737 | 1745 | db_begin_transaction(); |
| 1738 | 1746 | if( zDate==0 ) zDate = "now"; |
| 1739 | 1747 | db_initial_setup(zTemplate, zDate, zDefaultUser); |
| 1740 | 1748 | db_end_transaction(0); |
| | @@ -2823,11 +2831,11 @@ |
| 2823 | 2831 | */ |
| 2824 | 2832 | void setting_cmd(void){ |
| 2825 | 2833 | int i; |
| 2826 | 2834 | int globalFlag = find_option("global","g",0)!=0; |
| 2827 | 2835 | int unsetFlag = g.argv[1][0]=='u'; |
| 2828 | | - db_open_config(1); |
| 2836 | + db_open_config(1, 0); |
| 2829 | 2837 | if( !globalFlag ){ |
| 2830 | 2838 | db_find_and_open_repository(OPEN_ANY_SCHEMA | OPEN_OK_NOT_FOUND, 0); |
| 2831 | 2839 | } |
| 2832 | 2840 | if( !g.repositoryOpen ){ |
| 2833 | 2841 | globalFlag = 1; |
| 2834 | 2842 | |