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



commit c7190c25d30b1a1c3e8b0455279bce647c2a41d2
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 c3b6423..3c6bea8 100644
--- a/properties/import-export.c
+++ b/properties/import-export.c
@@ -1618,7 +1618,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;
@@ -1660,6 +1659,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);
@@ -2037,16 +2037,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]