richardphibel / rpms / libdnf

Forked from rpms/libdnf 2 years ago
Clone
Blob Blame History Raw
From 842c0057f82a587f8dd2649d920420b7d888fddf Mon Sep 17 00:00:00 2001
From: Jaroslav Rohel <jrohel@redhat.com>
Date: Thu, 5 Sep 2019 13:55:00 +0200
Subject: [PATCH 12/13] Add dnf_remove_recursive_v2() that support unlink of
 file

The dnf_remove_recursive() accepts only directory as argument.
The new function supports unlink of files.

Closes: #789
Approved by: m-blaha
---
 libdnf/hy-iutil-private.hpp |  1 +
 libdnf/hy-iutil.cpp         | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/libdnf/hy-iutil-private.hpp b/libdnf/hy-iutil-private.hpp
index 2d84cc21..bf1714e9 100644
--- a/libdnf/hy-iutil-private.hpp
+++ b/libdnf/hy-iutil-private.hpp
@@ -41,6 +41,7 @@ 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_remove_recursive_v2(const gchar *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);
diff --git a/libdnf/hy-iutil.cpp b/libdnf/hy-iutil.cpp
index 5401a9cf..e1a1906a 100644
--- a/libdnf/hy-iutil.cpp
+++ b/libdnf/hy-iutil.cpp
@@ -333,6 +333,24 @@ mv(const char* old_path, const char* new_path, GError** error)
     return TRUE;
 }
 
+/**
+ * dnf_remove_recursive_v2:
+ * @directory: A directory path
+ * @error: A #GError, or %NULL
+ *
+ * Removes a file or a directory and its contents.
+ *
+ * Returns: %FALSE if an error was set
+ **/
+gboolean
+dnf_remove_recursive_v2(const gchar *path, GError **error)
+{
+    if (g_file_test(path, G_FILE_TEST_IS_DIR))
+        return dnf_remove_recursive(path, error);
+    else
+        return dnf_ensure_file_unlinked(path, error);
+}
+
 gboolean
 dnf_copy_file(const std::string & srcPath, const std::string & dstPath, GError ** error)
 {
-- 
2.21.0