Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/rpm-software-management/createrepo_c.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleš Matěj <amatej@redhat.com>2021-11-02 16:28:49 +0300
committerNeal Gompa (ニール・ゴンパ) <ngompa13@gmail.com>2021-12-12 00:06:06 +0300
commitb49b8b2586c07d3e84009beba677162b86539f9d (patch)
treea746d94f797e193e1f65254731ba8c781c63808a
parentfc47e3f48d70b05fa7dab39103c0d5777f8fdf84 (diff)
Use copy+delete fallback when moving of a dir fails
For: https://github.com/rpm-software-management/createrepo_c/issues/266
-rw-r--r--src/createrepo_c.c8
-rw-r--r--src/dumper_thread.c4
-rw-r--r--src/mergerepo_c.c8
-rw-r--r--src/misc.c10
-rw-r--r--src/misc.h9
-rw-r--r--src/sqliterepo_c.c12
-rw-r--r--src/xml_file.c3
7 files changed, 36 insertions, 18 deletions
diff --git a/src/createrepo_c.c b/src/createrepo_c.c
index ae3baec..b96588c 100644
--- a/src/createrepo_c.c
+++ b/src/createrepo_c.c
@@ -2038,18 +2038,18 @@ deltaerror:
gchar *old_repodata_path = g_build_filename(out_dir, tmp_dirname, NULL);
g_free(tmp_dirname);
- if (g_rename(out_repo, old_repodata_path) == -1) {
+ if (!cr_move_recursive(out_repo, old_repodata_path, &tmp_err)) {
g_debug("Old repodata doesn't exists: Cannot rename %s -> %s: %s",
- out_repo, old_repodata_path, g_strerror(errno));
+ out_repo, old_repodata_path, tmp_err->message);
} else {
g_debug("Renamed %s -> %s", out_repo, old_repodata_path);
old_repodata_renamed = TRUE;
}
// Rename tmp_out_repo to out_repo
- if (g_rename(tmp_out_repo, out_repo) == -1) {
+ if (!cr_move_recursive(tmp_out_repo, out_repo, &tmp_err)) {
g_critical("Cannot rename %s -> %s: %s", tmp_out_repo, out_repo,
- g_strerror(errno));
+ tmp_err->message);
exit(EXIT_FAILURE);
} else {
g_debug("Renamed %s -> %s", tmp_out_repo, out_repo);
diff --git a/src/dumper_thread.c b/src/dumper_thread.c
index ea10c77..0a0da96 100644
--- a/src/dumper_thread.c
+++ b/src/dumper_thread.c
@@ -279,8 +279,10 @@ get_checksum(const char *filename,
write(fd, checksum, strlen(checksum));
close(fd);
- if (g_rename(template, cachefn) == -1)
+ if (!cr_move_recursive(template, cachefn, &tmp_err)) {
+ g_propagate_prefixed_error(err, tmp_err, "Error while renaming: ");
g_remove(template);
+ }
g_free(template);
}
diff --git a/src/mergerepo_c.c b/src/mergerepo_c.c
index fa26879..0e41890 100644
--- a/src/mergerepo_c.c
+++ b/src/mergerepo_c.c
@@ -1685,8 +1685,8 @@ dump_merged_metadata(GHashTable *merged_hashtable,
continue;
}
- if (g_rename(full_path, new_full_path) == -1)
- g_critical("Cannot move file %s -> %s", full_path, new_full_path);
+ if (!cr_move_recursive(full_path, new_full_path, &tmp_err))
+ g_critical("Cannot move file %s -> %s : %s", full_path, new_full_path, tmp_err->message);
else
g_debug("Moved %s -> %s", full_path, new_full_path);
@@ -1706,8 +1706,8 @@ dump_merged_metadata(GHashTable *merged_hashtable,
// Rename tmp_out_repo to out_repo
- if (g_rename(cmd_options->tmp_out_repo, cmd_options->out_repo) == -1) {
- g_critical("Cannot rename %s -> %s", cmd_options->tmp_out_repo, cmd_options->out_repo);
+ if (!cr_move_recursive(cmd_options->tmp_out_repo, cmd_options->out_repo, &tmp_err)) {
+ g_critical("Cannot rename %s -> %s : %s", cmd_options->tmp_out_repo, cmd_options->out_repo, tmp_err->message);
} else {
g_debug("Renamed %s -> %s", cmd_options->tmp_out_repo, cmd_options->out_repo);
}
diff --git a/src/misc.c b/src/misc.c
index 4144dbc..4c1ff2c 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -846,6 +846,16 @@ cr_remove_dir(const char *path, GError **err)
return CRE_OK;
}
+gboolean
+cr_move_recursive(const char *srcDir, const char *dstDir, GError **err)
+{
+ if (rename(srcDir, dstDir) == -1) {
+ if (!cr_cp(srcDir, dstDir, CR_CP_RECURSIVE, NULL, err))
+ return FALSE;
+ return (cr_remove_dir(srcDir, err) == CRE_OK);
+ }
+ return TRUE;
+}
// Return path with exactly one trailing '/'
char *
diff --git a/src/misc.h b/src/misc.h
index 60f1a0f..cb89539 100644
--- a/src/misc.h
+++ b/src/misc.h
@@ -251,6 +251,15 @@ gboolean cr_better_copy_file(const char *src,
*/
int cr_remove_dir(const char *path, GError **err);
+/** Move a directory and its contents. Native move is preferred,
+ * if not supported copy and delete fallback is used.
+ * @param srcDir A source directory path
+ * @param dstDir A destination directory path
+ * @param err GError **
+ * @return TRUE on success, FALSE otherwise
+ */
+gboolean cr_move_recursive(const char *srcDir, const char *dstDir, GError **err);
+
/** Normalize path (Path with exactly one trailing '/').
*@param path path
*@return mallocated string with normalized path or NULL
diff --git a/src/sqliterepo_c.c b/src/sqliterepo_c.c
index 06a2a65..e136e8a 100644
--- a/src/sqliterepo_c.c
+++ b/src/sqliterepo_c.c
@@ -637,10 +637,8 @@ move_results(const gchar *tmp_out_repo,
dst_path = g_build_filename(in_repo, filename, NULL);
// Move the file
- if (g_rename(src_path, dst_path) == -1) {
- g_set_error(err, CREATEREPO_C_ERROR, CRE_IO,
- "Cannot move: %s to: %s: %s",
- src_path, dst_path, g_strerror(errno));
+ if (!cr_move_recursive(src_path, dst_path, &tmp_err)) {
+ g_propagate_error(err, tmp_err);
return FALSE;
}
}
@@ -651,10 +649,8 @@ move_results(const gchar *tmp_out_repo,
_cleanup_free_ gchar *dst_path = NULL;
src_path = g_build_filename(tmp_out_repo, "repomd.xml", NULL);
dst_path = g_build_filename(in_repo, "repomd.xml", NULL);
- if (g_rename(src_path, dst_path) == -1) {
- g_set_error(err, CREATEREPO_C_ERROR, CRE_IO,
- "Cannot move: %s to: %s: %s",
- src_path, dst_path, g_strerror(errno));
+ if (!cr_move_recursive(src_path, dst_path, &tmp_err)) {
+ g_propagate_error(err, tmp_err);
return FALSE;
}
}
diff --git a/src/xml_file.c b/src/xml_file.c
index 32458aa..e369f51 100644
--- a/src/xml_file.c
+++ b/src/xml_file.c
@@ -26,6 +26,7 @@
#include "xml_dump.h"
#include "compression_wrapper.h"
#include "xml_dump_internal.h"
+#include "misc.h"
#define ERR_DOMAIN CREATEREPO_C_ERROR
@@ -485,7 +486,7 @@ cr_rewrite_header_package_count(gchar *original_filename,
return;
}
- if (g_rename(tmp_xml_filename, original_filename) == -1) {
+ if (!cr_move_recursive(tmp_xml_filename, original_filename, &tmp_err)) {
g_propagate_prefixed_error(err, tmp_err, "Error encountered while renaming:");
g_free(tmp_xml_filename);
return;