Remove .repodata on failure exits
authorTomas Mlcoch <tmlcoch@redhat.com>
Fri, 17 Jan 2014 12:34:26 +0000 (13:34 +0100)
committerTomas Mlcoch <tmlcoch@redhat.com>
Fri, 17 Jan 2014 12:34:26 +0000 (13:34 +0100)
src/createrepo_c.c

index 85b8582..cffe1ca 100644 (file)
@@ -109,14 +109,23 @@ struct BufferedTask {
 char *tmp_repodata_path = NULL;     // Path to temporary dir - /foo/bar/.repodata
 
 
+void
+failure_exit_cleanup(int exit_status, void *data)
+{
+    CR_UNUSED(data);
+    if ((exit_status != EXIT_SUCCESS) && tmp_repodata_path) {
+        g_debug("Removing %s", tmp_repodata_path);
+        cr_remove_dir(tmp_repodata_path, NULL);
+    }
+}
+
+
 // Signal handler
 void
 sigint_catcher(int sig)
 {
     CR_UNUSED(sig);
     g_message("SIGINT catched: Terminating...");
-    if (tmp_repodata_path)
-        cr_remove_dir(tmp_repodata_path, NULL);
     exit(1);
 }
 
@@ -732,11 +741,14 @@ main(int argc, char **argv)
         exit(EXIT_FAILURE);
     }
 
+    tmp_repodata_path = tmp_out_repo;
+
+    // Register cleanup function
+    if (on_exit(failure_exit_cleanup, NULL))
+        g_warning("Cannot set exit cleanup function by atexit()");
 
     // Set handler for sigint
 
-    tmp_repodata_path = tmp_out_repo;
-
     g_debug("SIGINT handler setup");
     struct sigaction sigact;
     sigact.sa_handler = sigint_catcher;