mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
Added modify counter which is increased every time something is changed
in configuration. Autosaving settings doesn't even try to save them if config isn't changed. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@871 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
532d6c1e9d
commit
a954fa03d0
@ -35,6 +35,7 @@ static GHashTable *settings;
|
|||||||
static char *last_error_msg;
|
static char *last_error_msg;
|
||||||
static int timeout_tag;
|
static int timeout_tag;
|
||||||
|
|
||||||
|
static int config_last_modifycounter;
|
||||||
static time_t config_last_mtime;
|
static time_t config_last_mtime;
|
||||||
static long config_last_size;
|
static long config_last_size;
|
||||||
static unsigned int config_last_checksum;
|
static unsigned int config_last_checksum;
|
||||||
@ -379,7 +380,8 @@ int settings_save(const char *fname)
|
|||||||
fname = mainconfig->fname;
|
fname = mainconfig->fname;
|
||||||
|
|
||||||
error = config_write(mainconfig, fname, 0660) != 0;
|
error = config_write(mainconfig, fname, 0660) != 0;
|
||||||
irssi_config_save_state(fname);
|
irssi_config_save_state(fname);
|
||||||
|
config_last_modifycounter = mainconfig->modifycounter;
|
||||||
if (error) {
|
if (error) {
|
||||||
str = g_strdup_printf(_("Couldn't save "
|
str = g_strdup_printf(_("Couldn't save "
|
||||||
"configuration file: %s"),
|
"configuration file: %s"),
|
||||||
@ -394,7 +396,8 @@ static void sig_autosave(void)
|
|||||||
{
|
{
|
||||||
char *fname, *str;
|
char *fname, *str;
|
||||||
|
|
||||||
if (!settings_get_bool("settings_autosave"))
|
if (!settings_get_bool("settings_autosave") ||
|
||||||
|
config_last_modifycounter == mainconfig->modifycounter)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!irssi_config_is_changed(NULL))
|
if (!irssi_config_is_changed(NULL))
|
||||||
@ -419,6 +422,7 @@ void settings_init(void)
|
|||||||
(GCompareFunc) g_str_equal);
|
(GCompareFunc) g_str_equal);
|
||||||
|
|
||||||
config_last_mtime = 0;
|
config_last_mtime = 0;
|
||||||
|
config_last_modifycounter = 0;
|
||||||
init_configfile();
|
init_configfile();
|
||||||
|
|
||||||
settings_add_bool("misc", "settings_autosave", TRUE);
|
settings_add_bool("misc", "settings_autosave", TRUE);
|
||||||
|
@ -46,12 +46,13 @@ typedef struct {
|
|||||||
struct _config_rec {
|
struct _config_rec {
|
||||||
char *fname;
|
char *fname;
|
||||||
int handle;
|
int handle;
|
||||||
int create_mode;
|
int create_mode;
|
||||||
|
int modifycounter; /* increase every time something is changed */
|
||||||
|
|
||||||
char *last_error;
|
char *last_error;
|
||||||
CONFIG_NODE *mainnode;
|
CONFIG_NODE *mainnode;
|
||||||
GHashTable *cache; /* path -> node (for querying) */
|
GHashTable *cache; /* path -> node (for querying) */
|
||||||
GHashTable *cache_nodes; /* node -> path (for removing) */
|
GHashTable *cache_nodes; /* node -> path (for removing) */
|
||||||
|
|
||||||
GScanner *scanner;
|
GScanner *scanner;
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ void config_node_remove(CONFIG_REC *rec, CONFIG_NODE *parent, CONFIG_NODE *node)
|
|||||||
g_return_if_fail(parent != NULL);
|
g_return_if_fail(parent != NULL);
|
||||||
g_return_if_fail(node != NULL);
|
g_return_if_fail(node != NULL);
|
||||||
|
|
||||||
|
rec->modifycounter++;
|
||||||
cache_remove(rec, node);
|
cache_remove(rec, node);
|
||||||
parent->value = g_slist_remove(parent->value, node);
|
parent->value = g_slist_remove(parent->value, node);
|
||||||
|
|
||||||
@ -114,6 +115,7 @@ void config_node_set_str(CONFIG_REC *rec, CONFIG_NODE *parent, const char *key,
|
|||||||
}
|
}
|
||||||
|
|
||||||
node->value = g_strdup(value);
|
node->value = g_strdup(value);
|
||||||
|
rec->modifycounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void config_node_set_int(CONFIG_NODE *parent, const char *key, int value)
|
void config_node_set_int(CONFIG_NODE *parent, const char *key, int value)
|
||||||
|
Loading…
Reference in New Issue
Block a user