Fossil SCM

Further work on getting a "commit" or "update" to continue operating after an autosync failure. The "commit" command prompts to verify that you want to continue.

drh 2010-11-19 22:29 trunk
Commit 0cc4875fde9f492b2f04bbc2b095417905adb4af
+8 -1
--- src/checkin.c
+++ src/checkin.c
@@ -807,11 +807,18 @@
807807
808808
/*
809809
** Autosync if autosync is enabled and this is not a private check-in.
810810
*/
811811
if( !g.markPrivate ){
812
- autosync(AUTOSYNC_PULL);
812
+ if( autosync(AUTOSYNC_PULL) ){
813
+ Blob ans;
814
+ blob_zero(&ans);
815
+ prompt_user("continue in spite of sync failure (y/N)? ", &ans);
816
+ if( blob_str(&ans)[0]!='y' ){
817
+ fossil_exit(1);
818
+ }
819
+ }
813820
}
814821
815822
/* Require confirmation to continue with the check-in if there is
816823
** clock skew
817824
*/
818825
--- src/checkin.c
+++ src/checkin.c
@@ -807,11 +807,18 @@
807
808 /*
809 ** Autosync if autosync is enabled and this is not a private check-in.
810 */
811 if( !g.markPrivate ){
812 autosync(AUTOSYNC_PULL);
 
 
 
 
 
 
 
813 }
814
815 /* Require confirmation to continue with the check-in if there is
816 ** clock skew
817 */
818
--- src/checkin.c
+++ src/checkin.c
@@ -807,11 +807,18 @@
807
808 /*
809 ** Autosync if autosync is enabled and this is not a private check-in.
810 */
811 if( !g.markPrivate ){
812 if( autosync(AUTOSYNC_PULL) ){
813 Blob ans;
814 blob_zero(&ans);
815 prompt_user("continue in spite of sync failure (y/N)? ", &ans);
816 if( blob_str(&ans)[0]!='y' ){
817 fossil_exit(1);
818 }
819 }
820 }
821
822 /* Require confirmation to continue with the check-in if there is
823 ** clock skew
824 */
825
--- src/http_socket.c
+++ src/http_socket.c
@@ -152,11 +152,11 @@
152152
if( pHost!=0 ){
153153
memcpy(&addr.sin_addr,pHost->h_addr_list[0],pHost->h_length);
154154
}else
155155
#endif
156156
{
157
- socket_set_errmsg("can't resolve host name: %s\n", g.urlName);
157
+ socket_set_errmsg("can't resolve host name: %s", g.urlName);
158158
return 1;
159159
}
160160
}
161161
addrIsInit = 1;
162162
163163
--- src/http_socket.c
+++ src/http_socket.c
@@ -152,11 +152,11 @@
152 if( pHost!=0 ){
153 memcpy(&addr.sin_addr,pHost->h_addr_list[0],pHost->h_length);
154 }else
155 #endif
156 {
157 socket_set_errmsg("can't resolve host name: %s\n", g.urlName);
158 return 1;
159 }
160 }
161 addrIsInit = 1;
162
163
--- src/http_socket.c
+++ src/http_socket.c
@@ -152,11 +152,11 @@
152 if( pHost!=0 ){
153 memcpy(&addr.sin_addr,pHost->h_addr_list[0],pHost->h_length);
154 }else
155 #endif
156 {
157 socket_set_errmsg("can't resolve host name: %s", g.urlName);
158 return 1;
159 }
160 }
161 addrIsInit = 1;
162
163
+11 -6
--- src/sync.c
+++ src/sync.c
@@ -32,33 +32,36 @@
3232
3333
/*
3434
** If the respository is configured for autosyncing, then do an
3535
** autosync. This will be a pull if the argument is true or a push
3636
** if the argument is false.
37
+**
38
+** Return the number of errors.
3739
*/
38
-void autosync(int flags){
40
+int autosync(int flags){
3941
const char *zUrl;
4042
const char *zAutosync;
4143
const char *zPw;
44
+ int rc;
4245
int configSync = 0; /* configuration changes transferred */
4346
if( g.fNoSync ){
44
- return;
47
+ return 0;
4548
}
4649
zAutosync = db_get("autosync", 0);
4750
if( zAutosync ){
4851
if( (flags & AUTOSYNC_PUSH)!=0 && memcmp(zAutosync,"pull",4)==0 ){
49
- return; /* Do not auto-push when autosync=pullonly */
52
+ return 0; /* Do not auto-push when autosync=pullonly */
5053
}
5154
if( is_false(zAutosync) ){
52
- return; /* Autosync is completely off */
55
+ return 0; /* Autosync is completely off */
5356
}
5457
}else{
5558
/* Autosync defaults on. To make it default off, "return" here. */
5659
}
5760
zUrl = db_get("last-sync-url", 0);
5861
if( zUrl==0 ){
59
- return; /* No default server */
62
+ return 0; /* No default server */
6063
}
6164
zPw = unobscure(db_get("last-sync-pw", 0));
6265
url_parse(zUrl);
6366
if( g.urlUser!=0 && g.urlPasswd==0 ){
6467
g.urlPasswd = mprintf("%s", zPw);
@@ -75,11 +78,13 @@
7578
configSync = CONFIGSET_SHUN;
7679
}
7780
#endif
7881
printf("Autosync: %s\n", g.urlCanonical);
7982
url_enable_proxy("via proxy: ");
80
- client_sync((flags & AUTOSYNC_PUSH)!=0, 1, 0, configSync, 0);
83
+ rc = client_sync((flags & AUTOSYNC_PUSH)!=0, 1, 0, configSync, 0);
84
+ if( rc ) fossil_warning("Autosync failed");
85
+ return rc;
8186
}
8287
8388
/*
8489
** This routine processes the command-line argument for push, pull,
8590
** and sync. If a command-line argument is given, that is the URL
8691
--- src/sync.c
+++ src/sync.c
@@ -32,33 +32,36 @@
32
33 /*
34 ** If the respository is configured for autosyncing, then do an
35 ** autosync. This will be a pull if the argument is true or a push
36 ** if the argument is false.
 
 
37 */
38 void autosync(int flags){
39 const char *zUrl;
40 const char *zAutosync;
41 const char *zPw;
 
42 int configSync = 0; /* configuration changes transferred */
43 if( g.fNoSync ){
44 return;
45 }
46 zAutosync = db_get("autosync", 0);
47 if( zAutosync ){
48 if( (flags & AUTOSYNC_PUSH)!=0 && memcmp(zAutosync,"pull",4)==0 ){
49 return; /* Do not auto-push when autosync=pullonly */
50 }
51 if( is_false(zAutosync) ){
52 return; /* Autosync is completely off */
53 }
54 }else{
55 /* Autosync defaults on. To make it default off, "return" here. */
56 }
57 zUrl = db_get("last-sync-url", 0);
58 if( zUrl==0 ){
59 return; /* No default server */
60 }
61 zPw = unobscure(db_get("last-sync-pw", 0));
62 url_parse(zUrl);
63 if( g.urlUser!=0 && g.urlPasswd==0 ){
64 g.urlPasswd = mprintf("%s", zPw);
@@ -75,11 +78,13 @@
75 configSync = CONFIGSET_SHUN;
76 }
77 #endif
78 printf("Autosync: %s\n", g.urlCanonical);
79 url_enable_proxy("via proxy: ");
80 client_sync((flags & AUTOSYNC_PUSH)!=0, 1, 0, configSync, 0);
 
 
81 }
82
83 /*
84 ** This routine processes the command-line argument for push, pull,
85 ** and sync. If a command-line argument is given, that is the URL
86
--- src/sync.c
+++ src/sync.c
@@ -32,33 +32,36 @@
32
33 /*
34 ** If the respository is configured for autosyncing, then do an
35 ** autosync. This will be a pull if the argument is true or a push
36 ** if the argument is false.
37 **
38 ** Return the number of errors.
39 */
40 int autosync(int flags){
41 const char *zUrl;
42 const char *zAutosync;
43 const char *zPw;
44 int rc;
45 int configSync = 0; /* configuration changes transferred */
46 if( g.fNoSync ){
47 return 0;
48 }
49 zAutosync = db_get("autosync", 0);
50 if( zAutosync ){
51 if( (flags & AUTOSYNC_PUSH)!=0 && memcmp(zAutosync,"pull",4)==0 ){
52 return 0; /* Do not auto-push when autosync=pullonly */
53 }
54 if( is_false(zAutosync) ){
55 return 0; /* Autosync is completely off */
56 }
57 }else{
58 /* Autosync defaults on. To make it default off, "return" here. */
59 }
60 zUrl = db_get("last-sync-url", 0);
61 if( zUrl==0 ){
62 return 0; /* No default server */
63 }
64 zPw = unobscure(db_get("last-sync-pw", 0));
65 url_parse(zUrl);
66 if( g.urlUser!=0 && g.urlPasswd==0 ){
67 g.urlPasswd = mprintf("%s", zPw);
@@ -75,11 +78,13 @@
78 configSync = CONFIGSET_SHUN;
79 }
80 #endif
81 printf("Autosync: %s\n", g.urlCanonical);
82 url_enable_proxy("via proxy: ");
83 rc = client_sync((flags & AUTOSYNC_PUSH)!=0, 1, 0, configSync, 0);
84 if( rc ) fossil_warning("Autosync failed");
85 return rc;
86 }
87
88 /*
89 ** This routine processes the command-line argument for push, pull,
90 ** and sync. If a command-line argument is given, that is the URL
91
+17 -6
--- src/xfer.c
+++ src/xfer.c
@@ -975,11 +975,11 @@
975975
**
976976
** Records are pushed to the server if pushFlag is true. Records
977977
** are pulled if pullFlag is true. A full sync occurs if both are
978978
** true.
979979
*/
980
-void client_sync(
980
+int client_sync(
981981
int pushFlag, /* True to do a push (or a sync) */
982982
int pullFlag, /* True to do a pull (or a sync) */
983983
int cloneFlag, /* True if this is a clone */
984984
int configRcvMask, /* Receive these configuration items */
985985
int configSendMask /* Send these configuration items */
@@ -1002,14 +1002,15 @@
10021002
int pctDone; /* Percentage done with a message */
10031003
int lastPctDone = -1; /* Last displayed pctDone */
10041004
double rArrivalTime; /* Time at which a message arrived */
10051005
const char *zSCode = db_get("server-code", "x");
10061006
const char *zPCode = db_get("project-code", 0);
1007
+ int nErr = 0; /* Number of errors */
10071008
10081009
if( db_get_boolean("dont-push", 0) ) pushFlag = 0;
10091010
if( pushFlag + pullFlag + cloneFlag == 0
1010
- && configRcvMask==0 && configSendMask==0 ) return;
1011
+ && configRcvMask==0 && configSendMask==0 ) return 0;
10111012
10121013
transport_stats(0, 0, 1);
10131014
socket_global_init();
10141015
memset(&xfer, 0, sizeof(xfer));
10151016
xfer.pIn = &recv;
@@ -1126,11 +1127,14 @@
11261127
xfer.nIGotSent = 0;
11271128
if( !g.cgiOutput && !g.fQuiet ){
11281129
printf("waiting for server...");
11291130
}
11301131
fflush(stdout);
1131
- http_exchange(&send, &recv, cloneFlag==0 || nCycle>0);
1132
+ if( http_exchange(&send, &recv, cloneFlag==0 || nCycle>0) ){
1133
+ nErr++;
1134
+ break;
1135
+ }
11321136
lastPctDone = -1;
11331137
blob_reset(&send);
11341138
rArrivalTime = db_double(0.0, "SELECT julianday('now')");
11351139
11361140
/* Begin constructing the next message (which might never be
@@ -1352,27 +1356,33 @@
13521356
go = 1;
13531357
}
13541358
}else{
13551359
blob_appendf(&xfer.err, "\rserver says: %s", zMsg);
13561360
}
1357
- fossil_fatal("\rError: %s", zMsg);
1361
+ fossil_warning("\rError: %s", zMsg);
1362
+ nErr++;
1363
+ break;
13581364
}
13591365
}else
13601366
13611367
/* Unknown message */
13621368
{
13631369
if( blob_str(&xfer.aToken[0])[0]=='<' ){
1364
- fossil_fatal(
1370
+ fossil_warning(
13651371
"server replies with HTML instead of fossil sync protocol:\n%b",
13661372
&recv
13671373
);
1374
+ nErr++;
1375
+ break;
13681376
}
13691377
blob_appendf(&xfer.err, "unknown command: %b", &xfer.aToken[0]);
13701378
}
13711379
13721380
if( blob_size(&xfer.err) ){
1373
- fossil_fatal("%b", &xfer.err);
1381
+ fossil_warning("%b", &xfer.err);
1382
+ nErr++;
1383
+ break;
13741384
}
13751385
blobarray_reset(xfer.aToken, xfer.nToken);
13761386
blob_reset(&xfer.line);
13771387
}
13781388
if( origConfigRcvMask & (CONFIGSET_TKT|CONFIGSET_USER) ){
@@ -1423,6 +1433,7 @@
14231433
transport_global_shutdown();
14241434
db_multi_exec("DROP TABLE onremote");
14251435
manifest_crosslink_end();
14261436
content_enable_dephantomize(1);
14271437
db_end_transaction(0);
1438
+ return nErr;
14281439
}
14291440
--- src/xfer.c
+++ src/xfer.c
@@ -975,11 +975,11 @@
975 **
976 ** Records are pushed to the server if pushFlag is true. Records
977 ** are pulled if pullFlag is true. A full sync occurs if both are
978 ** true.
979 */
980 void client_sync(
981 int pushFlag, /* True to do a push (or a sync) */
982 int pullFlag, /* True to do a pull (or a sync) */
983 int cloneFlag, /* True if this is a clone */
984 int configRcvMask, /* Receive these configuration items */
985 int configSendMask /* Send these configuration items */
@@ -1002,14 +1002,15 @@
1002 int pctDone; /* Percentage done with a message */
1003 int lastPctDone = -1; /* Last displayed pctDone */
1004 double rArrivalTime; /* Time at which a message arrived */
1005 const char *zSCode = db_get("server-code", "x");
1006 const char *zPCode = db_get("project-code", 0);
 
1007
1008 if( db_get_boolean("dont-push", 0) ) pushFlag = 0;
1009 if( pushFlag + pullFlag + cloneFlag == 0
1010 && configRcvMask==0 && configSendMask==0 ) return;
1011
1012 transport_stats(0, 0, 1);
1013 socket_global_init();
1014 memset(&xfer, 0, sizeof(xfer));
1015 xfer.pIn = &recv;
@@ -1126,11 +1127,14 @@
1126 xfer.nIGotSent = 0;
1127 if( !g.cgiOutput && !g.fQuiet ){
1128 printf("waiting for server...");
1129 }
1130 fflush(stdout);
1131 http_exchange(&send, &recv, cloneFlag==0 || nCycle>0);
 
 
 
1132 lastPctDone = -1;
1133 blob_reset(&send);
1134 rArrivalTime = db_double(0.0, "SELECT julianday('now')");
1135
1136 /* Begin constructing the next message (which might never be
@@ -1352,27 +1356,33 @@
1352 go = 1;
1353 }
1354 }else{
1355 blob_appendf(&xfer.err, "\rserver says: %s", zMsg);
1356 }
1357 fossil_fatal("\rError: %s", zMsg);
 
 
1358 }
1359 }else
1360
1361 /* Unknown message */
1362 {
1363 if( blob_str(&xfer.aToken[0])[0]=='<' ){
1364 fossil_fatal(
1365 "server replies with HTML instead of fossil sync protocol:\n%b",
1366 &recv
1367 );
 
 
1368 }
1369 blob_appendf(&xfer.err, "unknown command: %b", &xfer.aToken[0]);
1370 }
1371
1372 if( blob_size(&xfer.err) ){
1373 fossil_fatal("%b", &xfer.err);
 
 
1374 }
1375 blobarray_reset(xfer.aToken, xfer.nToken);
1376 blob_reset(&xfer.line);
1377 }
1378 if( origConfigRcvMask & (CONFIGSET_TKT|CONFIGSET_USER) ){
@@ -1423,6 +1433,7 @@
1423 transport_global_shutdown();
1424 db_multi_exec("DROP TABLE onremote");
1425 manifest_crosslink_end();
1426 content_enable_dephantomize(1);
1427 db_end_transaction(0);
 
1428 }
1429
--- src/xfer.c
+++ src/xfer.c
@@ -975,11 +975,11 @@
975 **
976 ** Records are pushed to the server if pushFlag is true. Records
977 ** are pulled if pullFlag is true. A full sync occurs if both are
978 ** true.
979 */
980 int client_sync(
981 int pushFlag, /* True to do a push (or a sync) */
982 int pullFlag, /* True to do a pull (or a sync) */
983 int cloneFlag, /* True if this is a clone */
984 int configRcvMask, /* Receive these configuration items */
985 int configSendMask /* Send these configuration items */
@@ -1002,14 +1002,15 @@
1002 int pctDone; /* Percentage done with a message */
1003 int lastPctDone = -1; /* Last displayed pctDone */
1004 double rArrivalTime; /* Time at which a message arrived */
1005 const char *zSCode = db_get("server-code", "x");
1006 const char *zPCode = db_get("project-code", 0);
1007 int nErr = 0; /* Number of errors */
1008
1009 if( db_get_boolean("dont-push", 0) ) pushFlag = 0;
1010 if( pushFlag + pullFlag + cloneFlag == 0
1011 && configRcvMask==0 && configSendMask==0 ) return 0;
1012
1013 transport_stats(0, 0, 1);
1014 socket_global_init();
1015 memset(&xfer, 0, sizeof(xfer));
1016 xfer.pIn = &recv;
@@ -1126,11 +1127,14 @@
1127 xfer.nIGotSent = 0;
1128 if( !g.cgiOutput && !g.fQuiet ){
1129 printf("waiting for server...");
1130 }
1131 fflush(stdout);
1132 if( http_exchange(&send, &recv, cloneFlag==0 || nCycle>0) ){
1133 nErr++;
1134 break;
1135 }
1136 lastPctDone = -1;
1137 blob_reset(&send);
1138 rArrivalTime = db_double(0.0, "SELECT julianday('now')");
1139
1140 /* Begin constructing the next message (which might never be
@@ -1352,27 +1356,33 @@
1356 go = 1;
1357 }
1358 }else{
1359 blob_appendf(&xfer.err, "\rserver says: %s", zMsg);
1360 }
1361 fossil_warning("\rError: %s", zMsg);
1362 nErr++;
1363 break;
1364 }
1365 }else
1366
1367 /* Unknown message */
1368 {
1369 if( blob_str(&xfer.aToken[0])[0]=='<' ){
1370 fossil_warning(
1371 "server replies with HTML instead of fossil sync protocol:\n%b",
1372 &recv
1373 );
1374 nErr++;
1375 break;
1376 }
1377 blob_appendf(&xfer.err, "unknown command: %b", &xfer.aToken[0]);
1378 }
1379
1380 if( blob_size(&xfer.err) ){
1381 fossil_warning("%b", &xfer.err);
1382 nErr++;
1383 break;
1384 }
1385 blobarray_reset(xfer.aToken, xfer.nToken);
1386 blob_reset(&xfer.line);
1387 }
1388 if( origConfigRcvMask & (CONFIGSET_TKT|CONFIGSET_USER) ){
@@ -1423,6 +1433,7 @@
1433 transport_global_shutdown();
1434 db_multi_exec("DROP TABLE onremote");
1435 manifest_crosslink_end();
1436 content_enable_dephantomize(1);
1437 db_end_transaction(0);
1438 return nErr;
1439 }
1440

Keyboard Shortcuts

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