chantra / rpms / libdnf

Forked from rpms/libdnf 2 years ago
Clone

Blame SOURCES/0011-Expose-dnf_copy_file-and-dnf_copy_recursive-in-priva.patch

885e9e
From 865b0b958c044af966f89520ed97fad9b987f006 Mon Sep 17 00:00:00 2001
885e9e
From: Jaroslav Rohel <jrohel@redhat.com>
885e9e
Date: Thu, 5 Sep 2019 09:20:20 +0200
885e9e
Subject: [PATCH 11/13] Expose dnf_copy_file and dnf_copy_recursive in private
885e9e
 hpp
885e9e
885e9e
Renaming:
885e9e
copyFile -> dnf_copy_file
885e9e
copyRecursive -> dnf_copy_recursice
885e9e
885e9e
Exposes newnames in private hpp to be possible use it internally
885e9e
in libdnf.
885e9e
885e9e
Closes: #789
885e9e
Approved by: m-blaha
885e9e
---
885e9e
 libdnf/hy-iutil-private.hpp |  2 ++
885e9e
 libdnf/hy-iutil.cpp         | 20 ++++++++++----------
885e9e
 2 files changed, 12 insertions(+), 10 deletions(-)
885e9e
885e9e
diff --git a/libdnf/hy-iutil-private.hpp b/libdnf/hy-iutil-private.hpp
885e9e
index 4920ad39..2d84cc21 100644
885e9e
--- a/libdnf/hy-iutil-private.hpp
885e9e
+++ b/libdnf/hy-iutil-private.hpp
885e9e
@@ -41,6 +41,8 @@ char *abspath(const char *path);
885e9e
 int is_readable_rpm(const char *fn);
885e9e
 int mkcachedir(char *path);
885e9e
 gboolean mv(const char *old_path, const char *new_path, GError **error);
885e9e
+gboolean dnf_copy_file(const std::string & srcPath, const std::string & dstPath, GError ** error);
885e9e
+gboolean dnf_copy_recursive(const std::string & srcPath, const std::string & dstPath, GError ** error);
885e9e
 gboolean dnf_move_recursive(const gchar *src_dir, const gchar *dst_dir, GError **error);
885e9e
 char *this_username(void);
885e9e
 
885e9e
diff --git a/libdnf/hy-iutil.cpp b/libdnf/hy-iutil.cpp
885e9e
index d3b57c79..5401a9cf 100644
885e9e
--- a/libdnf/hy-iutil.cpp
885e9e
+++ b/libdnf/hy-iutil.cpp
885e9e
@@ -333,18 +333,18 @@ mv(const char* old_path, const char* new_path, GError** error)
885e9e
     return TRUE;
885e9e
 }
885e9e
 
885e9e
-static gboolean
885e9e
-copyFile(const std::string & srcPath, const std::string & dstPath, GError ** error)
885e9e
+gboolean
885e9e
+dnf_copy_file(const std::string & srcPath, const std::string & dstPath, GError ** error)
885e9e
 {
885e9e
     g_autoptr(GFile) src = g_file_new_for_path(srcPath.c_str());
885e9e
     g_autoptr(GFile) dest = g_file_new_for_path(dstPath.c_str());
885e9e
     return g_file_copy(src, dest,
885e9e
-        static_cast<GFileCopyFlags>(G_FILE_COPY_NOFOLLOW_SYMLINKS | G_FILE_COPY_ALL_METADATA)
885e9e
-        , NULL, NULL, NULL, error);
885e9e
+        static_cast<GFileCopyFlags>(G_FILE_COPY_NOFOLLOW_SYMLINKS | G_FILE_COPY_ALL_METADATA),
885e9e
+        NULL, NULL, NULL, error);
885e9e
 }
885e9e
 
885e9e
-static gboolean
885e9e
-copyRecursive(const std::string & srcPath, const std::string & dstPath, GError ** error)
885e9e
+gboolean
885e9e
+dnf_copy_recursive(const std::string & srcPath, const std::string & dstPath, GError ** error)
885e9e
 {
885e9e
     struct stat info;
885e9e
     if (!stat(srcPath.c_str(), &info)) {
885e9e
@@ -359,14 +359,14 @@ copyRecursive(const std::string & srcPath, const std::string & dstPath, GError *
885e9e
                 return FALSE;
885e9e
             }
885e9e
             if (auto fd = opendir(srcPath.c_str())) {
885e9e
-                int ret = TRUE;
885e9e
+                gboolean ret = TRUE;
885e9e
                 while (auto dent = readdir(fd)) {
885e9e
                     auto name = dent->d_name;
885e9e
                     if (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0')))
885e9e
                         continue;
885e9e
                     std::string srcItem = srcPath + "/" + name;
885e9e
                     std::string dstItem = dstPath + "/" + name;
885e9e
-                    ret = copyRecursive(srcItem, dstItem, error);
885e9e
+                    ret = dnf_copy_recursive(srcItem, dstItem, error);
885e9e
                     if (!ret)
885e9e
                         break;
885e9e
                 }
885e9e
@@ -382,7 +382,7 @@ copyRecursive(const std::string & srcPath, const std::string & dstPath, GError *
885e9e
                 return FALSE;
885e9e
             }
885e9e
         } else {
885e9e
-            return copyFile(srcPath, dstPath, error);
885e9e
+            return dnf_copy_file(srcPath, dstPath, error);
885e9e
         }
885e9e
     } else {
885e9e
         auto err = errno;
885e9e
@@ -410,7 +410,7 @@ gboolean
885e9e
 dnf_move_recursive(const char * srcDir, const char * dstDir, GError ** error)
885e9e
 {
885e9e
     if (rename(srcDir, dstDir) == -1) {
885e9e
-        if (!copyRecursive(srcDir, dstDir, error))
885e9e
+        if (!dnf_copy_recursive(srcDir, dstDir, error))
885e9e
             return FALSE;
885e9e
         return dnf_remove_recursive(srcDir, error);
885e9e
     }
885e9e
-- 
885e9e
2.21.0
885e9e