Blame SOURCES/0012-Add-dnf_remove_recursive_v2-that-support-unlink-of-f.patch

885e9e
From 842c0057f82a587f8dd2649d920420b7d888fddf Mon Sep 17 00:00:00 2001
885e9e
From: Jaroslav Rohel <jrohel@redhat.com>
885e9e
Date: Thu, 5 Sep 2019 13:55:00 +0200
885e9e
Subject: [PATCH 12/13] Add dnf_remove_recursive_v2() that support unlink of
885e9e
 file
885e9e
885e9e
The dnf_remove_recursive() accepts only directory as argument.
885e9e
The new function supports unlink of files.
885e9e
885e9e
Closes: #789
885e9e
Approved by: m-blaha
885e9e
---
885e9e
 libdnf/hy-iutil-private.hpp |  1 +
885e9e
 libdnf/hy-iutil.cpp         | 18 ++++++++++++++++++
885e9e
 2 files changed, 19 insertions(+)
885e9e
885e9e
diff --git a/libdnf/hy-iutil-private.hpp b/libdnf/hy-iutil-private.hpp
885e9e
index 2d84cc21..bf1714e9 100644
885e9e
--- a/libdnf/hy-iutil-private.hpp
885e9e
+++ b/libdnf/hy-iutil-private.hpp
885e9e
@@ -41,6 +41,7 @@ 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_remove_recursive_v2(const gchar *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
diff --git a/libdnf/hy-iutil.cpp b/libdnf/hy-iutil.cpp
885e9e
index 5401a9cf..e1a1906a 100644
885e9e
--- a/libdnf/hy-iutil.cpp
885e9e
+++ b/libdnf/hy-iutil.cpp
885e9e
@@ -333,6 +333,24 @@ mv(const char* old_path, const char* new_path, GError** error)
885e9e
     return TRUE;
885e9e
 }
885e9e
 
885e9e
+/**
885e9e
+ * dnf_remove_recursive_v2:
885e9e
+ * @directory: A directory path
885e9e
+ * @error: A #GError, or %NULL
885e9e
+ *
885e9e
+ * Removes a file or a directory and its contents.
885e9e
+ *
885e9e
+ * Returns: %FALSE if an error was set
885e9e
+ **/
885e9e
+gboolean
885e9e
+dnf_remove_recursive_v2(const gchar *path, GError **error)
885e9e
+{
885e9e
+    if (g_file_test(path, G_FILE_TEST_IS_DIR))
885e9e
+        return dnf_remove_recursive(path, error);
885e9e
+    else
885e9e
+        return dnf_ensure_file_unlinked(path, error);
885e9e
+}
885e9e
+
885e9e
 gboolean
885e9e
 dnf_copy_file(const std::string & srcPath, const std::string & dstPath, GError ** error)
885e9e
 {
885e9e
-- 
885e9e
2.21.0
885e9e