From 1ad29f5f698b1ee24500aabc76e902b85f93a27e Mon Sep 17 00:00:00 2001 From: Tomas Mlcoch Date: Fri, 17 Jan 2014 13:34:26 +0100 Subject: [PATCH] Remove .repodata on failure exits --- src/createrepo_c.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/createrepo_c.c b/src/createrepo_c.c index 85b8582..cffe1ca 100644 --- a/src/createrepo_c.c +++ b/src/createrepo_c.c @@ -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; -- 2.7.4