1
0
Fork 0

Move all filepath handling to files.c

This commit is contained in:
James Booth 2016-07-24 21:35:12 +01:00
parent 29452f8f1b
commit a3a73cf003
19 changed files with 174 additions and 262 deletions

View File

@ -49,14 +49,13 @@
#include "xmpp/xmpp.h"
#include "xmpp/jid.h"
static gchar *accounts_loc;
static char *accounts_loc;
static GKeyFile *accounts;
static Autocomplete all_ac;
static Autocomplete enabled_ac;
static void _save_accounts(void);
static gchar* _get_accounts_file(void);
void
accounts_load(void)
@ -64,7 +63,7 @@ accounts_load(void)
log_info("Loading accounts");
all_ac = autocomplete_new();
enabled_ac = autocomplete_new();
accounts_loc = _get_accounts_file();
accounts_loc = files_get_data_path(FILE_ACCOUNTS);
if (g_file_test(accounts_loc, G_FILE_TEST_EXISTS)) {
g_chmod(accounts_loc, S_IRUSR | S_IWUSR);
@ -858,27 +857,13 @@ _save_accounts(void)
{
gsize g_data_size;
gchar *g_accounts_data = g_key_file_to_data(accounts, &g_data_size, NULL);
gchar *xdg_data = files_get_xdg_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);
gchar *base = g_path_get_basename(accounts_loc);
gchar *true_loc = get_file_or_linked(accounts_loc, base);
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);
g_free(base);
free(true_loc);
g_free(g_accounts_data);
g_string_free(base_str, TRUE);
}
static gchar*
_get_accounts_file(void)
{
gchar *xdg_data = files_get_xdg_data_home();
GString *logfile = g_string_new(xdg_data);
g_string_append(logfile, "/profanity/accounts");
gchar *result = strdup(logfile->str);
g_free(xdg_data);
g_string_free(logfile, TRUE);
return result;
}

View File

