Fossil SCM
Better error messages when "sync" fails due to server problems. Ticket [bfb8427cdd5]
Commit
0690aa18a4aa3dfb6f055d486d278590f715a2cc
Parent
e2431b17df0b386…
2 files changed
+10
-2
+25
-20
+10
-2
| --- src/http.c | ||
| +++ src/http.c | ||
| @@ -180,11 +180,16 @@ | ||
| 180 | 180 | closeConnection = 1; |
| 181 | 181 | iLength = -1; |
| 182 | 182 | while( (zLine = transport_receive_line())!=0 && zLine[0]!=0 ){ |
| 183 | 183 | if( strncasecmp(zLine, "http/1.", 7)==0 ){ |
| 184 | 184 | if( sscanf(zLine, "HTTP/1.%d %d", &iHttpVersion, &rc)!=2 ) goto write_err; |
| 185 | - if( rc!=200 ) goto write_err; | |
| 185 | + if( rc!=200 ){ | |
| 186 | + int ii; | |
| 187 | + for(ii=7; zLine[ii] && zLine[ii]!=' '; ii++){} | |
| 188 | + printf("ERROR. server says: %s\n", &zLine[ii]); | |
| 189 | + goto write_err; | |
| 190 | + } | |
| 186 | 191 | if( iHttpVersion==0 ){ |
| 187 | 192 | closeConnection = 1; |
| 188 | 193 | }else{ |
| 189 | 194 | closeConnection = 0; |
| 190 | 195 | } |
| @@ -204,11 +209,14 @@ | ||
| 204 | 209 | } |
| 205 | 210 | |
| 206 | 211 | /* |
| 207 | 212 | ** Extract the reply payload that follows the header |
| 208 | 213 | */ |
| 209 | - if( iLength<0 ) goto write_err; | |
| 214 | + if( iLength<0 ){ | |
| 215 | + printf("ERROR. Server did not reply\n"); | |
| 216 | + goto write_err; | |
| 217 | + } | |
| 210 | 218 | blob_zero(pReply); |
| 211 | 219 | blob_resize(pReply, iLength); |
| 212 | 220 | iLength = transport_receive(blob_buffer(pReply), iLength); |
| 213 | 221 | blob_resize(pReply, iLength); |
| 214 | 222 | if( g.fHttpTrace ){ |
| 215 | 223 |
| --- src/http.c | |
| +++ src/http.c | |
| @@ -180,11 +180,16 @@ | |
| 180 | closeConnection = 1; |
| 181 | iLength = -1; |
| 182 | while( (zLine = transport_receive_line())!=0 && zLine[0]!=0 ){ |
| 183 | if( strncasecmp(zLine, "http/1.", 7)==0 ){ |
| 184 | if( sscanf(zLine, "HTTP/1.%d %d", &iHttpVersion, &rc)!=2 ) goto write_err; |
| 185 | if( rc!=200 ) goto write_err; |
| 186 | if( iHttpVersion==0 ){ |
| 187 | closeConnection = 1; |
| 188 | }else{ |
| 189 | closeConnection = 0; |
| 190 | } |
| @@ -204,11 +209,14 @@ | |
| 204 | } |
| 205 | |
| 206 | /* |
| 207 | ** Extract the reply payload that follows the header |
| 208 | */ |
| 209 | if( iLength<0 ) goto write_err; |
| 210 | blob_zero(pReply); |
| 211 | blob_resize(pReply, iLength); |
| 212 | iLength = transport_receive(blob_buffer(pReply), iLength); |
| 213 | blob_resize(pReply, iLength); |
| 214 | if( g.fHttpTrace ){ |
| 215 |
| --- src/http.c | |
| +++ src/http.c | |
| @@ -180,11 +180,16 @@ | |
| 180 | closeConnection = 1; |
| 181 | iLength = -1; |
| 182 | while( (zLine = transport_receive_line())!=0 && zLine[0]!=0 ){ |
| 183 | if( strncasecmp(zLine, "http/1.", 7)==0 ){ |
| 184 | if( sscanf(zLine, "HTTP/1.%d %d", &iHttpVersion, &rc)!=2 ) goto write_err; |
| 185 | if( rc!=200 ){ |
| 186 | int ii; |
| 187 | for(ii=7; zLine[ii] && zLine[ii]!=' '; ii++){} |
| 188 | printf("ERROR. server says: %s\n", &zLine[ii]); |
| 189 | goto write_err; |
| 190 | } |
| 191 | if( iHttpVersion==0 ){ |
| 192 | closeConnection = 1; |
| 193 | }else{ |
| 194 | closeConnection = 0; |
| 195 | } |
| @@ -204,11 +209,14 @@ | |
| 209 | } |
| 210 | |
| 211 | /* |
| 212 | ** Extract the reply payload that follows the header |
| 213 | */ |
| 214 | if( iLength<0 ){ |
| 215 | printf("ERROR. Server did not reply\n"); |
| 216 | goto write_err; |
| 217 | } |
| 218 | blob_zero(pReply); |
| 219 | blob_resize(pReply, iLength); |
| 220 | iLength = transport_receive(blob_buffer(pReply), iLength); |
| 221 | blob_resize(pReply, iLength); |
| 222 | if( g.fHttpTrace ){ |
| 223 |
+25
-20
| --- src/xfer.c | ||
| +++ src/xfer.c | ||
| @@ -922,11 +922,12 @@ | ||
| 922 | 922 | int cloneFlag, /* True if this is a clone */ |
| 923 | 923 | int configRcvMask, /* Receive these configuration items */ |
| 924 | 924 | int configSendMask /* Send these configuration items */ |
| 925 | 925 | ){ |
| 926 | 926 | int go = 1; /* Loop until zero */ |
| 927 | - int nCard = 0; /* Number of cards sent or received */ | |
| 927 | + int nCardSent = 0; /* Number of cards sent */ | |
| 928 | + int nCardRcvd = 0; /* Number of cards received */ | |
| 928 | 929 | int nCycle = 0; /* Number of round trips to the server */ |
| 929 | 930 | int size; /* Size of a config value */ |
| 930 | 931 | int nFileSend = 0; |
| 931 | 932 | int origConfigRcvMask; /* Original value of configRcvMask */ |
| 932 | 933 | int nFileRecv; /* Number of files received */ |
| @@ -968,19 +969,19 @@ | ||
| 968 | 969 | */ |
| 969 | 970 | if( cloneFlag ){ |
| 970 | 971 | blob_appendf(&send, "clone\n"); |
| 971 | 972 | pushFlag = 0; |
| 972 | 973 | pullFlag = 0; |
| 973 | - nCard++; | |
| 974 | + nCardSent++; | |
| 974 | 975 | /* TBD: Request all transferable configuration values */ |
| 975 | 976 | }else if( pullFlag ){ |
| 976 | 977 | blob_appendf(&send, "pull %s %s\n", zSCode, zPCode); |
| 977 | - nCard++; | |
| 978 | + nCardSent++; | |
| 978 | 979 | } |
| 979 | 980 | if( pushFlag ){ |
| 980 | 981 | blob_appendf(&send, "push %s %s\n", zSCode, zPCode); |
| 981 | - nCard++; | |
| 982 | + nCardSent++; | |
| 982 | 983 | } |
| 983 | 984 | manifest_crosslink_begin(); |
| 984 | 985 | printf(zLabelFormat, "", "Bytes", "Cards", "Artifacts", "Deltas"); |
| 985 | 986 | |
| 986 | 987 | while( go ){ |
| @@ -1001,21 +1002,21 @@ | ||
| 1001 | 1002 | if( pullFlag || cloneFlag ){ |
| 1002 | 1003 | request_phantoms(&xfer, mxPhantomReq); |
| 1003 | 1004 | } |
| 1004 | 1005 | if( pushFlag ){ |
| 1005 | 1006 | send_unsent(&xfer); |
| 1006 | - nCard += send_unclustered(&xfer); | |
| 1007 | + nCardSent += send_unclustered(&xfer); | |
| 1007 | 1008 | } |
| 1008 | 1009 | |
| 1009 | 1010 | /* Send configuration parameter requests */ |
| 1010 | 1011 | if( configRcvMask ){ |
| 1011 | 1012 | const char *zName; |
| 1012 | 1013 | zName = configure_first_name(configRcvMask); |
| 1013 | 1014 | while( zName ){ |
| 1014 | 1015 | blob_appendf(&send, "reqconfig %s\n", zName); |
| 1015 | 1016 | zName = configure_next_name(configRcvMask); |
| 1016 | - nCard++; | |
| 1017 | + nCardSent++; | |
| 1017 | 1018 | } |
| 1018 | 1019 | if( configRcvMask & (CONFIGSET_USER|CONFIGSET_TKT) ){ |
| 1019 | 1020 | configure_prepare_to_receive(0); |
| 1020 | 1021 | } |
| 1021 | 1022 | configRcvMask = 0; |
| @@ -1026,11 +1027,11 @@ | ||
| 1026 | 1027 | const char *zName; |
| 1027 | 1028 | zName = configure_first_name(configSendMask); |
| 1028 | 1029 | while( zName ){ |
| 1029 | 1030 | send_config_card(&xfer, zName); |
| 1030 | 1031 | zName = configure_next_name(configSendMask); |
| 1031 | - nCard++; | |
| 1032 | + nCardSent++; | |
| 1032 | 1033 | } |
| 1033 | 1034 | configSendMask = 0; |
| 1034 | 1035 | } |
| 1035 | 1036 | |
| 1036 | 1037 | /* Append randomness to the end of the message */ |
| @@ -1039,13 +1040,14 @@ | ||
| 1039 | 1040 | free(zRandomness); |
| 1040 | 1041 | |
| 1041 | 1042 | /* Exchange messages with the server */ |
| 1042 | 1043 | nFileSend = xfer.nFileSent + xfer.nDeltaSent; |
| 1043 | 1044 | printf(zValueFormat, "Send:", |
| 1044 | - blob_size(&send), nCard+xfer.nGimmeSent+xfer.nIGotSent, | |
| 1045 | + blob_size(&send), nCardSent+xfer.nGimmeSent+xfer.nIGotSent, | |
| 1045 | 1046 | xfer.nFileSent, xfer.nDeltaSent); |
| 1046 | - nCard = 0; | |
| 1047 | + nCardSent = 0; | |
| 1048 | + nCardRcvd = 0; | |
| 1047 | 1049 | xfer.nFileSent = 0; |
| 1048 | 1050 | xfer.nDeltaSent = 0; |
| 1049 | 1051 | xfer.nGimmeSent = 0; |
| 1050 | 1052 | fflush(stdout); |
| 1051 | 1053 | http_exchange(&send, &recv); |
| @@ -1054,25 +1056,25 @@ | ||
| 1054 | 1056 | /* Begin constructing the next message (which might never be |
| 1055 | 1057 | ** sent) by beginning with the pull or push cards |
| 1056 | 1058 | */ |
| 1057 | 1059 | if( pullFlag ){ |
| 1058 | 1060 | blob_appendf(&send, "pull %s %s\n", zSCode, zPCode); |
| 1059 | - nCard++; | |
| 1061 | + nCardSent++; | |
| 1060 | 1062 | } |
| 1061 | 1063 | if( pushFlag ){ |
| 1062 | 1064 | blob_appendf(&send, "push %s %s\n", zSCode, zPCode); |
| 1063 | - nCard++; | |
| 1065 | + nCardSent++; | |
| 1064 | 1066 | } |
| 1065 | 1067 | |
| 1066 | 1068 | /* Process the reply that came back from the server */ |
| 1067 | 1069 | while( blob_line(&recv, &xfer.line) ){ |
| 1068 | 1070 | if( blob_buffer(&xfer.line)[0]=='#' ){ |
| 1069 | 1071 | continue; |
| 1070 | 1072 | } |
| 1071 | 1073 | xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken, count(xfer.aToken)); |
| 1072 | - nCard++; | |
| 1073 | - printf("\r%d", nCard); | |
| 1074 | + nCardRcvd++; | |
| 1075 | + printf("\r%d", nCardRcvd); | |
| 1074 | 1076 | fflush(stdout); |
| 1075 | 1077 | |
| 1076 | 1078 | /* file UUID SIZE \n CONTENT |
| 1077 | 1079 | ** file UUID DELTASRC SIZE \n CONTENT |
| 1078 | 1080 | ** |
| @@ -1138,11 +1140,11 @@ | ||
| 1138 | 1140 | if( zPCode==0 ){ |
| 1139 | 1141 | zPCode = mprintf("%b", &xfer.aToken[2]); |
| 1140 | 1142 | db_set("project-code", zPCode, 0); |
| 1141 | 1143 | } |
| 1142 | 1144 | blob_appendf(&send, "clone\n"); |
| 1143 | - nCard++; | |
| 1145 | + nCardSent++; | |
| 1144 | 1146 | }else |
| 1145 | 1147 | |
| 1146 | 1148 | /* config NAME SIZE \n CONTENT |
| 1147 | 1149 | ** |
| 1148 | 1150 | ** Receive a configuration value from the server. |
| @@ -1178,11 +1180,11 @@ | ||
| 1178 | 1180 | ** presumably the operator trusts the server. |
| 1179 | 1181 | */ |
| 1180 | 1182 | db_multi_exec("%s", blob_str(&content)); |
| 1181 | 1183 | } |
| 1182 | 1184 | } |
| 1183 | - nCard++; | |
| 1185 | + nCardSent++; | |
| 1184 | 1186 | blob_reset(&content); |
| 1185 | 1187 | blob_seek(xfer.pIn, 1, BLOB_SEEK_CUR); |
| 1186 | 1188 | }else |
| 1187 | 1189 | |
| 1188 | 1190 | |
| @@ -1204,11 +1206,11 @@ | ||
| 1204 | 1206 | ** Print a message. Similar to "error" but does not stop processing |
| 1205 | 1207 | */ |
| 1206 | 1208 | if( blob_eq(&xfer.aToken[0],"message") && xfer.nToken==2 ){ |
| 1207 | 1209 | char *zMsg = blob_terminate(&xfer.aToken[1]); |
| 1208 | 1210 | defossilize(zMsg); |
| 1209 | - printf("Server says: %s\n", zMsg); | |
| 1211 | + printf("\rServer says: %s\n", zMsg); | |
| 1210 | 1212 | }else |
| 1211 | 1213 | |
| 1212 | 1214 | /* error MESSAGE |
| 1213 | 1215 | ** |
| 1214 | 1216 | ** Report an error and abandon the sync session |
| @@ -1215,10 +1217,11 @@ | ||
| 1215 | 1217 | */ |
| 1216 | 1218 | if( blob_eq(&xfer.aToken[0],"error") && xfer.nToken==2 ){ |
| 1217 | 1219 | char *zMsg = blob_terminate(&xfer.aToken[1]); |
| 1218 | 1220 | defossilize(zMsg); |
| 1219 | 1221 | blob_appendf(&xfer.err, "server says: %s", zMsg); |
| 1222 | + printf("Server Error: %s\n", zMsg); | |
| 1220 | 1223 | }else |
| 1221 | 1224 | |
| 1222 | 1225 | /* Unknown message */ |
| 1223 | 1226 | { |
| 1224 | 1227 | if( blob_str(&xfer.aToken[0])[0]=='<' ){ |
| @@ -1238,13 +1241,15 @@ | ||
| 1238 | 1241 | } |
| 1239 | 1242 | if( origConfigRcvMask & (CONFIGSET_TKT|CONFIGSET_USER) ){ |
| 1240 | 1243 | configure_finalize_receive(); |
| 1241 | 1244 | } |
| 1242 | 1245 | origConfigRcvMask = 0; |
| 1243 | - printf(zValueFormat, "Received:", | |
| 1244 | - blob_size(&recv), nCard, | |
| 1245 | - xfer.nFileRcvd, xfer.nDeltaRcvd + xfer.nDanglingFile); | |
| 1246 | + if( nCardRcvd>0 ){ | |
| 1247 | + printf(zValueFormat, "Received:", | |
| 1248 | + blob_size(&recv), nCardRcvd, | |
| 1249 | + xfer.nFileRcvd, xfer.nDeltaRcvd + xfer.nDanglingFile); | |
| 1250 | + } | |
| 1246 | 1251 | blob_reset(&recv); |
| 1247 | 1252 | nCycle++; |
| 1248 | 1253 | go = 0; |
| 1249 | 1254 | |
| 1250 | 1255 | /* If we received one or more files on the previous exchange but |
| @@ -1254,11 +1259,11 @@ | ||
| 1254 | 1259 | if( (nFileRecv>0 || newPhantom) && db_exists("SELECT 1 FROM phantom") ){ |
| 1255 | 1260 | go = 1; |
| 1256 | 1261 | mxPhantomReq = nFileRecv*2; |
| 1257 | 1262 | if( mxPhantomReq<200 ) mxPhantomReq = 200; |
| 1258 | 1263 | } |
| 1259 | - nCard = 0; | |
| 1264 | + nCardRcvd = 0; | |
| 1260 | 1265 | xfer.nFileRcvd = 0; |
| 1261 | 1266 | xfer.nDeltaRcvd = 0; |
| 1262 | 1267 | xfer.nDanglingFile = 0; |
| 1263 | 1268 | |
| 1264 | 1269 | /* If we have one or more files queued to send, then go |
| 1265 | 1270 |
| --- src/xfer.c | |
| +++ src/xfer.c | |
| @@ -922,11 +922,12 @@ | |
| 922 | int cloneFlag, /* True if this is a clone */ |
| 923 | int configRcvMask, /* Receive these configuration items */ |
| 924 | int configSendMask /* Send these configuration items */ |
| 925 | ){ |
| 926 | int go = 1; /* Loop until zero */ |
| 927 | int nCard = 0; /* Number of cards sent or received */ |
| 928 | int nCycle = 0; /* Number of round trips to the server */ |
| 929 | int size; /* Size of a config value */ |
| 930 | int nFileSend = 0; |
| 931 | int origConfigRcvMask; /* Original value of configRcvMask */ |
| 932 | int nFileRecv; /* Number of files received */ |
| @@ -968,19 +969,19 @@ | |
| 968 | */ |
| 969 | if( cloneFlag ){ |
| 970 | blob_appendf(&send, "clone\n"); |
| 971 | pushFlag = 0; |
| 972 | pullFlag = 0; |
| 973 | nCard++; |
| 974 | /* TBD: Request all transferable configuration values */ |
| 975 | }else if( pullFlag ){ |
| 976 | blob_appendf(&send, "pull %s %s\n", zSCode, zPCode); |
| 977 | nCard++; |
| 978 | } |
| 979 | if( pushFlag ){ |
| 980 | blob_appendf(&send, "push %s %s\n", zSCode, zPCode); |
| 981 | nCard++; |
| 982 | } |
| 983 | manifest_crosslink_begin(); |
| 984 | printf(zLabelFormat, "", "Bytes", "Cards", "Artifacts", "Deltas"); |
| 985 | |
| 986 | while( go ){ |
| @@ -1001,21 +1002,21 @@ | |
| 1001 | if( pullFlag || cloneFlag ){ |
| 1002 | request_phantoms(&xfer, mxPhantomReq); |
| 1003 | } |
| 1004 | if( pushFlag ){ |
| 1005 | send_unsent(&xfer); |
| 1006 | nCard += send_unclustered(&xfer); |
| 1007 | } |
| 1008 | |
| 1009 | /* Send configuration parameter requests */ |
| 1010 | if( configRcvMask ){ |
| 1011 | const char *zName; |
| 1012 | zName = configure_first_name(configRcvMask); |
| 1013 | while( zName ){ |
| 1014 | blob_appendf(&send, "reqconfig %s\n", zName); |
| 1015 | zName = configure_next_name(configRcvMask); |
| 1016 | nCard++; |
| 1017 | } |
| 1018 | if( configRcvMask & (CONFIGSET_USER|CONFIGSET_TKT) ){ |
| 1019 | configure_prepare_to_receive(0); |
| 1020 | } |
| 1021 | configRcvMask = 0; |
| @@ -1026,11 +1027,11 @@ | |
| 1026 | const char *zName; |
| 1027 | zName = configure_first_name(configSendMask); |
| 1028 | while( zName ){ |
| 1029 | send_config_card(&xfer, zName); |
| 1030 | zName = configure_next_name(configSendMask); |
| 1031 | nCard++; |
| 1032 | } |
| 1033 | configSendMask = 0; |
| 1034 | } |
| 1035 | |
| 1036 | /* Append randomness to the end of the message */ |
| @@ -1039,13 +1040,14 @@ | |
| 1039 | free(zRandomness); |
| 1040 | |
| 1041 | /* Exchange messages with the server */ |
| 1042 | nFileSend = xfer.nFileSent + xfer.nDeltaSent; |
| 1043 | printf(zValueFormat, "Send:", |
| 1044 | blob_size(&send), nCard+xfer.nGimmeSent+xfer.nIGotSent, |
| 1045 | xfer.nFileSent, xfer.nDeltaSent); |
| 1046 | nCard = 0; |
| 1047 | xfer.nFileSent = 0; |
| 1048 | xfer.nDeltaSent = 0; |
| 1049 | xfer.nGimmeSent = 0; |
| 1050 | fflush(stdout); |
| 1051 | http_exchange(&send, &recv); |
| @@ -1054,25 +1056,25 @@ | |
| 1054 | /* Begin constructing the next message (which might never be |
| 1055 | ** sent) by beginning with the pull or push cards |
| 1056 | */ |
| 1057 | if( pullFlag ){ |
| 1058 | blob_appendf(&send, "pull %s %s\n", zSCode, zPCode); |
| 1059 | nCard++; |
| 1060 | } |
| 1061 | if( pushFlag ){ |
| 1062 | blob_appendf(&send, "push %s %s\n", zSCode, zPCode); |
| 1063 | nCard++; |
| 1064 | } |
| 1065 | |
| 1066 | /* Process the reply that came back from the server */ |
| 1067 | while( blob_line(&recv, &xfer.line) ){ |
| 1068 | if( blob_buffer(&xfer.line)[0]=='#' ){ |
| 1069 | continue; |
| 1070 | } |
| 1071 | xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken, count(xfer.aToken)); |
| 1072 | nCard++; |
| 1073 | printf("\r%d", nCard); |
| 1074 | fflush(stdout); |
| 1075 | |
| 1076 | /* file UUID SIZE \n CONTENT |
| 1077 | ** file UUID DELTASRC SIZE \n CONTENT |
| 1078 | ** |
| @@ -1138,11 +1140,11 @@ | |
| 1138 | if( zPCode==0 ){ |
| 1139 | zPCode = mprintf("%b", &xfer.aToken[2]); |
| 1140 | db_set("project-code", zPCode, 0); |
| 1141 | } |
| 1142 | blob_appendf(&send, "clone\n"); |
| 1143 | nCard++; |
| 1144 | }else |
| 1145 | |
| 1146 | /* config NAME SIZE \n CONTENT |
| 1147 | ** |
| 1148 | ** Receive a configuration value from the server. |
| @@ -1178,11 +1180,11 @@ | |
| 1178 | ** presumably the operator trusts the server. |
| 1179 | */ |
| 1180 | db_multi_exec("%s", blob_str(&content)); |
| 1181 | } |
| 1182 | } |
| 1183 | nCard++; |
| 1184 | blob_reset(&content); |
| 1185 | blob_seek(xfer.pIn, 1, BLOB_SEEK_CUR); |
| 1186 | }else |
| 1187 | |
| 1188 | |
| @@ -1204,11 +1206,11 @@ | |
| 1204 | ** Print a message. Similar to "error" but does not stop processing |
| 1205 | */ |
| 1206 | if( blob_eq(&xfer.aToken[0],"message") && xfer.nToken==2 ){ |
| 1207 | char *zMsg = blob_terminate(&xfer.aToken[1]); |
| 1208 | defossilize(zMsg); |
| 1209 | printf("Server says: %s\n", zMsg); |
| 1210 | }else |
| 1211 | |
| 1212 | /* error MESSAGE |
| 1213 | ** |
| 1214 | ** Report an error and abandon the sync session |
| @@ -1215,10 +1217,11 @@ | |
| 1215 | */ |
| 1216 | if( blob_eq(&xfer.aToken[0],"error") && xfer.nToken==2 ){ |
| 1217 | char *zMsg = blob_terminate(&xfer.aToken[1]); |
| 1218 | defossilize(zMsg); |
| 1219 | blob_appendf(&xfer.err, "server says: %s", zMsg); |
| 1220 | }else |
| 1221 | |
| 1222 | /* Unknown message */ |
| 1223 | { |
| 1224 | if( blob_str(&xfer.aToken[0])[0]=='<' ){ |
| @@ -1238,13 +1241,15 @@ | |
| 1238 | } |
| 1239 | if( origConfigRcvMask & (CONFIGSET_TKT|CONFIGSET_USER) ){ |
| 1240 | configure_finalize_receive(); |
| 1241 | } |
| 1242 | origConfigRcvMask = 0; |
| 1243 | printf(zValueFormat, "Received:", |
| 1244 | blob_size(&recv), nCard, |
| 1245 | xfer.nFileRcvd, xfer.nDeltaRcvd + xfer.nDanglingFile); |
| 1246 | blob_reset(&recv); |
| 1247 | nCycle++; |
| 1248 | go = 0; |
| 1249 | |
| 1250 | /* If we received one or more files on the previous exchange but |
| @@ -1254,11 +1259,11 @@ | |
| 1254 | if( (nFileRecv>0 || newPhantom) && db_exists("SELECT 1 FROM phantom") ){ |
| 1255 | go = 1; |
| 1256 | mxPhantomReq = nFileRecv*2; |
| 1257 | if( mxPhantomReq<200 ) mxPhantomReq = 200; |
| 1258 | } |
| 1259 | nCard = 0; |
| 1260 | xfer.nFileRcvd = 0; |
| 1261 | xfer.nDeltaRcvd = 0; |
| 1262 | xfer.nDanglingFile = 0; |
| 1263 | |
| 1264 | /* If we have one or more files queued to send, then go |
| 1265 |
| --- src/xfer.c | |
| +++ src/xfer.c | |
| @@ -922,11 +922,12 @@ | |
| 922 | int cloneFlag, /* True if this is a clone */ |
| 923 | int configRcvMask, /* Receive these configuration items */ |
| 924 | int configSendMask /* Send these configuration items */ |
| 925 | ){ |
| 926 | int go = 1; /* Loop until zero */ |
| 927 | int nCardSent = 0; /* Number of cards sent */ |
| 928 | int nCardRcvd = 0; /* Number of cards received */ |
| 929 | int nCycle = 0; /* Number of round trips to the server */ |
| 930 | int size; /* Size of a config value */ |
| 931 | int nFileSend = 0; |
| 932 | int origConfigRcvMask; /* Original value of configRcvMask */ |
| 933 | int nFileRecv; /* Number of files received */ |
| @@ -968,19 +969,19 @@ | |
| 969 | */ |
| 970 | if( cloneFlag ){ |
| 971 | blob_appendf(&send, "clone\n"); |
| 972 | pushFlag = 0; |
| 973 | pullFlag = 0; |
| 974 | nCardSent++; |
| 975 | /* TBD: Request all transferable configuration values */ |
| 976 | }else if( pullFlag ){ |
| 977 | blob_appendf(&send, "pull %s %s\n", zSCode, zPCode); |
| 978 | nCardSent++; |
| 979 | } |
| 980 | if( pushFlag ){ |
| 981 | blob_appendf(&send, "push %s %s\n", zSCode, zPCode); |
| 982 | nCardSent++; |
| 983 | } |
| 984 | manifest_crosslink_begin(); |
| 985 | printf(zLabelFormat, "", "Bytes", "Cards", "Artifacts", "Deltas"); |
| 986 | |
| 987 | while( go ){ |
| @@ -1001,21 +1002,21 @@ | |
| 1002 | if( pullFlag || cloneFlag ){ |
| 1003 | request_phantoms(&xfer, mxPhantomReq); |
| 1004 | } |
| 1005 | if( pushFlag ){ |
| 1006 | send_unsent(&xfer); |
| 1007 | nCardSent += send_unclustered(&xfer); |
| 1008 | } |
| 1009 | |
| 1010 | /* Send configuration parameter requests */ |
| 1011 | if( configRcvMask ){ |
| 1012 | const char *zName; |
| 1013 | zName = configure_first_name(configRcvMask); |
| 1014 | while( zName ){ |
| 1015 | blob_appendf(&send, "reqconfig %s\n", zName); |
| 1016 | zName = configure_next_name(configRcvMask); |
| 1017 | nCardSent++; |
| 1018 | } |
| 1019 | if( configRcvMask & (CONFIGSET_USER|CONFIGSET_TKT) ){ |
| 1020 | configure_prepare_to_receive(0); |
| 1021 | } |
| 1022 | configRcvMask = 0; |
| @@ -1026,11 +1027,11 @@ | |
| 1027 | const char *zName; |
| 1028 | zName = configure_first_name(configSendMask); |
| 1029 | while( zName ){ |
| 1030 | send_config_card(&xfer, zName); |
| 1031 | zName = configure_next_name(configSendMask); |
| 1032 | nCardSent++; |
| 1033 | } |
| 1034 | configSendMask = 0; |
| 1035 | } |
| 1036 | |
| 1037 | /* Append randomness to the end of the message */ |
| @@ -1039,13 +1040,14 @@ | |
| 1040 | free(zRandomness); |
| 1041 | |
| 1042 | /* Exchange messages with the server */ |
| 1043 | nFileSend = xfer.nFileSent + xfer.nDeltaSent; |
| 1044 | printf(zValueFormat, "Send:", |
| 1045 | blob_size(&send), nCardSent+xfer.nGimmeSent+xfer.nIGotSent, |
| 1046 | xfer.nFileSent, xfer.nDeltaSent); |
| 1047 | nCardSent = 0; |
| 1048 | nCardRcvd = 0; |
| 1049 | xfer.nFileSent = 0; |
| 1050 | xfer.nDeltaSent = 0; |
| 1051 | xfer.nGimmeSent = 0; |
| 1052 | fflush(stdout); |
| 1053 | http_exchange(&send, &recv); |
| @@ -1054,25 +1056,25 @@ | |
| 1056 | /* Begin constructing the next message (which might never be |
| 1057 | ** sent) by beginning with the pull or push cards |
| 1058 | */ |
| 1059 | if( pullFlag ){ |
| 1060 | blob_appendf(&send, "pull %s %s\n", zSCode, zPCode); |
| 1061 | nCardSent++; |
| 1062 | } |
| 1063 | if( pushFlag ){ |
| 1064 | blob_appendf(&send, "push %s %s\n", zSCode, zPCode); |
| 1065 | nCardSent++; |
| 1066 | } |
| 1067 | |
| 1068 | /* Process the reply that came back from the server */ |
| 1069 | while( blob_line(&recv, &xfer.line) ){ |
| 1070 | if( blob_buffer(&xfer.line)[0]=='#' ){ |
| 1071 | continue; |
| 1072 | } |
| 1073 | xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken, count(xfer.aToken)); |
| 1074 | nCardRcvd++; |
| 1075 | printf("\r%d", nCardRcvd); |
| 1076 | fflush(stdout); |
| 1077 | |
| 1078 | /* file UUID SIZE \n CONTENT |
| 1079 | ** file UUID DELTASRC SIZE \n CONTENT |
| 1080 | ** |
| @@ -1138,11 +1140,11 @@ | |
| 1140 | if( zPCode==0 ){ |
| 1141 | zPCode = mprintf("%b", &xfer.aToken[2]); |
| 1142 | db_set("project-code", zPCode, 0); |
| 1143 | } |
| 1144 | blob_appendf(&send, "clone\n"); |
| 1145 | nCardSent++; |
| 1146 | }else |
| 1147 | |
| 1148 | /* config NAME SIZE \n CONTENT |
| 1149 | ** |
| 1150 | ** Receive a configuration value from the server. |
| @@ -1178,11 +1180,11 @@ | |
| 1180 | ** presumably the operator trusts the server. |
| 1181 | */ |
| 1182 | db_multi_exec("%s", blob_str(&content)); |
| 1183 | } |
| 1184 | } |
| 1185 | nCardSent++; |
| 1186 | blob_reset(&content); |
| 1187 | blob_seek(xfer.pIn, 1, BLOB_SEEK_CUR); |
| 1188 | }else |
| 1189 | |
| 1190 | |
| @@ -1204,11 +1206,11 @@ | |
| 1206 | ** Print a message. Similar to "error" but does not stop processing |
| 1207 | */ |
| 1208 | if( blob_eq(&xfer.aToken[0],"message") && xfer.nToken==2 ){ |
| 1209 | char *zMsg = blob_terminate(&xfer.aToken[1]); |
| 1210 | defossilize(zMsg); |
| 1211 | printf("\rServer says: %s\n", zMsg); |
| 1212 | }else |
| 1213 | |
| 1214 | /* error MESSAGE |
| 1215 | ** |
| 1216 | ** Report an error and abandon the sync session |
| @@ -1215,10 +1217,11 @@ | |
| 1217 | */ |
| 1218 | if( blob_eq(&xfer.aToken[0],"error") && xfer.nToken==2 ){ |
| 1219 | char *zMsg = blob_terminate(&xfer.aToken[1]); |
| 1220 | defossilize(zMsg); |
| 1221 | blob_appendf(&xfer.err, "server says: %s", zMsg); |
| 1222 | printf("Server Error: %s\n", zMsg); |
| 1223 | }else |
| 1224 | |
| 1225 | /* Unknown message */ |
| 1226 | { |
| 1227 | if( blob_str(&xfer.aToken[0])[0]=='<' ){ |
| @@ -1238,13 +1241,15 @@ | |
| 1241 | } |
| 1242 | if( origConfigRcvMask & (CONFIGSET_TKT|CONFIGSET_USER) ){ |
| 1243 | configure_finalize_receive(); |
| 1244 | } |
| 1245 | origConfigRcvMask = 0; |
| 1246 | if( nCardRcvd>0 ){ |
| 1247 | printf(zValueFormat, "Received:", |
| 1248 | blob_size(&recv), nCardRcvd, |
| 1249 | xfer.nFileRcvd, xfer.nDeltaRcvd + xfer.nDanglingFile); |
| 1250 | } |
| 1251 | blob_reset(&recv); |
| 1252 | nCycle++; |
| 1253 | go = 0; |
| 1254 | |
| 1255 | /* If we received one or more files on the previous exchange but |
| @@ -1254,11 +1259,11 @@ | |
| 1259 | if( (nFileRecv>0 || newPhantom) && db_exists("SELECT 1 FROM phantom") ){ |
| 1260 | go = 1; |
| 1261 | mxPhantomReq = nFileRecv*2; |
| 1262 | if( mxPhantomReq<200 ) mxPhantomReq = 200; |
| 1263 | } |
| 1264 | nCardRcvd = 0; |
| 1265 | xfer.nFileRcvd = 0; |
| 1266 | xfer.nDeltaRcvd = 0; |
| 1267 | xfer.nDanglingFile = 0; |
| 1268 | |
| 1269 | /* If we have one or more files queued to send, then go |
| 1270 |