ifnet: backup configuration files before writing (bgo #670508)
This commit is contained in:
@@ -576,6 +576,8 @@ ifnet_flush_to_file (const char *config_file)
|
|||||||
if (!conn_table || !global_settings_table)
|
if (!conn_table || !global_settings_table)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
backup_file (config_file);
|
||||||
|
|
||||||
channel = g_io_channel_new_file (config_file, "w", NULL);
|
channel = g_io_channel_new_file (config_file, "w", NULL);
|
||||||
if (!channel) {
|
if (!channel) {
|
||||||
PLUGIN_WARN (IFNET_PLUGIN_NAME,
|
PLUGIN_WARN (IFNET_PLUGIN_NAME,
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <nm-utils.h>
|
#include <nm-utils.h>
|
||||||
#include <nm-system-config-interface.h>
|
#include <nm-system-config-interface.h>
|
||||||
|
#include <gio/gio.h>
|
||||||
#include "net_utils.h"
|
#include "net_utils.h"
|
||||||
#include "wpa_parser.h"
|
#include "wpa_parser.h"
|
||||||
#include "net_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_strfreev (all_lines);
|
||||||
g_free (contents);
|
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);
|
||||||
|
}
|
||||||
|
@@ -77,4 +77,5 @@ gboolean is_true (const char *str);
|
|||||||
|
|
||||||
void get_dhcp_hostname_and_client_id (char **hostname, char **client_id);
|
void get_dhcp_hostname_and_client_id (char **hostname, char **client_id);
|
||||||
|
|
||||||
|
void backup_file (gchar* target);
|
||||||
#endif
|
#endif
|
||||||
|
@@ -376,6 +376,8 @@ wpa_flush_to_file (const char *config_file)
|
|||||||
if (!wsec_table || !wsec_global_table)
|
if (!wsec_table || !wsec_global_table)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
backup_file (config_file);
|
||||||
|
|
||||||
channel = g_io_channel_new_file (config_file, "w", NULL);
|
channel = g_io_channel_new_file (config_file, "w", NULL);
|
||||||
if (!channel) {
|
if (!channel) {
|
||||||
PLUGIN_WARN (IFNET_PLUGIN_NAME,
|
PLUGIN_WARN (IFNET_PLUGIN_NAME,
|
||||||
|
Reference in New Issue
Block a user