From 4f1053c5464de12b635a8cf4128b78d51f6f3deb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20Bj=C3=B8rlykke?= Date: Tue, 20 Jun 2017 15:12:48 -0400 Subject: Qt: Create the user profiles dir at startup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ensure the user profiles directory is created at startup so that users can put downloaded profiles without creating the directory. Change-Id: Ib06bb3055daef8fd9e78d7887ce56f8fe50e48bf Reviewed-on: https://code.wireshark.org/review/22275 Petri-Dish: Stig Bjørlykke Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- wsutil/filesystem.c | 66 +++++++++++++++++++++++++++++++++-------------------- wsutil/filesystem.h | 5 ++++ 2 files changed, 46 insertions(+), 25 deletions(-) (limited to 'wsutil') diff --git a/wsutil/filesystem.c b/wsutil/filesystem.c index e4f3c3bed8..8738db204e 100644 --- a/wsutil/filesystem.c +++ b/wsutil/filesystem.c @@ -1378,6 +1378,45 @@ get_profiles_dir(void) G_DIR_SEPARATOR_S, PROFILES_DIR); } +int +create_profiles_dir(char **pf_dir_path_return) +{ + char *pf_dir_path; + ws_statb64 s_buf; + + /* + * Create the "Default" personal configuration files directory, if necessary. + */ + if (create_persconffile_profile (NULL, pf_dir_path_return) == -1) { + return -1; + } + + /* + * Check if profiles directory exists. + * If not then create it. + */ + pf_dir_path = get_profiles_dir (); + if (ws_stat64(pf_dir_path, &s_buf) != 0) { + if (errno != ENOENT) { + /* Some other problem; give up now. */ + *pf_dir_path_return = pf_dir_path; + return -1; + } + + /* + * It doesn't exist; try to create it. + */ + int ret = ws_mkdir(pf_dir_path, 0755); + if (ret == -1) { + *pf_dir_path_return = pf_dir_path; + return ret; + } + } + g_free(pf_dir_path); + + return 0; +} + char * get_global_profiles_dir(void) { @@ -1556,34 +1595,11 @@ create_persconffile_profile(const char *profilename, char **pf_dir_path_return) if (profilename) { /* - * Create the "Default" personal configuration files directory, if necessary. + * Create the personal profiles directory, if necessary. */ - if (create_persconffile_profile (NULL, pf_dir_path_return) == -1) { + if (create_profiles_dir(pf_dir_path_return) == -1) { return -1; } - - /* - * Check if profiles directory exists. - * If not then create it. - */ - pf_dir_path = get_profiles_dir (); - if (ws_stat64(pf_dir_path, &s_buf) != 0) { - if (errno != ENOENT) { - /* Some other problem; give up now. */ - *pf_dir_path_return = pf_dir_path; - return -1; - } - - /* - * It doesn't exist; try to create it. - */ - ret = ws_mkdir(pf_dir_path, 0755); - if (ret == -1) { - *pf_dir_path_return = pf_dir_path; - return ret; - } - } - g_free(pf_dir_path); } pf_dir_path = get_persconffile_dir(profilename); diff --git a/wsutil/filesystem.h b/wsutil/filesystem.h index 0edd0b2adc..f09e5ccaea 100644 --- a/wsutil/filesystem.h +++ b/wsutil/filesystem.h @@ -124,6 +124,11 @@ WS_DLL_PUBLIC gboolean has_global_profiles(void); */ WS_DLL_PUBLIC char *get_profiles_dir(void); +/* + * Create the directory used to store configuration profile directories. + */ +WS_DLL_PUBLIC int create_profiles_dir(char **pf_dir_path_return); + /* * Get the directory used to store global configuration profile directories. * Caller must free the returned string -- cgit v1.2.1