Fossil SCM
Try to handle some error conditions better. First, if the clone's first sync didn't bring down any artifacts there isn't likely any point in continuing. Second, if on resuming a clone no artifacts were received, abort. Third, check if the project-code has changed earlier (this might be detected earlier when the client receives the "push" card).
Commit
17f3408f6b557e2771be9976e5a9bea4f04bee39558a8ad43c2527f88a5e0915
Parent
4fdc41bd05192bb…
1 file changed
+26
-27
+26
-27
| --- src/clone.c | ||
| +++ src/clone.c | ||
| @@ -151,11 +151,11 @@ | ||
| 151 | 151 | int urlFlags = URL_PROMPT_PW | URL_REMEMBER; |
| 152 | 152 | int syncFlags = SYNC_CLONE; |
| 153 | 153 | int noCompress = find_option("nocompress",0,0)!=0; |
| 154 | 154 | int noOpen = find_option("no-open",0,0)!=0; |
| 155 | 155 | int allowNested = find_option("nested",0,0)!=0; /* Used by open */ |
| 156 | - int bResume = 0; /* Set if a previous clone failed */ | |
| 156 | + int nResumeSeqno = 0; /* Last seqno from which to resume clone */ | |
| 157 | 157 | const char *zNewProjCode; /* New Project code obtained during clone */ |
| 158 | 158 | const char *zOldProjCode; /* Old project code stored in resuming clone */ |
| 159 | 159 | const char *zRepo = 0; /* Name of the new local repository file */ |
| 160 | 160 | const char *zWorkDir = 0; /* Open in this directory, if not zero */ |
| 161 | 161 | |
| @@ -204,13 +204,13 @@ | ||
| 204 | 204 | } |
| 205 | 205 | fossil_free(zBase); |
| 206 | 206 | } |
| 207 | 207 | if( -1 != file_size(zRepo, ExtFILE) ){ |
| 208 | 208 | db_open_repository(zRepo); |
| 209 | - bResume = db_get_int("aux-clone-seqno",0)!=0; | |
| 209 | + nResumeSeqno = db_get_int("aux-clone-seqno",0); | |
| 210 | 210 | db_close(0); |
| 211 | - if( !bResume ){ | |
| 211 | + if( !nResumeSeqno ){ | |
| 212 | 212 | fossil_fatal("file already exists: %s", zRepo); |
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | 215 | /* Fail before clone if open will fail because inside an open check-out */ |
| 216 | 216 | if( zWorkDir!=0 && zWorkDir[0]!=0 && !noOpen ){ |
| @@ -236,23 +236,18 @@ | ||
| 236 | 236 | g.zLogin = db_text(0, "SELECT login FROM user WHERE cap LIKE '%%s%%'"); |
| 237 | 237 | } |
| 238 | 238 | fossil_print("Repository cloned into %s\n", zRepo); |
| 239 | 239 | }else{ |
| 240 | 240 | db_close_config(); |
| 241 | - if( bResume ){ | |
| 241 | + if( nResumeSeqno>1 ){ | |
| 242 | 242 | db_open_repository(zRepo); |
| 243 | 243 | db_open_config(0,0); |
| 244 | 244 | db_begin_transaction(); |
| 245 | - db_unprotect(PROTECT_CONFIG); | |
| 246 | 245 | zOldProjCode = db_get("project-code",0); |
| 247 | 246 | fossil_print("Resuming clone of project-id %s\n",zOldProjCode); |
| 248 | - db_multi_exec( | |
| 249 | - "DELETE FROM config WHERE name = 'project-code';" | |
| 250 | - "DELETE FROM config WHERE name = 'server-code';" | |
| 251 | - ); | |
| 252 | - db_protect_pop(); | |
| 253 | - db_initial_setup(0, 0, zDefaultUser); | |
| 247 | + db_create_default_users(1, zDefaultUser); | |
| 248 | + if( zDefaultUser ) g.zLogin = zDefaultUser; | |
| 254 | 249 | user_select(); |
| 255 | 250 | }else{ |
| 256 | 251 | db_create_repository(zRepo); |
| 257 | 252 | db_open_repository(zRepo); |
| 258 | 253 | db_open_config(0,0); |
| @@ -290,38 +285,42 @@ | ||
| 290 | 285 | url_get_password_if_needed(); |
| 291 | 286 | g.xlinkClusterOnly = 1; |
| 292 | 287 | while( nResumes++<3 && sync_interrupted()==0 |
| 293 | 288 | && (nErr = client_sync(syncFlags,CONFIGSET_ALL,0,0)) |
| 294 | 289 | ){ |
| 295 | - if( sync_interrupted()!=0 ){ | |
| 296 | - fossil_warning("cloning encountered errors, trying again."); | |
| 297 | - sqlite3_sleep(500); | |
| 290 | + if( sync_interrupted() ) break; | |
| 291 | + if( db_get_int("aux-clone-seqno",1)==1 ){ | |
| 292 | + fossil_fatal("server returned an error - clone aborted"); | |
| 298 | 293 | } |
| 294 | + fossil_warning("cloning encountered errors, trying again."); | |
| 295 | + sqlite3_sleep(500); | |
| 299 | 296 | } |
| 300 | 297 | g.xlinkClusterOnly = 0; |
| 301 | 298 | verify_cancel(); |
| 299 | + if( nResumeSeqno>1 ){ | |
| 300 | + if( nResumeSeqno==db_get_int("aux-clone-seqno",0) ){ | |
| 301 | + fossil_fatal("No progress was made - aborting"); | |
| 302 | + } | |
| 303 | + zNewProjCode = db_get("project-code",0); | |
| 304 | + if( zOldProjCode && zOldProjCode[0] | |
| 305 | + && fossil_strcmp(zOldProjCode, zNewProjCode)!=0 ){ | |
| 306 | + fossil_fatal("project-id changed\nwas %s\nis %s" | |
| 307 | + "\nrolling back changes", | |
| 308 | + zOldProjCode, zNewProjCode); | |
| 309 | + } | |
| 310 | + } | |
| 302 | 311 | if( nErr ){ |
| 303 | 312 | fossil_warning("server returned an error - clone incomplete"); |
| 304 | 313 | }else if( sync_interrupted()==1 ){ |
| 305 | 314 | fossil_warning("clone was interrupted"); |
| 306 | 315 | }else{ |
| 307 | 316 | db_unprotect(PROTECT_CONFIG); |
| 308 | 317 | db_multi_exec("DELETE FROM config WHERE name = 'aux-clone-seqno';"); |
| 309 | 318 | db_protect_pop(); |
| 310 | 319 | } |
| 311 | - zNewProjCode = db_get("project-code",0); | |
| 312 | - if( bResume && zOldProjCode && zOldProjCode[0] | |
| 313 | - && fossil_strcmp(zOldProjCode, zNewProjCode)!=0 ){ | |
| 314 | - fossil_warning("project-id changed\nwas %s\nis %s\nrolling back changes", | |
| 315 | - zOldProjCode, zNewProjCode); | |
| 316 | - db_end_transaction(1); | |
| 317 | - db_close(1); | |
| 318 | - fossil_exit(1); | |
| 319 | - }else{ | |
| 320 | - db_end_transaction(0); | |
| 321 | - db_close(1); | |
| 322 | - } | |
| 320 | + db_end_transaction(0); | |
| 321 | + db_close(1); | |
| 323 | 322 | db_open_repository(zRepo); |
| 324 | 323 | #if !defined(_WIN32) |
| 325 | 324 | signal(SIGINT, SIG_DFL); |
| 326 | 325 | #endif |
| 327 | 326 | } |
| @@ -330,11 +329,11 @@ | ||
| 330 | 329 | if( db_get_int("aux-clone-seqno",0)==0 ){ |
| 331 | 330 | fossil_fatal("there are unresolved deltas -" |
| 332 | 331 | " the clone is probabaly incomplete and unusable."); |
| 333 | 332 | } |
| 334 | 333 | } |
| 335 | - if( db_get_int("aux-clone-seqno",0)>0 ){ | |
| 334 | + if( db_get_int("aux-clone-seqno",0)>1 ){ | |
| 336 | 335 | fossil_warning("It may be possible to resume the" |
| 337 | 336 | " clone by running the same command again."); |
| 338 | 337 | }else{ |
| 339 | 338 | fossil_print("Rebuilding repository meta-data...\n"); |
| 340 | 339 | rebuild_db(1, 0); |
| 341 | 340 |
| --- src/clone.c | |
| +++ src/clone.c | |
| @@ -151,11 +151,11 @@ | |
| 151 | int urlFlags = URL_PROMPT_PW | URL_REMEMBER; |
| 152 | int syncFlags = SYNC_CLONE; |
| 153 | int noCompress = find_option("nocompress",0,0)!=0; |
| 154 | int noOpen = find_option("no-open",0,0)!=0; |
| 155 | int allowNested = find_option("nested",0,0)!=0; /* Used by open */ |
| 156 | int bResume = 0; /* Set if a previous clone failed */ |
| 157 | const char *zNewProjCode; /* New Project code obtained during clone */ |
| 158 | const char *zOldProjCode; /* Old project code stored in resuming clone */ |
| 159 | const char *zRepo = 0; /* Name of the new local repository file */ |
| 160 | const char *zWorkDir = 0; /* Open in this directory, if not zero */ |
| 161 | |
| @@ -204,13 +204,13 @@ | |
| 204 | } |
| 205 | fossil_free(zBase); |
| 206 | } |
| 207 | if( -1 != file_size(zRepo, ExtFILE) ){ |
| 208 | db_open_repository(zRepo); |
| 209 | bResume = db_get_int("aux-clone-seqno",0)!=0; |
| 210 | db_close(0); |
| 211 | if( !bResume ){ |
| 212 | fossil_fatal("file already exists: %s", zRepo); |
| 213 | } |
| 214 | } |
| 215 | /* Fail before clone if open will fail because inside an open check-out */ |
| 216 | if( zWorkDir!=0 && zWorkDir[0]!=0 && !noOpen ){ |
| @@ -236,23 +236,18 @@ | |
| 236 | g.zLogin = db_text(0, "SELECT login FROM user WHERE cap LIKE '%%s%%'"); |
| 237 | } |
| 238 | fossil_print("Repository cloned into %s\n", zRepo); |
| 239 | }else{ |
| 240 | db_close_config(); |
| 241 | if( bResume ){ |
| 242 | db_open_repository(zRepo); |
| 243 | db_open_config(0,0); |
| 244 | db_begin_transaction(); |
| 245 | db_unprotect(PROTECT_CONFIG); |
| 246 | zOldProjCode = db_get("project-code",0); |
| 247 | fossil_print("Resuming clone of project-id %s\n",zOldProjCode); |
| 248 | db_multi_exec( |
| 249 | "DELETE FROM config WHERE name = 'project-code';" |
| 250 | "DELETE FROM config WHERE name = 'server-code';" |
| 251 | ); |
| 252 | db_protect_pop(); |
| 253 | db_initial_setup(0, 0, zDefaultUser); |
| 254 | user_select(); |
| 255 | }else{ |
| 256 | db_create_repository(zRepo); |
| 257 | db_open_repository(zRepo); |
| 258 | db_open_config(0,0); |
| @@ -290,38 +285,42 @@ | |
| 290 | url_get_password_if_needed(); |
| 291 | g.xlinkClusterOnly = 1; |
| 292 | while( nResumes++<3 && sync_interrupted()==0 |
| 293 | && (nErr = client_sync(syncFlags,CONFIGSET_ALL,0,0)) |
| 294 | ){ |
| 295 | if( sync_interrupted()!=0 ){ |
| 296 | fossil_warning("cloning encountered errors, trying again."); |
| 297 | sqlite3_sleep(500); |
| 298 | } |
| 299 | } |
| 300 | g.xlinkClusterOnly = 0; |
| 301 | verify_cancel(); |
| 302 | if( nErr ){ |
| 303 | fossil_warning("server returned an error - clone incomplete"); |
| 304 | }else if( sync_interrupted()==1 ){ |
| 305 | fossil_warning("clone was interrupted"); |
| 306 | }else{ |
| 307 | db_unprotect(PROTECT_CONFIG); |
| 308 | db_multi_exec("DELETE FROM config WHERE name = 'aux-clone-seqno';"); |
| 309 | db_protect_pop(); |
| 310 | } |
| 311 | zNewProjCode = db_get("project-code",0); |
| 312 | if( bResume && zOldProjCode && zOldProjCode[0] |
| 313 | && fossil_strcmp(zOldProjCode, zNewProjCode)!=0 ){ |
| 314 | fossil_warning("project-id changed\nwas %s\nis %s\nrolling back changes", |
| 315 | zOldProjCode, zNewProjCode); |
| 316 | db_end_transaction(1); |
| 317 | db_close(1); |
| 318 | fossil_exit(1); |
| 319 | }else{ |
| 320 | db_end_transaction(0); |
| 321 | db_close(1); |
| 322 | } |
| 323 | db_open_repository(zRepo); |
| 324 | #if !defined(_WIN32) |
| 325 | signal(SIGINT, SIG_DFL); |
| 326 | #endif |
| 327 | } |
| @@ -330,11 +329,11 @@ | |
| 330 | if( db_get_int("aux-clone-seqno",0)==0 ){ |
| 331 | fossil_fatal("there are unresolved deltas -" |
| 332 | " the clone is probabaly incomplete and unusable."); |
| 333 | } |
| 334 | } |
| 335 | if( db_get_int("aux-clone-seqno",0)>0 ){ |
| 336 | fossil_warning("It may be possible to resume the" |
| 337 | " clone by running the same command again."); |
| 338 | }else{ |
| 339 | fossil_print("Rebuilding repository meta-data...\n"); |
| 340 | rebuild_db(1, 0); |
| 341 |
| --- src/clone.c | |
| +++ src/clone.c | |
| @@ -151,11 +151,11 @@ | |
| 151 | int urlFlags = URL_PROMPT_PW | URL_REMEMBER; |
| 152 | int syncFlags = SYNC_CLONE; |
| 153 | int noCompress = find_option("nocompress",0,0)!=0; |
| 154 | int noOpen = find_option("no-open",0,0)!=0; |
| 155 | int allowNested = find_option("nested",0,0)!=0; /* Used by open */ |
| 156 | int nResumeSeqno = 0; /* Last seqno from which to resume clone */ |
| 157 | const char *zNewProjCode; /* New Project code obtained during clone */ |
| 158 | const char *zOldProjCode; /* Old project code stored in resuming clone */ |
| 159 | const char *zRepo = 0; /* Name of the new local repository file */ |
| 160 | const char *zWorkDir = 0; /* Open in this directory, if not zero */ |
| 161 | |
| @@ -204,13 +204,13 @@ | |
| 204 | } |
| 205 | fossil_free(zBase); |
| 206 | } |
| 207 | if( -1 != file_size(zRepo, ExtFILE) ){ |
| 208 | db_open_repository(zRepo); |
| 209 | nResumeSeqno = db_get_int("aux-clone-seqno",0); |
| 210 | db_close(0); |
| 211 | if( !nResumeSeqno ){ |
| 212 | fossil_fatal("file already exists: %s", zRepo); |
| 213 | } |
| 214 | } |
| 215 | /* Fail before clone if open will fail because inside an open check-out */ |
| 216 | if( zWorkDir!=0 && zWorkDir[0]!=0 && !noOpen ){ |
| @@ -236,23 +236,18 @@ | |
| 236 | g.zLogin = db_text(0, "SELECT login FROM user WHERE cap LIKE '%%s%%'"); |
| 237 | } |
| 238 | fossil_print("Repository cloned into %s\n", zRepo); |
| 239 | }else{ |
| 240 | db_close_config(); |
| 241 | if( nResumeSeqno>1 ){ |
| 242 | db_open_repository(zRepo); |
| 243 | db_open_config(0,0); |
| 244 | db_begin_transaction(); |
| 245 | zOldProjCode = db_get("project-code",0); |
| 246 | fossil_print("Resuming clone of project-id %s\n",zOldProjCode); |
| 247 | db_create_default_users(1, zDefaultUser); |
| 248 | if( zDefaultUser ) g.zLogin = zDefaultUser; |
| 249 | user_select(); |
| 250 | }else{ |
| 251 | db_create_repository(zRepo); |
| 252 | db_open_repository(zRepo); |
| 253 | db_open_config(0,0); |
| @@ -290,38 +285,42 @@ | |
| 285 | url_get_password_if_needed(); |
| 286 | g.xlinkClusterOnly = 1; |
| 287 | while( nResumes++<3 && sync_interrupted()==0 |
| 288 | && (nErr = client_sync(syncFlags,CONFIGSET_ALL,0,0)) |
| 289 | ){ |
| 290 | if( sync_interrupted() ) break; |
| 291 | if( db_get_int("aux-clone-seqno",1)==1 ){ |
| 292 | fossil_fatal("server returned an error - clone aborted"); |
| 293 | } |
| 294 | fossil_warning("cloning encountered errors, trying again."); |
| 295 | sqlite3_sleep(500); |
| 296 | } |
| 297 | g.xlinkClusterOnly = 0; |
| 298 | verify_cancel(); |
| 299 | if( nResumeSeqno>1 ){ |
| 300 | if( nResumeSeqno==db_get_int("aux-clone-seqno",0) ){ |
| 301 | fossil_fatal("No progress was made - aborting"); |
| 302 | } |
| 303 | zNewProjCode = db_get("project-code",0); |
| 304 | if( zOldProjCode && zOldProjCode[0] |
| 305 | && fossil_strcmp(zOldProjCode, zNewProjCode)!=0 ){ |
| 306 | fossil_fatal("project-id changed\nwas %s\nis %s" |
| 307 | "\nrolling back changes", |
| 308 | zOldProjCode, zNewProjCode); |
| 309 | } |
| 310 | } |
| 311 | if( nErr ){ |
| 312 | fossil_warning("server returned an error - clone incomplete"); |
| 313 | }else if( sync_interrupted()==1 ){ |
| 314 | fossil_warning("clone was interrupted"); |
| 315 | }else{ |
| 316 | db_unprotect(PROTECT_CONFIG); |
| 317 | db_multi_exec("DELETE FROM config WHERE name = 'aux-clone-seqno';"); |
| 318 | db_protect_pop(); |
| 319 | } |
| 320 | db_end_transaction(0); |
| 321 | db_close(1); |
| 322 | db_open_repository(zRepo); |
| 323 | #if !defined(_WIN32) |
| 324 | signal(SIGINT, SIG_DFL); |
| 325 | #endif |
| 326 | } |
| @@ -330,11 +329,11 @@ | |
| 329 | if( db_get_int("aux-clone-seqno",0)==0 ){ |
| 330 | fossil_fatal("there are unresolved deltas -" |
| 331 | " the clone is probabaly incomplete and unusable."); |
| 332 | } |
| 333 | } |
| 334 | if( db_get_int("aux-clone-seqno",0)>1 ){ |
| 335 | fossil_warning("It may be possible to resume the" |
| 336 | " clone by running the same command again."); |
| 337 | }else{ |
| 338 | fossil_print("Rebuilding repository meta-data...\n"); |
| 339 | rebuild_db(1, 0); |
| 340 |