Fossil SCM
Make "fossil test-integrity" and "fossil test-missing" exit with status 1 when they report an error, so that scripts can rely on them. With --parse, an artifact recorded as a check-in, wiki page, ticket, cluster or the like that fails to parse is an error.
Commit
ee8a2237f3ff041bb7f69d73063d7344dbdf5c02d3c99228fa8f903281a85170
Parent
516bb19ea81589e…
1 file changed
+16
-3
+16
-3
| --- src/content.c | ||
| +++ src/content.c | ||
| @@ -989,10 +989,12 @@ | ||
| 989 | 989 | ** |
| 990 | 990 | ** Verify that all content can be extracted from the BLOB table correctly. |
| 991 | 991 | ** If the BLOB table is correct, then the repository can always be |
| 992 | 992 | ** successfully reconstructed using "fossil rebuild". |
| 993 | 993 | ** |
| 994 | +** The exit status is 1 if any error is found. | |
| 995 | +** | |
| 994 | 996 | ** Options: |
| 995 | 997 | ** -d|--db-only Run "PRAGMA integrity_check" on the database only. |
| 996 | 998 | ** No other validation is performed. |
| 997 | 999 | ** --parse Parse all manifests, wikis, tickets, events, and |
| 998 | 1000 | ** so forth, reporting any errors found. |
| @@ -1010,14 +1012,14 @@ | ||
| 1010 | 1012 | int nPhantom = 0; |
| 1011 | 1013 | int anCA[10]; |
| 1012 | 1014 | int bParse = find_option("parse",0,0)!=0; |
| 1013 | 1015 | int bDbOnly = find_option("db-only","d",0)!=0; |
| 1014 | 1016 | int bQuick = find_option("quick",0,0)!=0; |
| 1017 | + char *zRes; | |
| 1015 | 1018 | db_find_and_open_repository(OPEN_ANY_SCHEMA, 2); |
| 1016 | 1019 | if( bDbOnly || bQuick ){ |
| 1017 | 1020 | const char *zType = bQuick ? "quick" : "integrity"; |
| 1018 | - char *zRes; | |
| 1019 | 1021 | zRes = db_text(0,"PRAGMA repository.%s_check", zType/*safe-for-%s*/); |
| 1020 | 1022 | if( fossil_strcmp(zRes,"ok")!=0 ){ |
| 1021 | 1023 | fossil_print("%s_check failed!\n", zType); |
| 1022 | 1024 | exit(1); |
| 1023 | 1025 | }else{ |
| @@ -1089,10 +1091,17 @@ | ||
| 1089 | 1091 | zFirstLine[i] = 0; |
| 1090 | 1092 | p = manifest_parse(&content, 0, &err); |
| 1091 | 1093 | if( p==0 ){ |
| 1092 | 1094 | fossil_print("manifest_parse failed for %s:\n%s\n", |
| 1093 | 1095 | zUuid, blob_str(&err)); |
| 1096 | + /* An ordinary file can look like a control artifact and fail to | |
| 1097 | + ** parse. That is an error only if the repository has it down | |
| 1098 | + ** as a check-in, wiki page, ticket or the like, or as a cluster. */ | |
| 1099 | + if( db_exists("SELECT 1 FROM event WHERE objid=%d" | |
| 1100 | + " UNION ALL" | |
| 1101 | + " SELECT 1 FROM tagxref WHERE rid=%d AND tagid=%d", | |
| 1102 | + rid, rid, TAG_CLUSTER) ) nErr++; | |
| 1094 | 1103 | if( strncmp(blob_str(&err), "line 1:", 7)==0 ){ |
| 1095 | 1104 | fossil_print("\"%s\"\n", zFirstLine); |
| 1096 | 1105 | } |
| 1097 | 1106 | }else{ |
| 1098 | 1107 | anCA[p->type]++; |
| @@ -1120,11 +1129,14 @@ | ||
| 1120 | 1129 | for(i=1; i<count(azType); i++){ |
| 1121 | 1130 | if( anCA[i] ) fossil_print(" %d %ss\n", anCA[i], azType[i]); |
| 1122 | 1131 | } |
| 1123 | 1132 | } |
| 1124 | 1133 | fossil_print("low-level database integrity-check: "); |
| 1125 | - fossil_print("%s\n", db_text(0, "PRAGMA integrity_check(10)")); | |
| 1134 | + zRes = db_text(0, "PRAGMA repository.integrity_check(10)"); | |
| 1135 | + fossil_print("%s\n", zRes); | |
| 1136 | + if( fossil_strcmp(zRes,"ok")!=0 ) nErr++; | |
| 1137 | + if( nErr ) fossil_exit(1); | |
| 1126 | 1138 | } |
| 1127 | 1139 | |
| 1128 | 1140 | /* |
| 1129 | 1141 | ** COMMAND: test-orphans |
| 1130 | 1142 | ** |
| @@ -1231,11 +1243,11 @@ | ||
| 1231 | 1243 | ** |
| 1232 | 1244 | ** Usage: %fossil test-missing |
| 1233 | 1245 | ** |
| 1234 | 1246 | ** Look at every artifact in the repository and verify that |
| 1235 | 1247 | ** all references are satisfied. Report any referenced artifacts |
| 1236 | -** that are missing or shunned. | |
| 1248 | +** that are missing or shunned. The exit status is 1 if any are found. | |
| 1237 | 1249 | ** |
| 1238 | 1250 | ** Options: |
| 1239 | 1251 | ** --notshunned Do not report shunned artifacts |
| 1240 | 1252 | ** -q|--quiet Only show output if there are errors |
| 1241 | 1253 | */ |
| @@ -1291,10 +1303,11 @@ | ||
| 1291 | 1303 | db_finalize(&q); |
| 1292 | 1304 | if( nErr>0 || quietFlag==0 ){ |
| 1293 | 1305 | fossil_print("%d missing or shunned references in %d control artifacts\n", |
| 1294 | 1306 | nErr, nArtifact); |
| 1295 | 1307 | } |
| 1308 | + if( nErr ) fossil_exit(1); | |
| 1296 | 1309 | } |
| 1297 | 1310 | |
| 1298 | 1311 | /* |
| 1299 | 1312 | ** COMMAND: test-content-erase |
| 1300 | 1313 | ** |
| 1301 | 1314 |
| --- src/content.c | |
| +++ src/content.c | |
| @@ -989,10 +989,12 @@ | |
| 989 | ** |
| 990 | ** Verify that all content can be extracted from the BLOB table correctly. |
| 991 | ** If the BLOB table is correct, then the repository can always be |
| 992 | ** successfully reconstructed using "fossil rebuild". |
| 993 | ** |
| 994 | ** Options: |
| 995 | ** -d|--db-only Run "PRAGMA integrity_check" on the database only. |
| 996 | ** No other validation is performed. |
| 997 | ** --parse Parse all manifests, wikis, tickets, events, and |
| 998 | ** so forth, reporting any errors found. |
| @@ -1010,14 +1012,14 @@ | |
| 1010 | int nPhantom = 0; |
| 1011 | int anCA[10]; |
| 1012 | int bParse = find_option("parse",0,0)!=0; |
| 1013 | int bDbOnly = find_option("db-only","d",0)!=0; |
| 1014 | int bQuick = find_option("quick",0,0)!=0; |
| 1015 | db_find_and_open_repository(OPEN_ANY_SCHEMA, 2); |
| 1016 | if( bDbOnly || bQuick ){ |
| 1017 | const char *zType = bQuick ? "quick" : "integrity"; |
| 1018 | char *zRes; |
| 1019 | zRes = db_text(0,"PRAGMA repository.%s_check", zType/*safe-for-%s*/); |
| 1020 | if( fossil_strcmp(zRes,"ok")!=0 ){ |
| 1021 | fossil_print("%s_check failed!\n", zType); |
| 1022 | exit(1); |
| 1023 | }else{ |
| @@ -1089,10 +1091,17 @@ | |
| 1089 | zFirstLine[i] = 0; |
| 1090 | p = manifest_parse(&content, 0, &err); |
| 1091 | if( p==0 ){ |
| 1092 | fossil_print("manifest_parse failed for %s:\n%s\n", |
| 1093 | zUuid, blob_str(&err)); |
| 1094 | if( strncmp(blob_str(&err), "line 1:", 7)==0 ){ |
| 1095 | fossil_print("\"%s\"\n", zFirstLine); |
| 1096 | } |
| 1097 | }else{ |
| 1098 | anCA[p->type]++; |
| @@ -1120,11 +1129,14 @@ | |
| 1120 | for(i=1; i<count(azType); i++){ |
| 1121 | if( anCA[i] ) fossil_print(" %d %ss\n", anCA[i], azType[i]); |
| 1122 | } |
| 1123 | } |
| 1124 | fossil_print("low-level database integrity-check: "); |
| 1125 | fossil_print("%s\n", db_text(0, "PRAGMA integrity_check(10)")); |
| 1126 | } |
| 1127 | |
| 1128 | /* |
| 1129 | ** COMMAND: test-orphans |
| 1130 | ** |
| @@ -1231,11 +1243,11 @@ | |
| 1231 | ** |
| 1232 | ** Usage: %fossil test-missing |
| 1233 | ** |
| 1234 | ** Look at every artifact in the repository and verify that |
| 1235 | ** all references are satisfied. Report any referenced artifacts |
| 1236 | ** that are missing or shunned. |
| 1237 | ** |
| 1238 | ** Options: |
| 1239 | ** --notshunned Do not report shunned artifacts |
| 1240 | ** -q|--quiet Only show output if there are errors |
| 1241 | */ |
| @@ -1291,10 +1303,11 @@ | |
| 1291 | db_finalize(&q); |
| 1292 | if( nErr>0 || quietFlag==0 ){ |
| 1293 | fossil_print("%d missing or shunned references in %d control artifacts\n", |
| 1294 | nErr, nArtifact); |
| 1295 | } |
| 1296 | } |
| 1297 | |
| 1298 | /* |
| 1299 | ** COMMAND: test-content-erase |
| 1300 | ** |
| 1301 |
| --- src/content.c | |
| +++ src/content.c | |
| @@ -989,10 +989,12 @@ | |
| 989 | ** |
| 990 | ** Verify that all content can be extracted from the BLOB table correctly. |
| 991 | ** If the BLOB table is correct, then the repository can always be |
| 992 | ** successfully reconstructed using "fossil rebuild". |
| 993 | ** |
| 994 | ** The exit status is 1 if any error is found. |
| 995 | ** |
| 996 | ** Options: |
| 997 | ** -d|--db-only Run "PRAGMA integrity_check" on the database only. |
| 998 | ** No other validation is performed. |
| 999 | ** --parse Parse all manifests, wikis, tickets, events, and |
| 1000 | ** so forth, reporting any errors found. |
| @@ -1010,14 +1012,14 @@ | |
| 1012 | int nPhantom = 0; |
| 1013 | int anCA[10]; |
| 1014 | int bParse = find_option("parse",0,0)!=0; |
| 1015 | int bDbOnly = find_option("db-only","d",0)!=0; |
| 1016 | int bQuick = find_option("quick",0,0)!=0; |
| 1017 | char *zRes; |
| 1018 | db_find_and_open_repository(OPEN_ANY_SCHEMA, 2); |
| 1019 | if( bDbOnly || bQuick ){ |
| 1020 | const char *zType = bQuick ? "quick" : "integrity"; |
| 1021 | zRes = db_text(0,"PRAGMA repository.%s_check", zType/*safe-for-%s*/); |
| 1022 | if( fossil_strcmp(zRes,"ok")!=0 ){ |
| 1023 | fossil_print("%s_check failed!\n", zType); |
| 1024 | exit(1); |
| 1025 | }else{ |
| @@ -1089,10 +1091,17 @@ | |
| 1091 | zFirstLine[i] = 0; |
| 1092 | p = manifest_parse(&content, 0, &err); |
| 1093 | if( p==0 ){ |
| 1094 | fossil_print("manifest_parse failed for %s:\n%s\n", |
| 1095 | zUuid, blob_str(&err)); |
| 1096 | /* An ordinary file can look like a control artifact and fail to |
| 1097 | ** parse. That is an error only if the repository has it down |
| 1098 | ** as a check-in, wiki page, ticket or the like, or as a cluster. */ |
| 1099 | if( db_exists("SELECT 1 FROM event WHERE objid=%d" |
| 1100 | " UNION ALL" |
| 1101 | " SELECT 1 FROM tagxref WHERE rid=%d AND tagid=%d", |
| 1102 | rid, rid, TAG_CLUSTER) ) nErr++; |
| 1103 | if( strncmp(blob_str(&err), "line 1:", 7)==0 ){ |
| 1104 | fossil_print("\"%s\"\n", zFirstLine); |
| 1105 | } |
| 1106 | }else{ |
| 1107 | anCA[p->type]++; |
| @@ -1120,11 +1129,14 @@ | |
| 1129 | for(i=1; i<count(azType); i++){ |
| 1130 | if( anCA[i] ) fossil_print(" %d %ss\n", anCA[i], azType[i]); |
| 1131 | } |
| 1132 | } |
| 1133 | fossil_print("low-level database integrity-check: "); |
| 1134 | zRes = db_text(0, "PRAGMA repository.integrity_check(10)"); |
| 1135 | fossil_print("%s\n", zRes); |
| 1136 | if( fossil_strcmp(zRes,"ok")!=0 ) nErr++; |
| 1137 | if( nErr ) fossil_exit(1); |
| 1138 | } |
| 1139 | |
| 1140 | /* |
| 1141 | ** COMMAND: test-orphans |
| 1142 | ** |
| @@ -1231,11 +1243,11 @@ | |
| 1243 | ** |
| 1244 | ** Usage: %fossil test-missing |
| 1245 | ** |
| 1246 | ** Look at every artifact in the repository and verify that |
| 1247 | ** all references are satisfied. Report any referenced artifacts |
| 1248 | ** that are missing or shunned. The exit status is 1 if any are found. |
| 1249 | ** |
| 1250 | ** Options: |
| 1251 | ** --notshunned Do not report shunned artifacts |
| 1252 | ** -q|--quiet Only show output if there are errors |
| 1253 | */ |
| @@ -1291,10 +1303,11 @@ | |
| 1303 | db_finalize(&q); |
| 1304 | if( nErr>0 || quietFlag==0 ){ |
| 1305 | fossil_print("%d missing or shunned references in %d control artifacts\n", |
| 1306 | nErr, nArtifact); |
| 1307 | } |
| 1308 | if( nErr ) fossil_exit(1); |
| 1309 | } |
| 1310 | |
| 1311 | /* |
| 1312 | ** COMMAND: test-content-erase |
| 1313 | ** |
| 1314 |