[ostree/wip/packfile-rebase2] core: Add g_file_unlink()



commit 9cf071b83fbece04d44c43c0a59d71baba6e6289
Author: Colin Walters <walters verbum org>
Date:   Sat Mar 24 14:45:17 2012 -0400

    core: Add g_file_unlink()

 src/libotutil/ot-gio-utils.c |   28 ++++++++++++++++++++++++++++
 src/libotutil/ot-gio-utils.h |    4 ++++
 2 files changed, 32 insertions(+), 0 deletions(-)
---
diff --git a/src/libotutil/ot-gio-utils.c b/src/libotutil/ot-gio-utils.c
index 1c8c5dc..0ca520c 100644
--- a/src/libotutil/ot-gio-utils.c
+++ b/src/libotutil/ot-gio-utils.c
@@ -77,6 +77,34 @@ ot_gfile_ensure_directory (GFile     *dir,
   return ret;
 }
 
+/**
+ * ot_gfile_unlink:
+ * @path: Path to file
+ * @cancellable: a #GCancellable
+ * @error: a #GError
+ *
+ * Like g_file_delete(), except this function does not follow Unix
+ * symbolic links, and will delete a symbolic link even if it's
+ * pointing to a nonexistent file.
+ *
+ * Returns: %TRUE on success, %FALSE on error
+ */
+gboolean
+ot_gfile_unlink (GFile          *path,
+                 GCancellable   *cancellable,
+                 GError        **error)
+{
+  if (g_cancellable_set_error_if_cancelled (cancellable, error))
+    return FALSE;
+
+  if (unlink (ot_gfile_get_path_cached (path)) < 0)
+    {
+      ot_util_set_error_from_errno (error, errno);
+      return FALSE;
+    }
+  return TRUE;
+}
+
 gboolean
 ot_gfile_load_contents_utf8 (GFile         *file,
                              char         **contents_out,
diff --git a/src/libotutil/ot-gio-utils.h b/src/libotutil/ot-gio-utils.h
index 46c8e3c..9b837e1 100644
--- a/src/libotutil/ot-gio-utils.h
+++ b/src/libotutil/ot-gio-utils.h
@@ -44,6 +44,10 @@ const char *ot_gfile_get_basename_cached (GFile *file);
 
 gboolean ot_gfile_ensure_directory (GFile *dir, gboolean with_parents, GError **error);
 
+gboolean ot_gfile_unlink (GFile          *path,
+                          GCancellable   *cancellable,
+                          GError        **error);
+
 gboolean ot_gfile_load_contents_utf8 (GFile         *file,
                                       char         **contents_out,
                                       char         **etag_out,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]