From 6cf6a1092384ca160e91db48d544eafc4faae5bc Mon Sep 17 00:00:00 2001 From: Tomas Mlcoch Date: Thu, 29 Nov 2012 12:20:26 +0100 Subject: [PATCH] Fix bug in final move from .repodata/ to repodata/ --- src/createrepo_c.c | 17 +++++++++++++---- src/mergerepo_c.c | 20 +++++++++++++++++--- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/createrepo_c.c b/src/createrepo_c.c index 60aca00..826fb9a 100644 --- a/src/createrepo_c.c +++ b/src/createrepo_c.c @@ -1168,7 +1168,6 @@ main(int argc, char **argv) // Move files from out_repo into tmp_out_repo g_debug("Moving data from %s", out_repo); - if (g_file_test(out_repo, G_FILE_TEST_EXISTS)) { // Delete old metadata @@ -1188,11 +1187,21 @@ main(int argc, char **argv) gchar *full_path = g_strconcat(out_repo, filename, NULL); gchar *new_full_path = g_strconcat(tmp_out_repo, filename, NULL); - if (g_rename(full_path, new_full_path) == -1) { + // Do not override new file with the old one + if (g_file_test(new_full_path, G_FILE_TEST_EXISTS)) { + g_debug("Skip move of: %s -> %s (the destination file already exists)", + full_path, new_full_path); + g_debug("Removing: %s", full_path); + g_remove(full_path); + g_free(full_path); + g_free(new_full_path); + continue; + } + + if (g_rename(full_path, new_full_path) == -1) g_critical("Cannot move file %s -> %s", full_path, new_full_path); - } else { + else g_debug("Moved %s -> %s", full_path, new_full_path); - } g_free(full_path); g_free(new_full_path); diff --git a/src/mergerepo_c.c b/src/mergerepo_c.c index 1f34131..fafdc55 100644 --- a/src/mergerepo_c.c +++ b/src/mergerepo_c.c @@ -1277,6 +1277,10 @@ dump_merged_metadata(GHashTable *merged_hashtable, g_debug("Moving data from %s", cmd_options->out_repo); if (g_file_test(cmd_options->out_repo, G_FILE_TEST_EXISTS)) { + // Delete old metadata + g_debug("Removing old metadata from %s", cmd_options->out_repo); + cr_remove_metadata_classic(cmd_options->out_dir, 0); + // Move files from out_repo to tmp_out_repo GDir *dirp; dirp = g_dir_open (cmd_options->out_repo, 0, NULL); @@ -1290,11 +1294,21 @@ dump_merged_metadata(GHashTable *merged_hashtable, gchar *full_path = g_strconcat(cmd_options->out_repo, filename, NULL); gchar *new_full_path = g_strconcat(cmd_options->tmp_out_repo, filename, NULL); - if (g_rename(full_path, new_full_path) == -1) { + // Do not override new file with the old one + if (g_file_test(new_full_path, G_FILE_TEST_EXISTS)) { + g_debug("Skip move of: %s -> %s (the destination file already exists)", + full_path, new_full_path); + g_debug("Removing: %s", full_path); + g_remove(full_path); + g_free(full_path); + g_free(new_full_path); + continue; + } + + if (g_rename(full_path, new_full_path) == -1) g_critical("Cannot move file %s -> %s", full_path, new_full_path); - } else { + else g_debug("Moved %s -> %s", full_path, new_full_path); - } g_free(full_path); g_free(new_full_path); -- 2.7.4