From b8e46552bffc559263e86b2dcc0331b3f47065b7 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Sun, 13 Mar 2022 11:58:56 +0100 Subject: 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 --- src/otr/otr.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'src/otr') diff --git a/src/otr/otr.c b/src/otr/otr.c index 5f45e23c..562914a2 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -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"); + 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; + } - err = otrl_privkey_write_fingerprints(user_state, fpsfilename->str); + 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 create fingerprints file"); + cons_show_error("Failed to write fingerprints file"); } - g_free(otr_dir); - g_string_free(fpsfilename, TRUE); + 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; } -- cgit 1.4.1-2-gfad0