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/config/files.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/config/files.c') diff --git a/src/config/files.c b/src/config/files.c index ce3f1196..8a241be5 100644 --- a/src/config/files.c +++ b/src/config/files.c @@ -38,6 +38,8 @@ #include #include #include +#include +#include #include #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) { -- cgit 1.4.1-2-gfad0