createrepo_c should exit nonzero if there are any errors.
authorNoel Burton-Krahn <noel@burton-krahn.com>
Mon, 19 Sep 2016 22:26:59 +0000 (15:26 -0700)
committerNoel Burton-Krahn <noel@burton-krahn.com>
Tue, 13 Dec 2016 23:34:20 +0000 (15:34 -0800)
Issue: https://github.com/rpm-software-management/createrepo_c/issues/58

src/createrepo_c.c
src/dumper_thread.c
src/dumper_thread.h

index 31864febdc57150320190b714f344eb48e072424..965cfc223814b1af87c28dac1b28d78f2b7e6ff3 100644 (file)
@@ -328,7 +328,7 @@ main(int argc, char **argv)
     struct CmdOptions *cmd_options;
     gboolean ret;
     GError *tmp_err = NULL;
-
+    int exit_val = EXIT_SUCCESS;
 
     // Arguments parsing
     cmd_options = parse_arguments(&argc, &argv, &tmp_err);
@@ -852,6 +852,7 @@ main(int argc, char **argv)
     user_data.deltatargetpackages = NULL;
     user_data.cut_dirs          = cmd_options->cut_dirs;
     user_data.location_prefix   = cmd_options->location_prefix;
+    user_data.had_errors        = 0;
 
     g_debug("Thread pool user data ready");
 
@@ -861,7 +862,13 @@ main(int argc, char **argv)
 
     // Wait until pool is finished
     g_thread_pool_free(pool, FALSE, TRUE);
-    g_message("Pool finished");
+
+    // if there were any errors, exit nonzero
+    if( user_data.had_errors ) {
+       exit_val = EXIT_FAILURE;
+    }
+
+    g_message("Pool finished%s", (user_data.had_errors ? " with errors" : ""));
 
     cr_xml_dump_cleanup();
 
@@ -1347,5 +1354,5 @@ deltaerror:
     cr_package_parser_cleanup();
 
     g_debug("All done");
-    exit(EXIT_SUCCESS);
+    exit(exit_val);
 }
index eff7e0bc38c593af481d1ea8b8edabfe5fc2bc93..fbaa5be2a92ac95929c669970fd7aac40e925bce 100644 (file)
@@ -79,6 +79,7 @@ write_pkg(long id,
     if (tmp_err) {
         g_critical("Cannot add primary chunk:\n%s\nError: %s",
                    res.primary, tmp_err->message);
+        udata->had_errors = TRUE;
         g_clear_error(&tmp_err);
     }
 
@@ -87,6 +88,7 @@ write_pkg(long id,
         if (tmp_err) {
             g_critical("Cannot add record of %s (%s) to primary db: %s",
                        pkg->name, pkg->pkgId, tmp_err->message);
+            udata->had_errors = TRUE;
             g_clear_error(&tmp_err);
         }
     }
@@ -103,6 +105,7 @@ write_pkg(long id,
     if (tmp_err) {
         g_critical("Cannot add filelists chunk:\n%s\nError: %s",
                    res.filelists, tmp_err->message);
+        udata->had_errors = TRUE;
         g_clear_error(&tmp_err);
     }
 
@@ -111,6 +114,7 @@ write_pkg(long id,
         if (tmp_err) {
             g_critical("Cannot add record of %s (%s) to filelists db: %s",
                        pkg->name, pkg->pkgId, tmp_err->message);
+            udata->had_errors = TRUE;
             g_clear_error(&tmp_err);
         }
     }
@@ -127,6 +131,7 @@ write_pkg(long id,
     if (tmp_err) {
         g_critical("Cannot add other chunk:\n%s\nError: %s",
                    res.other, tmp_err->message);
+        udata->had_errors = TRUE;
         g_clear_error(&tmp_err);
     }
 
@@ -135,6 +140,7 @@ write_pkg(long id,
         if (tmp_err) {
             g_critical("Cannot add record of %s (%s) to other db: %s",
                        pkg->name, pkg->pkgId, tmp_err->message);
+            udata->had_errors = TRUE;
             g_clear_error(&tmp_err);
         }
     }
@@ -416,6 +422,7 @@ cr_dumper_thread(gpointer data, gpointer user_data)
         if (!pkg) {
             g_warning("Cannot read package: %s: %s",
                       task->full_path, tmp_err->message);
+            udata->had_errors = TRUE;
             g_clear_error(&tmp_err);
             goto task_cleanup;
         }
@@ -424,6 +431,7 @@ cr_dumper_thread(gpointer data, gpointer user_data)
         if (tmp_err) {
             g_critical("Cannot dump XML for %s (%s): %s",
                        pkg->name, pkg->pkgId, tmp_err->message);
+            udata->had_errors = TRUE;
             g_clear_error(&tmp_err);
             goto task_cleanup;
         }
@@ -434,6 +442,7 @@ cr_dumper_thread(gpointer data, gpointer user_data)
         if (tmp_err) {
             g_critical("Cannot dump XML for %s (%s): %s",
                        md->name, md->pkgId, tmp_err->message);
+            udata->had_errors = TRUE;
             g_clear_error(&tmp_err);
             goto task_cleanup;
         }
@@ -572,5 +581,3 @@ task_cleanup:
 
     return;
 }
-
-
index eaee5101959ead0462c838e87a23c24fc5f17e35..ed2105342fa12f69e352f423190c89710a7429d3 100644 (file)
@@ -94,6 +94,7 @@ struct UserData {
                                     // in location href path
     gchar *location_prefix;         // Append this prefix into location_href
                                     // during repodata generation
+    gboolean had_errors;            // Any errors encountered?
 };