[network-manager-openvpn/th/export-bgo764132: 5/24] properties: use g_file_sets_contents() to write file in do_export()



commit 9eae6eae79b8cffbc3b32a4e1a341a286d0ea115
Author: Thomas Haller <thaller redhat com>
Date:   Wed Mar 23 18:31:45 2016 +0100

    properties: use g_file_sets_contents() to write file in do_export()

 properties/import-export.c |   16 +++++++---------
 1 files changed, 7 insertions(+), 9 deletions(-)
---
diff --git a/properties/import-export.c b/properties/import-export.c
index 8429131..0c47006 100644
--- a/properties/import-export.c
+++ b/properties/import-export.c
@@ -1616,7 +1616,6 @@ do_export (const char *path, NMConnection *connection, GError **error)
        NMSettingConnection *s_con;
        NMSettingIPConfig *s_ip4;
        NMSettingVpn *s_vpn;
-       FILE *ff;
        const char *value;
        const char *gateways = NULL;
        char **gw_list, **gw_iter;
@@ -1658,6 +1657,7 @@ do_export (const char *path, NMConnection *connection, GError **error)
        int i;
        guint num;
        nm_auto(_auto_free_gstring_p) GString *f = NULL;
+       gs_free_error GError *local = NULL;
 
        s_con = nm_connection_get_setting_connection (connection);
        g_assert (s_con);
@@ -2038,16 +2038,14 @@ do_export (const char *path, NMConnection *connection, GError **error)
        args_write_line (f, "user", "openvpn");
        args_write_line (f, "group", "openvpn");
 
-       ff = fopen (path, "w");
-       if (!ff) {
-               g_set_error_literal (error,
-                                    OPENVPN_EDITOR_PLUGIN_ERROR,
-                                    OPENVPN_EDITOR_PLUGIN_ERROR_FILE_NOT_OPENVPN,
-                                    _("could not open file for writing"));
+       if (!g_file_set_contents (path, f->str, f->len, &local)) {
+               g_set_error (error,
+                            OPENVPN_EDITOR_PLUGIN_ERROR,
+                            OPENVPN_EDITOR_PLUGIN_ERROR_FILE_NOT_OPENVPN,
+                            _("failed to write file: %s"),
+                            local->message);
                return FALSE;
        }
-       fprintf (ff, "%s", f->str);
-       fclose (ff);
 
        return TRUE;
 }


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