mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
add files_file_in_account_data_path()
As all parts of the code invoking the `files_get_account_data_path()` function did the same afterwards, a function has been added with the same behavior. 1. create path 2. `mkdir` of that path 3. return final path Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
This commit is contained in:
parent
764a7fb71b
commit
b8e46552bf
@ -38,6 +38,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "common.h"
|
||||
@ -191,6 +193,25 @@ files_get_account_data_path(const char* const specific_dir, const char* const ji
|
||||
return result;
|
||||
}
|
||||
|
||||
gchar*
|
||||
files_file_in_account_data_path(const char* const specific_dir, const char* const jid, const char* const file_name)
|
||||
{
|
||||
gchar* data_path = files_get_account_data_path(specific_dir, jid);
|
||||
|
||||
if (g_mkdir_with_parents(data_path, S_IRWXU) != 0) {
|
||||
log_error("Failed to create directory at '%s' with error '%s'", data_path, strerror(errno));
|
||||
g_free(data_path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!file_name) {
|
||||
return data_path;
|
||||
}
|
||||
gchar* filename = g_strdup_printf("%s/%s", data_path, file_name);
|
||||
g_free(data_path);
|
||||
return filename;
|
||||
}
|
||||
|
||||
static char*
|
||||
_files_get_xdg_config_home(void)
|
||||
{
|
||||
|
@ -69,4 +69,7 @@ gchar* files_get_account_data_path(const char* const specific_dir, const char* c
|
||||
gchar* files_get_log_file(const char* const log_file);
|
||||
gchar* files_get_inputrc_file(void);
|
||||
|
||||
gchar*
|
||||
files_file_in_account_data_path(const char* const specific_dir, const char* const jid, const char* const file_name);
|
||||
|
||||
#endif
|
||||
|
@ -56,27 +56,7 @@ static prof_msg_type_t _get_message_type_type(const char* const type);
|
||||
static char*
|
||||
_get_db_filename(ProfAccount* account)
|
||||
{
|
||||
gchar* database_dir = files_get_account_data_path(DIR_DATABASE, account->jid);
|
||||
|
||||
int res = g_mkdir_with_parents(database_dir, S_IRWXU);
|
||||
if (res == -1) {
|
||||
const char* errmsg = strerror(errno);
|
||||
if (errmsg) {
|
||||
log_error("DATABASE: error creating directory: %s, %s", database_dir, errmsg);
|
||||
} else {
|
||||
log_error("DATABASE: creating directory: %s", database_dir);
|
||||
}
|
||||
g_free(database_dir);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GString* chatlog_filename = g_string_new(database_dir);
|
||||
g_string_append(chatlog_filename, "/chatlog.db");
|
||||
gchar* result = g_strdup(chatlog_filename->str);
|
||||
g_string_free(chatlog_filename, TRUE);
|
||||
g_free(database_dir);
|
||||
|
||||
return result;
|
||||
return files_file_in_account_data_path(DIR_DATABASE, account->jid, "chatlog.db");
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
@ -231,7 +231,11 @@ omemo_on_connect(ProfAccount* account)
|
||||
omemo_ctx.device_list_handler = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
|
||||
omemo_ctx.known_devices = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_g_hash_table_free);
|
||||
|
||||
gchar* omemo_dir = files_get_account_data_path(DIR_OMEMO, account->jid);
|
||||
gchar* omemo_dir = files_file_in_account_data_path(DIR_OMEMO, account->jid, NULL);
|
||||
if (!omemo_dir) {
|
||||
log_error("[OMEMO] failed creating directory");
|
||||
return;
|
||||
}
|
||||
|
||||
omemo_ctx.identity_filename = g_string_new(omemo_dir);
|
||||
g_string_append(omemo_ctx.identity_filename, "/identity.txt");
|
||||
@ -242,17 +246,6 @@ omemo_on_connect(ProfAccount* account)
|
||||
omemo_ctx.known_devices_filename = g_string_new(omemo_dir);
|
||||
g_string_append(omemo_ctx.known_devices_filename, "/known_devices.txt");
|
||||
|
||||
errno = 0;
|
||||
int res = g_mkdir_with_parents(omemo_dir, S_IRWXU);
|
||||
if (res == -1) {
|
||||
const char* errmsg = strerror(errno);
|
||||
if (errmsg) {
|
||||
log_error("[OMEMO] error creating directory: %s, %s", omemo_dir, errmsg);
|
||||
} else {
|
||||
log_error("[OMEMO] creating directory: %s", omemo_dir);
|
||||
}
|
||||
}
|
||||
|
||||
g_free(omemo_dir);
|
||||
|
||||
omemo_devicelist_subscribe();
|
||||
|
@ -129,19 +129,20 @@ static void
|
||||
cb_write_fingerprints(void* opdata)
|
||||
{
|
||||
gcry_error_t err = 0;
|
||||
gchar* otr_dir = files_get_account_data_path(DIR_OTR, jid);
|
||||
|
||||
GString* fpsfilename = g_string_new(otr_dir);
|
||||
g_string_append(fpsfilename, "/fingerprints.txt");
|
||||
|
||||
err = otrl_privkey_write_fingerprints(user_state, fpsfilename->str);
|
||||
if (err != GPG_ERR_NO_ERROR) {
|
||||
log_error("Failed to write fingerprints file");
|
||||
gchar* fpsfilename = files_file_in_account_data_path(DIR_OTR, jid, "fingerprints.txt");
|
||||
if (!fpsfilename) {
|
||||
log_error("Failed to create fingerprints file");
|
||||
cons_show_error("Failed to create fingerprints file");
|
||||
return;
|
||||
}
|
||||
|
||||
g_free(otr_dir);
|
||||
g_string_free(fpsfilename, TRUE);
|
||||
err = otrl_privkey_write_fingerprints(user_state, fpsfilename);
|
||||
if (err != GPG_ERR_NO_ERROR) {
|
||||
log_error("Failed to write fingerprints file");
|
||||
cons_show_error("Failed to write fingerprints file");
|
||||
}
|
||||
|
||||
g_free(fpsfilename);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -212,12 +213,10 @@ otr_on_connect(ProfAccount* account)
|
||||
jid = strdup(account->jid);
|
||||
log_info("Loading OTR key for %s", jid);
|
||||
|
||||
gchar* otr_dir = files_get_account_data_path(DIR_OTR, jid);
|
||||
|
||||
if (!mkdir_recursive(otr_dir)) {
|
||||
log_error("Could not create %s for account %s.", otr_dir, jid);
|
||||
cons_show_error("Could not create %s for account %s.", otr_dir, jid);
|
||||
g_free(otr_dir);
|
||||
gchar* otr_dir = files_file_in_account_data_path(DIR_OTR, jid, NULL);
|
||||
if (!otr_dir) {
|
||||
log_error("Could not create directory for account %s.", jid);
|
||||
cons_show_error("Could not create directory for account %s.", jid);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -381,12 +380,11 @@ otr_keygen(ProfAccount* account)
|
||||
jid = strdup(account->jid);
|
||||
log_info("Generating OTR key for %s", jid);
|
||||
|
||||
gchar* otr_dir = files_get_account_data_path(DIR_OTR, jid);
|
||||
gchar* otr_dir = files_file_in_account_data_path(DIR_OTR, jid, NULL);
|
||||
|
||||
if (!mkdir_recursive(otr_dir)) {
|
||||
log_error("Could not create %s for account %s.", otr_dir, jid);
|
||||
cons_show_error("Could not create %s for account %s.", otr_dir, jid);
|
||||
g_free(otr_dir);
|
||||
if (!otr_dir) {
|
||||
log_error("Could not create directory for account %s.", jid);
|
||||
cons_show_error("Could not create directory for account %s.", jid);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -161,26 +161,12 @@ p_gpg_close(void)
|
||||
void
|
||||
p_gpg_on_connect(const char* const barejid)
|
||||
{
|
||||
gchar* pubsfile = files_get_account_data_path(DIR_PGP, barejid);
|
||||
|
||||
// mkdir if doesn't exist for account
|
||||
errno = 0;
|
||||
int res = g_mkdir_with_parents(pubsfile, S_IRWXU);
|
||||
if (res == -1) {
|
||||
const char* errmsg = strerror(errno);
|
||||
if (errmsg) {
|
||||
log_error("Error creating directory: %s, %s", pubsfile, errmsg);
|
||||
} else {
|
||||
log_error("Error creating directory: %s", pubsfile);
|
||||
pubsloc = files_file_in_account_data_path(DIR_PGP, barejid, "pubkeys");
|
||||
if (!pubsloc) {
|
||||
log_error("Could not create directory for account %s.", barejid);
|
||||
cons_show_error("Could not create directory for account %s.", barejid);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// create or read publickeys
|
||||
GString* pubtmp = g_string_new(pubsfile);
|
||||
g_string_append(pubtmp, "/pubkeys");
|
||||
pubsloc = pubtmp->str;
|
||||
g_string_free(pubtmp, FALSE);
|
||||
g_free(pubsfile);
|
||||
|
||||
if (g_file_test(pubsloc, G_FILE_TEST_EXISTS)) {
|
||||
g_chmod(pubsloc, S_IRUSR | S_IWUSR);
|
||||
|
Loading…
Reference in New Issue
Block a user