1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Follow symlinks for profrc and accounts files

This commit is contained in:
James Booth 2014-10-26 20:43:05 +00:00
parent 7a88898a21
commit be7c4f5a00
4 changed files with 43 additions and 2 deletions

View File

@ -522,3 +522,28 @@ _data_callback(void *ptr, size_t size, size_t nmemb, void *data)
return realsize;
}
char*
get_file_or_linked(char *loc, char *basedir)
{
char *true_loc = NULL;
// check for symlink
if (g_file_test(loc, G_FILE_TEST_IS_SYMLINK)) {
true_loc = g_file_read_link(loc, NULL);
// if relative, add basedir
if (!g_str_has_prefix(true_loc, "/") && !g_str_has_prefix(true_loc, "~")) {
GString *base_str = g_string_new(basedir);
g_string_append(base_str, true_loc);
free(true_loc);
true_loc = base_str->str;
g_string_free(base_str, FALSE);
}
// use given location
} else {
true_loc = strdup(loc);
}
return true_loc;
}

View File

@ -116,4 +116,6 @@ char * create_unique_id(char *prefix);
int cmp_win_num(gconstpointer a, gconstpointer b);
int get_next_available_win_num(GList *used);
char* get_file_or_linked(char *loc, char *basedir);
#endif

View File

@ -808,9 +808,16 @@ _save_accounts(void)
{
gsize g_data_size;
gchar *g_accounts_data = g_key_file_to_data(accounts, &g_data_size, NULL);
g_file_set_contents(accounts_loc, g_accounts_data, g_data_size, NULL);
gchar *xdg_data = xdg_get_data_home();
GString *base_str = g_string_new(xdg_data);
g_string_append(base_str, "/profanity/");
gchar *true_loc = get_file_or_linked(accounts_loc, base_str->str);
g_file_set_contents(true_loc, g_accounts_data, g_data_size, NULL);
g_chmod(accounts_loc, S_IRUSR | S_IWUSR);
g_free(xdg_data);
free(true_loc);
g_free(g_accounts_data);
g_string_free(base_str, TRUE);
}
static gchar *

View File

@ -406,9 +406,16 @@ _save_prefs(void)
{
gsize g_data_size;
gchar *g_prefs_data = g_key_file_to_data(prefs, &g_data_size, NULL);
g_file_set_contents(prefs_loc, g_prefs_data, g_data_size, NULL);
gchar *xdg_config = xdg_get_config_home();
GString *base_str = g_string_new(xdg_config);
g_string_append(base_str, "/profanity/");
gchar *true_loc = get_file_or_linked(prefs_loc, base_str->str);
g_file_set_contents(true_loc, g_prefs_data, g_data_size, NULL);
g_chmod(prefs_loc, S_IRUSR | S_IWUSR);
g_free(xdg_config);
free(true_loc);
g_free(g_prefs_data);
g_string_free(base_str, TRUE);
}
static gchar *