|
|
885e9e |
From 99d35011a057a112957c6e878f4ac0b7ab0d0e7a Mon Sep 17 00:00:00 2001
|
|
|
885e9e |
From: Jaroslav Rohel <jrohel@redhat.com>
|
|
|
885e9e |
Date: Tue, 3 Sep 2019 13:13:31 +0200
|
|
|
885e9e |
Subject: [PATCH 10/10] Use copy+delete fallback if moving of directory failed
|
|
|
885e9e |
(RhBug:1700341)
|
|
|
885e9e |
|
|
|
885e9e |
Uses dnf_move_recursive() instead of g_rename()/rename() for
|
|
|
885e9e |
move a directories.
|
|
|
885e9e |
The dnf_move_recursive() uses copy+delete fallback if native moving
|
|
|
885e9e |
of directory failed (eg. moving between filesystems, overlayfs).
|
|
|
885e9e |
|
|
|
885e9e |
https://bugzilla.redhat.com/show_bug.cgi?id=1700341
|
|
|
885e9e |
---
|
|
|
885e9e |
libdnf/dnf-repo.cpp | 19 +++++++++----------
|
|
|
885e9e |
libdnf/repo/Repo.cpp | 12 ++++++++----
|
|
|
885e9e |
2 files changed, 17 insertions(+), 14 deletions(-)
|
|
|
885e9e |
|
|
|
885e9e |
diff --git a/libdnf/dnf-repo.cpp b/libdnf/dnf-repo.cpp
|
|
|
885e9e |
index a358356a..568e4262 100644
|
|
|
885e9e |
--- a/libdnf/dnf-repo.cpp
|
|
|
885e9e |
+++ b/libdnf/dnf-repo.cpp
|
|
|
885e9e |
@@ -36,6 +36,7 @@
|
|
|
885e9e |
#include "conf/OptionBool.hpp"
|
|
|
885e9e |
|
|
|
885e9e |
#include "hy-repo-private.hpp"
|
|
|
885e9e |
+#include "hy-iutil-private.hpp"
|
|
|
885e9e |
|
|
|
885e9e |
#include <strings.h>
|
|
|
885e9e |
#include <fcntl.h>
|
|
|
885e9e |
@@ -1826,14 +1827,13 @@ dnf_repo_update(DnfRepo *repo,
|
|
|
885e9e |
|
|
|
885e9e |
/* move the packages directory from the old cache to the new cache */
|
|
|
885e9e |
if (g_file_test(priv->packages, G_FILE_TEST_EXISTS)) {
|
|
|
885e9e |
- rc = g_rename(priv->packages, priv->packages_tmp);
|
|
|
885e9e |
- if (rc != 0) {
|
|
|
885e9e |
- ret = FALSE;
|
|
|
885e9e |
+ ret = dnf_move_recursive(priv->packages, priv->packages_tmp, &error_local);
|
|
|
885e9e |
+ if (!ret) {
|
|
|
885e9e |
g_set_error(error,
|
|
|
885e9e |
DNF_ERROR,
|
|
|
885e9e |
DNF_ERROR_CANNOT_FETCH_SOURCE,
|
|
|
885e9e |
- "cannot move %s to %s",
|
|
|
885e9e |
- priv->packages, priv->packages_tmp);
|
|
|
885e9e |
+ "cannot move %s to %s: %s",
|
|
|
885e9e |
+ priv->packages, priv->packages_tmp, error_local->message);
|
|
|
885e9e |
goto out;
|
|
|
885e9e |
}
|
|
|
885e9e |
}
|
|
|
885e9e |
@@ -1844,14 +1844,13 @@ dnf_repo_update(DnfRepo *repo,
|
|
|
885e9e |
goto out;
|
|
|
885e9e |
|
|
|
885e9e |
/* rename .tmp actual name */
|
|
|
885e9e |
- rc = g_rename(priv->location_tmp, priv->location);
|
|
|
885e9e |
- if (rc != 0) {
|
|
|
885e9e |
- ret = FALSE;
|
|
|
885e9e |
+ ret = dnf_move_recursive(priv->location_tmp, priv->location, &error_local);
|
|
|
885e9e |
+ if (!ret) {
|
|
|
885e9e |
g_set_error(error,
|
|
|
885e9e |
DNF_ERROR,
|
|
|
885e9e |
DNF_ERROR_CANNOT_FETCH_SOURCE,
|
|
|
885e9e |
- "cannot move %s to %s",
|
|
|
885e9e |
- priv->location_tmp, priv->location);
|
|
|
885e9e |
+ "cannot move %s to %s: %s",
|
|
|
885e9e |
+ priv->location_tmp, priv->location, error_local->message);
|
|
|
885e9e |
goto out;
|
|
|
885e9e |
}
|
|
|
885e9e |
ret = lr_handle_setopt(priv->repo_handle, error,
|
|
|
885e9e |
diff --git a/libdnf/repo/Repo.cpp b/libdnf/repo/Repo.cpp
|
|
|
885e9e |
index 23638839..0dbeed8b 100644
|
|
|
885e9e |
--- a/libdnf/repo/Repo.cpp
|
|
|
885e9e |
+++ b/libdnf/repo/Repo.cpp
|
|
|
885e9e |
@@ -31,6 +31,7 @@
|
|
|
885e9e |
#include "../hy-iutil.h"
|
|
|
885e9e |
#include "../hy-repo-private.hpp"
|
|
|
885e9e |
#include "../hy-util-private.hpp"
|
|
|
885e9e |
+#include "../hy-iutil-private.hpp"
|
|
|
885e9e |
#include "../hy-types.h"
|
|
|
885e9e |
#include "libdnf/conf/ConfigParser.hpp"
|
|
|
885e9e |
#include "libdnf/utils/File.hpp"
|
|
|
885e9e |
@@ -1155,10 +1156,13 @@ void Repo::Impl::fetch(const std::string & destdir, std::unique_ptr<LrHandle> &&
|
|
|
885e9e |
}
|
|
|
885e9e |
}
|
|
|
885e9e |
auto tempElement = tmpdir + "/" + elName;
|
|
|
885e9e |
- if (rename(tempElement.c_str(), targetElement.c_str()) == -1) {
|
|
|
885e9e |
- const char * errTxt = strerror(errno);
|
|
|
885e9e |
- throw std::runtime_error(tfm::format(
|
|
|
885e9e |
- _("Cannot rename directory \"%s\" to \"%s\": %s"), tempElement, targetElement, errTxt));
|
|
|
885e9e |
+ GError * error = NULL;
|
|
|
885e9e |
+ if (!dnf_move_recursive(tempElement.c_str(), targetElement.c_str(), &error)) {
|
|
|
885e9e |
+ std::string errTxt = tfm::format(
|
|
|
885e9e |
+ _("Cannot rename directory \"%s\" to \"%s\": %s"),
|
|
|
885e9e |
+ tempElement, targetElement, error->message);
|
|
|
885e9e |
+ g_error_free(error);
|
|
|
885e9e |
+ throw std::runtime_error(errTxt);
|
|
|
885e9e |
}
|
|
|
885e9e |
}
|
|
|
885e9e |
}
|
|
|
885e9e |
--
|
|
|
885e9e |
2.21.0
|
|
|
885e9e |
|