summary refs log tree commit diff
path: root/src/settings/plugins/ifnet/net_utils.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2016-03-30 00:56:30 +0200
committerMichael Biebl <biebl@debian.org>2016-03-30 00:56:30 +0200
commitd9c99a29a0d3384c9c3d2adce430f5cb1134ab6a (patch)
treefa41baf72753961e71dd8d5bdbe2b89c9109e4f1 /src/settings/plugins/ifnet/net_utils.c
parentc2de0d98ba39e0a1a970d066fd19be786092f376 (diff)
Imported Upstream version 1.1.92 upstream/1.1.92
Diffstat (limited to 'src/settings/plugins/ifnet/net_utils.c')
-rw-r--r--src/settings/plugins/ifnet/net_utils.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/settings/plugins/ifnet/net_utils.c b/src/settings/plugins/ifnet/net_utils.c
index 1944e478..bd5d65d5 100644
--- a/src/settings/plugins/ifnet/net_utils.c
+++ b/src/settings/plugins/ifnet/net_utils.c
@@ -800,18 +800,27 @@ gchar *backup_file (const gchar* target)
 {
 	GFile *source, *backup;
 	gchar* backup_path;
-	GError **error = NULL;
+	GError *error = NULL;
 
 	source = g_file_new_for_path (target);
+
+	if (!g_file_query_exists (source, NULL)) {
+		g_object_unref (source);
+		return NULL;
+	}
+
 	backup_path = g_strdup_printf ("%s.bak", target);
 	backup = g_file_new_for_path (backup_path);
 
-	g_file_copy (source, backup, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, error);
-	if (error && *error) {
-		nm_log_warn (LOGD_SETTINGS, "Backup failed: %s", (*error)->message);
+	if (!g_file_copy (source, backup, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error)) {
+		nm_log_warn (LOGD_SETTINGS, "Backup failed: %s", error->message);
 		g_free (backup_path);
 		backup_path = NULL;
+		g_error_free (error);
 	}
 
+	g_object_unref (source);
+	g_object_unref (backup);
+
 	return backup_path;
 }