[gnome-software] Add two utility functions for plugins
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Add two utility functions for plugins
- Date: Tue, 7 Jun 2016 14:22:49 +0000 (UTC)
commit 4c59a3edc7d597cf7b8135b5ee5643dfb564c5f0
Author: Richard Hughes <richard hughsie com>
Date: Tue Jun 7 15:21:15 2016 +0100
Add two utility functions for plugins
src/gs-utils.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
src/gs-utils.h | 5 +++++
2 files changed, 56 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-utils.c b/src/gs-utils.c
index 12d03ea..08430f5 100644
--- a/src/gs-utils.c
+++ b/src/gs-utils.c
@@ -34,6 +34,7 @@
#include <errno.h>
#include <fnmatch.h>
+#include <glib/gstdio.h>
#ifdef HAVE_POLKIT
#include <polkit/polkit.h>
@@ -306,4 +307,54 @@ gs_utils_get_desktop_app_info (const gchar *id)
return app_info;
}
+/**
+ * gs_utils_symlink:
+ * @target: the full path of the symlink to create
+ * @source: where the symlink should point to
+ * @error: A #GError, or %NULL
+ *
+ * Creates a symlink that can cross filesystem boundaries.
+ * Any parent directories needed for target to exist are also created.
+ *
+ * Returns: %TRUE for success
+ **/
+gboolean
+gs_utils_symlink (const gchar *target, const gchar *linkpath, GError **error)
+{
+ if (!gs_mkdir_parent (target, error))
+ return FALSE;
+ if (symlink (target, linkpath) != 0) {
+ g_set_error (error,
+ GS_PLUGIN_ERROR,
+ GS_PLUGIN_ERROR_FAILED,
+ "failed to create symlink from %s to %s",
+ linkpath, target);
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/**
+ * gs_utils_unlink:
+ * @filename: A full pathname to delete
+ * @error: A #GError, or %NULL
+ *
+ * Deletes a file from disk.
+ *
+ * Returns: %TRUE for success
+ **/
+gboolean
+gs_utils_unlink (const gchar *filename, GError **error)
+{
+ if (g_unlink (filename) != 0) {
+ g_set_error (error,
+ GS_PLUGIN_ERROR,
+ GS_PLUGIN_ERROR_FAILED,
+ "failed to delete %s",
+ filename);
+ return FALSE;
+ }
+ return TRUE;
+}
+
/* vim: set noexpandtab: */
diff --git a/src/gs-utils.h b/src/gs-utils.h
index ee55388..8fd1f3d 100644
--- a/src/gs-utils.h
+++ b/src/gs-utils.h
@@ -47,6 +47,11 @@ guint gs_utils_get_file_age (GFile *file);
gchar *gs_utils_get_content_type (GFile *file,
GCancellable *cancellable,
GError **error);
+gboolean gs_utils_symlink (const gchar *target,
+ const gchar *linkpath,
+ GError **error);
+gboolean gs_utils_unlink (const gchar *filename,
+ GError **error);
gboolean gs_mkdir_parent (const gchar *path,
GError **error);
gchar *gs_utils_get_cache_filename (const gchar *kind,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]