ifnet: backup configuration files before writing (bgo #670508)

This commit is contained in:
Mu Qiao
2012-02-21 21:53:04 +08:00
committed by Dan Williams
parent cd867534da
commit 4641649cc1
4 changed files with 25 additions and 2 deletions

View File

@@ -576,6 +576,8 @@ ifnet_flush_to_file (const char *config_file)
if (!conn_table || !global_settings_table)
return FALSE;
backup_file (config_file);
channel = g_io_channel_new_file (config_file, "w", NULL);
if (!channel) {
PLUGIN_WARN (IFNET_PLUGIN_NAME,

View File

@@ -26,6 +26,7 @@
#include <errno.h>
#include <nm-utils.h>
#include <nm-system-config-interface.h>
#include <gio/gio.h>
#include "net_utils.h"
#include "wpa_parser.h"
#include "net_parser.h"
@@ -949,3 +950,20 @@ get_dhcp_hostname_and_client_id (char **hostname, char **client_id)
g_strfreev (all_lines);
g_free (contents);
}
void backup_file (gchar* target)
{
GFile *source, *backup;
gchar* backup_path;
GError **error;
source = g_file_new_for_path (target);
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)
PLUGIN_WARN (IFNET_PLUGIN_NAME, "Backup failed: %s", (*error)->message);
g_free (backup_path);
}

View File

@@ -77,4 +77,5 @@ gboolean is_true (const char *str);
void get_dhcp_hostname_and_client_id (char **hostname, char **client_id);
void backup_file (gchar* target);
#endif

View File

@@ -376,6 +376,8 @@ wpa_flush_to_file (const char *config_file)
if (!wsec_table || !wsec_global_table)
return FALSE;
backup_file (config_file);
channel = g_io_channel_new_file (config_file, "w", NULL);
if (!channel) {
PLUGIN_WARN (IFNET_PLUGIN_NAME,