aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStig Bjørlykke <stig@bjorlykke.org>2017-06-20 15:12:48 -0400
committerAnders Broman <a.broman58@gmail.com>2017-06-20 19:45:03 +0000
commit4f1053c5464de12b635a8cf4128b78d51f6f3deb (patch)
treead6f1008934c656ab10c57ed9bb1884453ca59f0
parentc919c625025afdca318a1a3413b268d00ad1985c (diff)
Qt: Create the user profiles dir at startup
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 <stig@bjorlykke.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r--wireshark-qt.cpp8
-rw-r--r--wsutil/filesystem.c66
-rw-r--r--wsutil/filesystem.h5
3 files changed, 54 insertions, 25 deletions
diff --git a/wireshark-qt.cpp b/wireshark-qt.cpp
index b7426dd604..7e4d597c7a 100644
--- a/wireshark-qt.cpp
+++ b/wireshark-qt.cpp
@@ -473,6 +473,14 @@ int main(int argc, char *qt_argv[])
/* Assemble the run-time version information string */
runtime_info_str = get_runtime_version_info(get_wireshark_runtime_info);
+ /* Create the user profiles directory */
+ if (create_profiles_dir(&rf_path) == -1) {
+ simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
+ "Could not create profiles directory\n\"%s\"",
+ rf_path);
+ g_free (rf_path);
+ }
+
profile_store_persconffiles(TRUE);
/* Read the profile independent recent file. We have to do this here so we can */
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
@@ -125,6 +125,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
*/