Blob Blame History Raw
From 865b0b958c044af966f89520ed97fad9b987f006 Mon Sep 17 00:00:00 2001
From: Jaroslav Rohel <jrohel@redhat.com>
Date: Thu, 5 Sep 2019 09:20:20 +0200
Subject: [PATCH 11/13] Expose dnf_copy_file and dnf_copy_recursive in private
 hpp

Renaming:
copyFile -> dnf_copy_file
copyRecursive -> dnf_copy_recursice

Exposes newnames in private hpp to be possible use it internally
in libdnf.

Closes: #789
Approved by: m-blaha
---
 libdnf/hy-iutil-private.hpp |  2 ++
 libdnf/hy-iutil.cpp         | 20 ++++++++++----------
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/libdnf/hy-iutil-private.hpp b/libdnf/hy-iutil-private.hpp
index 4920ad39..2d84cc21 100644
--- a/libdnf/hy-iutil-private.hpp
+++ b/libdnf/hy-iutil-private.hpp
@@ -41,6 +41,8 @@ char *abspath(const char *path);
 int is_readable_rpm(const char *fn);
 int mkcachedir(char *path);
 gboolean mv(const char *old_path, const char *new_path, GError **error);
+gboolean dnf_copy_file(const std::string & srcPath, const std::string & dstPath, GError ** error);
+gboolean dnf_copy_recursive(const std::string & srcPath, const std::string & dstPath, GError ** error);
 gboolean dnf_move_recursive(const gchar *src_dir, const gchar *dst_dir, GError **error);
 char *this_username(void);
 
diff --git a/libdnf/hy-iutil.cpp b/libdnf/hy-iutil.cpp
index d3b57c79..5401a9cf 100644
--- a/libdnf/hy-iutil.cpp
+++ b/libdnf/hy-iutil.cpp
@@ -333,18 +333,18 @@ mv(const char* old_path, const char* new_path, GError** error)
     return TRUE;
 }
 
-static gboolean
-copyFile(const std::string & srcPath, const std::string & dstPath, GError ** error)
+gboolean
+dnf_copy_file(const std::string & srcPath, const std::string & dstPath, GError ** error)
 {
     g_autoptr(GFile) src = g_file_new_for_path(srcPath.c_str());
     g_autoptr(GFile) dest = g_file_new_for_path(dstPath.c_str());
     return g_file_copy(src, dest,
-        static_cast<GFileCopyFlags>(G_FILE_COPY_NOFOLLOW_SYMLINKS | G_FILE_COPY_ALL_METADATA)
-        , NULL, NULL, NULL, error);
+        static_cast<GFileCopyFlags>(G_FILE_COPY_NOFOLLOW_SYMLINKS | G_FILE_COPY_ALL_METADATA),
+        NULL, NULL, NULL, error);
 }
 
-static gboolean
-copyRecursive(const std::string & srcPath, const std::string & dstPath, GError ** error)
+gboolean
+dnf_copy_recursive(const std::string & srcPath, const std::string & dstPath, GError ** error)
 {
     struct stat info;
     if (!stat(srcPath.c_str(), &info)) {
@@ -359,14 +359,14 @@ copyRecursive(const std::string & srcPath, const std::string & dstPath, GError *
                 return FALSE;
             }
             if (auto fd = opendir(srcPath.c_str())) {
-                int ret = TRUE;
+                gboolean ret = TRUE;
                 while (auto dent = readdir(fd)) {
                     auto name = dent->d_name;
                     if (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0')))
                         continue;
                     std::string srcItem = srcPath + "/" + name;
                     std::string dstItem = dstPath + "/" + name;
-                    ret = copyRecursive(srcItem, dstItem, error);
+                    ret = dnf_copy_recursive(srcItem, dstItem, error);
                     if (!ret)
                         break;
                 }
@@ -382,7 +382,7 @@ copyRecursive(const std::string & srcPath, const std::string & dstPath, GError *
                 return FALSE;
             }
         } else {
-            return copyFile(srcPath, dstPath, error);
+            return dnf_copy_file(srcPath, dstPath, error);
         }
     } else {
         auto err = errno;
@@ -410,7 +410,7 @@ gboolean
 dnf_move_recursive(const char * srcDir, const char * dstDir, GError ** error)
 {
     if (rename(srcDir, dstDir) == -1) {
-        if (!copyRecursive(srcDir, dstDir, error))
+        if (!dnf_copy_recursive(srcDir, dstDir, error))
             return FALSE;
         return dnf_remove_recursive(srcDir, error);
     }
-- 
2.21.0