@ -35,18 +35,22 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <glib.h>
#include "common.h"
#include "log.h"
#include "config/files.h"
#include "config/preferences.h"
static char* _files_get_xdg_config_home(void);
static char* _files_get_xdg_data_home(void);
void
files_create_directories(void)
{
gchar *xdg_config = files_get_xdg_config_home();
gchar *xdg_data = files_get_xdg_data_home();
gchar *xdg_config = _files_get_xdg_config_home();
gchar *xdg_data = _files_get_xdg_data_home();
GString *themes_dir = g_string_new(xdg_config);
g_string_append(themes_dir, "/profanity/themes");
@ -85,17 +89,17 @@ files_create_directories(void)
g_free(xdg_data);
}
gchar*
files_get_inputrc_path(void)
char*
files_get_inputrc_file(void)
{
gchar *xdg_config = files_get_xdg_config_home();
gchar *xdg_config = _files_get_xdg_config_home();
GString *inputrc_file = g_string_new(xdg_config);
g_free(xdg_config);
g_string_append(inputrc_file, "/profanity/inputrc");
if (g_file_test(inputrc_file->str, G_FILE_TEST_IS_REGULAR)) {
gchar *result = strdup(inputrc_file->str);
char *result = strdup(inputrc_file->str);
g_string_free(inputrc_file, TRUE);
return result;
@ -106,8 +110,53 @@ files_get_inputrc_path(void)
return NULL;
}
gchar*
files_get_xdg_config_home(void)
char*
files_get_log_file(void)
{
gchar *xdg_data = _files_get_xdg_data_home();
GString *logfile = g_string_new(xdg_data);
g_string_append(logfile, "/profanity/logs/profanity");
if (!prefs_get_boolean(PREF_LOG_SHARED)) {
g_string_append_printf(logfile, "%d", getpid());
}
g_string_append(logfile, ".log");
char *result = strdup(logfile->str);
free(xdg_data);
g_string_free(logfile, TRUE);
return result;
}
char*
files_get_config_path(char *config_base)
{
gchar *xdg_config = _files_get_xdg_config_home();
GString *file_str = g_string_new(xdg_config);
g_string_append(file_str, "/profanity/");
g_string_append(file_str, config_base);
char *result = strdup(file_str->str);
g_free(xdg_config);
g_string_free(file_str, TRUE);
return result;
}
char*
files_get_data_path(char *data_base)
{
gchar *xdg_data = _files_get_xdg_data_home();
GString *file_str = g_string_new(xdg_data);
g_string_append(file_str, "/profanity/");
g_string_append(file_str, data_base);
char *result = strdup(file_str->str);
g_free(xdg_data);
g_string_free(file_str, TRUE);
return result;
}
static char*
_files_get_xdg_config_home(void)
{
gchar *xdg_config_home = getenv("XDG_CONFIG_HOME");
if (xdg_config_home)
@ -118,15 +167,15 @@ files_get_xdg_config_home(void)
} else {
GString *default_path = g_string_new(getenv("HOME"));
g_string_append(default_path, "/.config");
gchar *result = strdup(default_path->str);
char *result = strdup(default_path->str);
g_string_free(default_path, TRUE);
return result;
}
}
gchar*
files_get_xdg_data_home(void)
static char*
_files_get_xdg_data_home(void)
{
gchar *xdg_data_home = getenv("XDG_DATA_HOME");
if (xdg_data_home)

View File

@ -37,11 +37,27 @@
#include <glib.h>
#define FILE_PROFRC "profrc"
#define FILE_ACCOUNTS "accounts"
#define FILE_TLSCERTS "tlscerts"
#define FILE_PLUGIN_SETTINGS "plugin_settings"
#define FILE_PLUGIN_THEMES "plugin_themes"
#define FILE_CAPSCACHE "capscache"
#define DIR_THEMES "themes"
#define DIR_ICONS "icons"
#define DIR_SCRIPTS "scripts"
#define DIR_CHATLOGS "chatlogs"
#define DIR_OTR "otr"
#define DIR_PGP "pgp"
#define DIR_PLUGINS "plugins"
void files_create_directories(void);
gchar* files_get_inputrc_path(void);
char* files_get_config_path(char *config_base);
char* files_get_data_path(char *data_base);
gchar* files_get_xdg_config_home(void);
gchar* files_get_xdg_data_home(void);
char* files_get_log_file(void);
char* files_get_inputrc_file(void);
#endif

View File

@ -62,7 +62,7 @@
#define INPBLOCK_DEFAULT 1000
static gchar *prefs_loc;
static char *prefs_loc;
static GKeyFile *prefs;
gint log_maxsize = 0;
@ -70,7 +70,6 @@ static Autocomplete boolean_choice_ac;
static Autocomplete room_trigger_ac;
static void _save_prefs(void);
static gchar* _get_preferences_file(void);
static const char* _get_group(preference_t pref);
static const char* _get_key(preference_t pref);
static gboolean _get_default_boolean(preference_t pref);
@ -80,7 +79,7 @@ void
prefs_load(void)
{
GError *err;
prefs_loc = _get_preferences_file();
prefs_loc = files_get_config_path(FILE_PROFRC);
if (g_file_test(prefs_loc, G_FILE_TEST_EXISTS)) {
g_chmod(prefs_loc, S_IRUSR | S_IWUSR);
@ -1140,29 +1139,15 @@ _save_prefs(void)
{
gsize g_data_size;
gchar *g_prefs_data = g_key_file_to_data(prefs, &g_data_size, NULL);
gchar *xdg_config = files_get_xdg_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);
gchar *base = g_path_get_basename(prefs_loc);
gchar *true_loc = get_file_or_linked(prefs_loc, base);
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);
g_free(base);
free(true_loc);
g_free(g_prefs_data);
g_string_free(base_str, TRUE);
}
static gchar*
_get_preferences_file(void)
{
gchar *xdg_config = files_get_xdg_config_home();
GString *prefs_file = g_string_new(xdg_config);
g_string_append(prefs_file, "/profanity/profrc");
gchar *result = strdup(prefs_file->str);
g_free(xdg_config);
g_string_free(prefs_file, TRUE);
return result;
}
// get the preference group for a specific preference

View File

@ -51,38 +51,31 @@
void
scripts_init(void)
{
gchar *data_home = files_get_xdg_data_home();
GString *scriptsdir = g_string_new(data_home);
free(data_home);
g_string_append(scriptsdir, "/profanity/scripts");
char *scriptsdir = files_get_data_path(DIR_SCRIPTS);
// mkdir if doesn't exist
errno = 0;
int res = g_mkdir_with_parents(scriptsdir->str, S_IRWXU);
int res = g_mkdir_with_parents(scriptsdir, S_IRWXU);
if (res == -1) {
char *errmsg = strerror(errno);
if (errmsg) {
log_error("Error creating directory: %s, %s", scriptsdir->str, errmsg);
log_error("Error creating directory: %s, %s", scriptsdir, errmsg);
} else {
log_error("Error creating directory: %s", scriptsdir->str);
log_error("Error creating directory: %s", scriptsdir);
}
}
g_string_free(scriptsdir, TRUE);
free(scriptsdir);
}
GSList*
scripts_list(void)
{
gchar *data_home = files_get_xdg_data_home();
GString *scriptsdir = g_string_new(data_home);
free(data_home);
g_string_append(scriptsdir, "/profanity/scripts");
char *scriptsdir = files_get_data_path(DIR_SCRIPTS);
GSList *result = NULL;
GDir *scripts = g_dir_open(scriptsdir->str, 0, NULL);
g_string_free(scriptsdir, TRUE);
GDir *scripts = g_dir_open(scriptsdir, 0, NULL);
free(scriptsdir);
if (scripts) {
const gchar *script = g_dir_read_name(scripts);
@ -99,11 +92,10 @@ scripts_list(void)
GSList*
scripts_read(const char *const script)
{
gchar *data_home = files_get_xdg_data_home();
GString *scriptpath = g_string_new(data_home);
free(data_home);
g_string_append(scriptpath, "/profanity/scripts/");
char *scriptsdir = files_get_data_path(DIR_SCRIPTS);
GString *scriptpath = g_string_new(scriptsdir);
free(scriptsdir);
g_string_append(scriptpath, "/");
g_string_append(scriptpath, script);
FILE *scriptfile = g_fopen(scriptpath->str, "r");
@ -137,11 +129,10 @@ scripts_read(const char *const script)
gboolean
scripts_exec(const char *const script)
{
gchar *data_home = files_get_xdg_data_home();
GString *scriptpath = g_string_new(data_home);
free(data_home);
g_string_append(scriptpath, "/profanity/scripts/");
char *scriptsdir = files_get_data_path(DIR_SCRIPTS);
GString *scriptpath = g_string_new(scriptsdir);
free(scriptsdir);
g_string_append(scriptpath, "/");
g_string_append(scriptpath, script);
FILE *scriptfile = g_fopen(scriptpath->str, "r");

View File

@ -63,7 +63,6 @@ struct colour_string_t {
};
static void _load_preferences(void);
static gchar* _get_themes_dir(void);
void _theme_list_dir(const gchar *const dir, GSList **result);
static GString* _theme_find(const char *const theme_name);
static gboolean _theme_load_file(const char *const theme_name);
@ -218,7 +217,7 @@ GSList*
theme_list(void)
{
GSList *result = NULL;
char *themes_dir = _get_themes_dir();
char *themes_dir = files_get_config_path(DIR_THEMES);
_theme_list_dir(themes_dir, &result);
free(themes_dir);
#ifdef THEMES_PATH
@ -532,16 +531,6 @@ _load_preferences(void)
}
}
static gchar*
_get_themes_dir(void)
{
gchar *xdg_config = files_get_xdg_config_home();
GString *themes_dir = g_string_new(xdg_config);
g_free(xdg_config);
g_string_append(themes_dir, "/profanity/themes");
return g_string_free(themes_dir, FALSE);
}
void
_theme_list_dir(const gchar *const dir, GSList **result)
{
@ -560,11 +549,11 @@ static GString*
_theme_find(const char *const theme_name)
{
GString *path = NULL;
gchar *themes_dir = _get_themes_dir();
char *themes_dir = files_get_config_path(DIR_THEMES);
if (themes_dir) {
path = g_string_new(themes_dir);
g_free(themes_dir);
free(themes_dir);
g_string_append(path, "/");
g_string_append(path, theme_name);
if (!g_file_test(path->str, G_FILE_TEST_EXISTS)) {

View File

@ -44,10 +44,9 @@
#include "config/tlscerts.h"
#include "tools/autocomplete.h"
static gchar *tlscerts_loc;
static char *tlscerts_loc;
static GKeyFile *tlscerts;
static gchar* _get_tlscerts_file(void);
static void _save_tlscerts(void);
static Autocomplete certs_ac;
@ -58,7 +57,7 @@ void
tlscerts_init(void)
{
log_info("Loading TLS certificates");
tlscerts_loc = _get_tlscerts_file();
tlscerts_loc = files_get_data_path(FILE_TLSCERTS);
if (g_file_test(tlscerts_loc, G_FILE_TEST_EXISTS)) {
g_chmod(tlscerts_loc, S_IRUSR | S_IWUSR);
@ -429,19 +428,6 @@ tlscerts_close(void)
autocomplete_free(certs_ac);
}
static gchar*
_get_tlscerts_file(void)
{
gchar *xdg_data = files_get_xdg_data_home();
GString *tlscerts_file = g_string_new(xdg_data);
g_string_append(tlscerts_file, "/profanity/tlscerts");
gchar *result = strdup(tlscerts_file->str);
g_free(xdg_data);
g_string_free(tlscerts_file, TRUE);
return result;
}
static void
_save_tlscerts(void)
{

View File

@ -85,8 +85,6 @@ static gboolean _key_equals(void *key1, void *key2);
static char* _get_log_filename(const char *const other, const char *const login, GDateTime *dt, gboolean create);
static char* _get_groupchat_log_filename(const char *const room, const char *const login, GDateTime *dt,
gboolean create);
static gchar* _get_chatlog_dir(void);
static gchar* _get_main_log_file(void);
static void _rotate_log_file(void);
static char* _log_string_from_level(log_level_t level);
static void _chat_log_chat(const char *const login, const char *const other, const gchar *const msg,
@ -145,7 +143,7 @@ log_init(log_level_t filter)
{
level_filter = filter;
tz = g_time_zone_new_local();
gchar *log_file = _get_main_log_file();
char *log_file = files_get_log_file();
logp = fopen(log_file, "a");
g_chmod(log_file, S_IRUSR | S_IWUSR);
mainlogfile = g_string_new(log_file);
@ -226,7 +224,7 @@ log_level_from_string(char *log_level)
static void
_rotate_log_file(void)
{
gchar *log_file = _get_main_log_file();
char *log_file = files_get_log_file();
size_t len = strlen(log_file);
char *log_file_new = malloc(len + 3);
@ -572,7 +570,7 @@ gboolean _key_equals(void *key1, void *key2)
static char*
_get_log_filename(const char *const other, const char *const login, GDateTime *dt, gboolean create)
{
gchar *chatlogs_dir = _get_chatlog_dir();
char *chatlogs_dir = files_get_data_path(DIR_CHATLOGS);
GString *log_file = g_string_new(chatlogs_dir);
free(chatlogs_dir);
@ -603,9 +601,9 @@ _get_log_filename(const char *const other, const char *const login, GDateTime *d
static char*
_get_groupchat_log_filename(const char *const room, const char *const login, GDateTime *dt, gboolean create)
{
gchar *chatlogs_dir = _get_chatlog_dir();
char *chatlogs_dir = files_get_data_path(DIR_CHATLOGS);
GString *log_file = g_string_new(chatlogs_dir);
g_free(chatlogs_dir);
free(chatlogs_dir);
gchar *login_dir = str_replace(login, "@", "_at_");
g_string_append_printf(log_file, "/%s", login_dir);
@ -636,36 +634,6 @@ _get_groupchat_log_filename(const char *const room, const char *const login, GDa
return result;
}
static gchar*
_get_chatlog_dir(void)
{
gchar *xdg_data = files_get_xdg_data_home();
GString *chatlogs_dir = g_string_new(xdg_data);
g_string_append(chatlogs_dir, "/profanity/chatlogs");
gchar *result = strdup(chatlogs_dir->str);
free(xdg_data);
g_string_free(chatlogs_dir, TRUE);
return result;
}
static gchar*
_get_main_log_file(void)
{
gchar *xdg_data = files_get_xdg_data_home();
GString *logfile = g_string_new(xdg_data);
g_string_append(logfile, "/profanity/logs/profanity");
if (!prefs_get_boolean(PREF_LOG_SHARED)) {
g_string_append_printf(logfile, "%d", getpid());
}
g_string_append(logfile, ".log");
gchar *result = strdup(logfile->str);
free(xdg_data);
g_string_free(logfile, TRUE);
return result;
}
static char*
_log_string_from_level(log_level_t level)
{

View File

@ -126,12 +126,11 @@ cb_write_fingerprints(void *opdata)
{
gcry_error_t err = 0;
gchar *data_home = files_get_xdg_data_home();
GString *basedir = g_string_new(data_home);
free(data_home);
char *otrdir = files_get_data_path(DIR_OTR);
GString *basedir = g_string_new(otrdir);
free(otrdir);
gchar *account_dir = str_replace(jid, "@", "_at_");
g_string_append(basedir, "/profanity/otr/");
g_string_append(basedir, "/");
g_string_append(basedir, account_dir);
g_string_append(basedir, "/");
free(account_dir);
@ -215,12 +214,11 @@ otr_on_connect(ProfAccount *account)
jid = strdup(account->jid);
log_info("Loading OTR key for %s", jid);
gchar *data_home = files_get_xdg_data_home();
GString *basedir = g_string_new(data_home);
free(data_home);
char *otrdir = files_get_data_path(DIR_OTR);
GString *basedir = g_string_new(otrdir);
free(otrdir);
gchar *account_dir = str_replace(jid, "@", "_at_");
g_string_append(basedir, "/profanity/otr/");
g_string_append(basedir, "/");
g_string_append(basedir, account_dir);
g_string_append(basedir, "/");
free(account_dir);
@ -393,12 +391,11 @@ otr_keygen(ProfAccount *account)
jid = strdup(account->jid);
log_info("Generating OTR key for %s", jid);
gchar *data_home = files_get_xdg_data_home();
GString *basedir = g_string_new(data_home);
free(data_home);
char *otrdir = files_get_data_path(DIR_OTR);
GString *basedir = g_string_new(otrdir);
free(otrdir);
gchar *account_dir = str_replace(jid, "@", "_at_");
g_string_append(basedir, "/profanity/otr/");
g_string_append(basedir, "/");
g_string_append(basedir, account_dir);
g_string_append(basedir, "/");
free(account_dir);

View File

@ -157,12 +157,10 @@ p_gpg_close(void)
void
p_gpg_on_connect(const char *const barejid)
{
gchar *data_home = files_get_xdg_data_home();
GString *pubsfile = g_string_new(data_home);
free(data_home);
char *pgpdir = files_get_data_path(DIR_PGP);
GString *pubsfile = g_string_new(pgpdir);
gchar *account_dir = str_replace(barejid, "@", "_at_");
g_string_append(pubsfile, "/profanity/pgp/");
g_string_append(pubsfile, "/");
g_string_append(pubsfile, account_dir);
free(account_dir);

View File

@ -41,6 +41,7 @@
#include "log.h"
#include "config/preferences.h"
#include "config/files.h"
#include "plugins/api.h"
#include "plugins/callbacks.h"
#include "plugins/plugins.h"
@ -60,9 +61,9 @@ c_plugin_create(const char *const filename)
ProfPlugin *plugin;
void *handle = NULL;
gchar *plugins_dir = plugins_get_dir();
char *plugins_dir = files_get_data_path(DIR_PLUGINS);
GString *path = g_string_new(plugins_dir);
g_free(plugins_dir);
free(plugins_dir);
g_string_append(path, "/");
g_string_append(path, filename);

View File

@ -131,7 +131,7 @@ plugins_init(void)
gboolean
plugins_install(const char *const plugin_name, const char *const filename)
{
char *plugins_dir = plugins_get_dir();
char *plugins_dir = files_get_data_path(DIR_PLUGINS);
GString *target_path = g_string_new(plugins_dir);
free(plugins_dir);
g_string_append(target_path, "/");
@ -266,7 +266,7 @@ GSList*
plugins_unloaded_list(void)
{
GSList *result = NULL;
char *plugins_dir = plugins_get_dir();
char *plugins_dir = files_get_data_path(DIR_PLUGINS);
_plugins_unloaded_list_dir(plugins_dir, &result);
free(plugins_dir);
@ -830,16 +830,3 @@ plugins_shutdown(void)
callbacks_close();
disco_close();
}
char*
plugins_get_dir(void)
{
gchar *xdg_data = files_get_xdg_data_home();
GString *plugins_dir = g_string_new(xdg_data);
g_string_append(plugins_dir, "/profanity/plugins");
char *result = strdup(plugins_dir->str);
g_free(xdg_data);
g_string_free(plugins_dir, TRUE);
return result;
}

View File

@ -36,6 +36,7 @@
#include "config.h"
#include "config/preferences.h"
#include "config/files.h"
#include "plugins/api.h"
#include "plugins/callbacks.h"
#include "plugins/plugins.h"
@ -77,7 +78,7 @@ python_env_init(void)
python_init_prof();
gchar *plugins_dir = plugins_get_dir();
char *plugins_dir = files_get_data_path(DIR_PLUGINS);
GString *path = g_string_new("import sys\n");
g_string_append(path, "sys.path.append(\"");
g_string_append(path, plugins_dir);

View File

@ -49,24 +49,21 @@ static void _save_settings(void);
void
plugin_settings_init(void)
{
gchar *xdg_data = files_get_xdg_data_home();
GString *fileloc = g_string_new(xdg_data);
g_string_append(fileloc, "/profanity/plugin_settings");
g_free(xdg_data);
char *settings_file = files_get_data_path(FILE_PLUGIN_SETTINGS);
if (g_file_test(fileloc->str, G_FILE_TEST_EXISTS)) {
g_chmod(fileloc->str, S_IRUSR | S_IWUSR);
if (g_file_test(settings_file, G_FILE_TEST_EXISTS)) {
g_chmod(settings_file, S_IRUSR | S_IWUSR);
}
settings = g_key_file_new();
g_key_file_load_from_file(settings, fileloc->str, G_KEY_FILE_KEEP_COMMENTS, NULL);
g_key_file_load_from_file(settings, settings_file, G_KEY_FILE_KEEP_COMMENTS, NULL);
gsize g_data_size;
gchar *g_data = g_key_file_to_data(settings, &g_data_size, NULL);
g_file_set_contents(fileloc->str, g_data, g_data_size, NULL);
g_chmod(fileloc->str, S_IRUSR | S_IWUSR);
g_file_set_contents(settings_file, g_data, g_data_size, NULL);
g_chmod(settings_file, S_IRUSR | S_IWUSR);
g_free(g_data);
g_string_free(fileloc, TRUE);
free(settings_file);
}
void
@ -135,19 +132,13 @@ _save_settings(void)
gsize g_data_size;
gchar *g_data = g_key_file_to_data(settings, &g_data_size, NULL);
gchar *xdg_data = files_get_xdg_data_home();
GString *fileloc = g_string_new(xdg_data);
g_free(xdg_data);
g_string_append(fileloc, "/profanity/");
char *base = strdup(fileloc->str);
g_string_append(fileloc, "plugin_settings");
gchar *true_loc = get_file_or_linked(fileloc->str, base);
free(base);
char *fileloc = files_get_data_path(FILE_PLUGIN_SETTINGS);
gchar *base = g_path_get_basename(fileloc);
gchar *true_loc = get_file_or_linked(fileloc, base);
g_free(base);
g_file_set_contents(true_loc, g_data, g_data_size, NULL);
free(true_loc);
g_free(g_data);
g_chmod(fileloc->str, S_IRUSR | S_IWUSR);
g_string_free(fileloc, TRUE);
g_chmod(fileloc, S_IRUSR | S_IWUSR);
free(fileloc);
}

View File

@ -32,6 +32,8 @@
*
*/
#include <stdlib.h>
#include <glib.h>
#include <glib/gstdio.h>
@ -44,24 +46,21 @@ static GKeyFile *themes;
void
plugin_themes_init(void)
{
gchar *xdg_data = files_get_xdg_data_home();
GString *fileloc = g_string_new(xdg_data);
g_string_append(fileloc, "/profanity/plugin_themes");
g_free(xdg_data);
char *themes_file = files_get_data_path(FILE_PLUGIN_THEMES);
if (g_file_test(fileloc->str, G_FILE_TEST_EXISTS)) {
g_chmod(fileloc->str, S_IRUSR | S_IWUSR);
if (g_file_test(themes_file, G_FILE_TEST_EXISTS)) {
g_chmod(themes_file, S_IRUSR | S_IWUSR);
}
themes = g_key_file_new();
g_key_file_load_from_file(themes, fileloc->str, G_KEY_FILE_KEEP_COMMENTS, NULL);
g_key_file_load_from_file(themes, themes_file, G_KEY_FILE_KEEP_COMMENTS, NULL);
gsize g_data_size;
gchar *g_data = g_key_file_to_data(themes, &g_data_size, NULL);
g_file_set_contents(fileloc->str, g_data, g_data_size, NULL);
g_chmod(fileloc->str, S_IRUSR | S_IWUSR);
g_file_set_contents(themes_file, g_data, g_data_size, NULL);
g_chmod(themes_file, S_IRUSR | S_IWUSR);
g_free(g_data);
g_string_free(fileloc, TRUE);
free(themes_file);
}
void

View File

@ -428,7 +428,7 @@ _inp_rl_startup_hook(void)
rl_variable_bind("disable-completion", "on");
// check for and load ~/.config/profanity/inputrc
char *inputrc = files_get_inputrc_path();
char *inputrc = files_get_inputrc_file();
if (inputrc) {
rl_read_init_file(inputrc);
free(inputrc);

View File

@ -79,10 +79,8 @@ _get_icons(void)
#endif /* ICONS_PATH */
gchar *xdg_config = files_get_xdg_config_home();
icons_dir = g_string_new(xdg_config);
g_free(xdg_config);
g_string_append(icons_dir, "/profanity/icons");
char *icons_dir_s = files_get_config_path(DIR_ICONS);
icons_dir = g_string_new(icons_dir_s);
GError *err = NULL;
if (!g_file_test(icons_dir->str, G_FILE_TEST_IS_DIR)) {
return;

View File

@ -61,7 +61,7 @@
#include "xmpp/form.h"
#include "xmpp/capabilities.h"
static gchar *cache_loc;
static char *cache_loc;
static GKeyFile *cache;
static GHashTable *jid_to_ver;
@ -69,7 +69,6 @@ static GHashTable *jid_to_caps;
static char *my_sha1;
static gchar* _get_cache_file(void);
static void _save_cache(void);
static Capabilities* _caps_by_ver(const char *const ver);
static Capabilities* _caps_by_jid(const char *const jid);
@ -79,15 +78,14 @@ void
caps_init(void)
{
log_info("Loading capabilities cache");
cache_loc = _get_cache_file();
cache_loc = files_get_data_path(FILE_CAPSCACHE);
if (g_file_test(cache_loc, G_FILE_TEST_EXISTS)) {
g_chmod(cache_loc, S_IRUSR | S_IWUSR);
}
cache = g_key_file_new();
g_key_file_load_from_file(cache, cache_loc, G_KEY_FILE_KEEP_COMMENTS,
NULL);
g_key_file_load_from_file(cache, cache_loc, G_KEY_FILE_KEEP_COMMENTS, NULL);
jid_to_ver = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
jid_to_caps = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)caps_destroy);
@ -678,6 +676,8 @@ caps_close(void)
cache = NULL;
g_hash_table_destroy(jid_to_ver);
g_hash_table_destroy(jid_to_caps);
free(cache_loc);
cache_loc = NULL;
}
void
@ -698,19 +698,6 @@ caps_destroy(Capabilities *caps)
}
}
static gchar*
_get_cache_file(void)
{
gchar *xdg_data = files_get_xdg_data_home();
GString *cache_file = g_string_new(xdg_data);
g_string_append(cache_file, "/profanity/capscache");
gchar *result = strdup(cache_file->str);
g_free(xdg_data);
g_string_free(cache_file, TRUE);
return result;
}
static void
_save_cache(void)
{

View File

@ -15,17 +15,9 @@
void create_config_dir(void **state)
{
setenv("XDG_CONFIG_HOME", "./tests/files/xdg_config_home", 1);
gchar *xdg_config = files_get_xdg_config_home();
GString *profanity_dir = g_string_new(xdg_config);
g_string_append(profanity_dir, "/profanity");
if (!mkdir_recursive(profanity_dir->str)) {
if (!mkdir_recursive("./tests/files/xdg_config_home/profanity")) {
assert_true(FALSE);
}
g_free(xdg_config);
g_string_free(profanity_dir, TRUE);
}
void remove_config_dir(void **state)
@ -37,17 +29,9 @@ void remove_config_dir(void **state)
void create_data_dir(void **state)
{
setenv("XDG_DATA_HOME", "./tests/files/xdg_data_home", 1);
gchar *xdg_data = files_get_xdg_data_home();
GString *profanity_dir = g_string_new(xdg_data);
g_string_append(profanity_dir, "/profanity");
if (!mkdir_recursive(profanity_dir->str)) {
if (!mkdir_recursive("./tests/files/xdg_data_home/profanity")) {
assert_true(FALSE);
}
g_free(xdg_data);
g_string_free(profanity_dir, TRUE);
}
void remove_data_dir(void **state)