changeset 2252:2c7cca6dec6a

Simplify hlog_enable()
author Mikael Berthe <mikael@lilotux.net>
date Sat, 27 Feb 2016 11:02:19 +0100
parents f3bd1564fa70
children 5a107c907e71
files mcabber/mcabber/histolog.c
diffstat 1 files changed, 32 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/mcabber/histolog.c	Fri Feb 19 22:14:15 2016 +0100
+++ b/mcabber/mcabber/histolog.c	Sat Feb 27 11:02:19 2016 +0100
@@ -372,40 +372,42 @@
   UseFileLogging = enable;
   FileLoadLogs = loadfiles;
 
-  if (enable || loadfiles) {
-    if (root_dir) {
-      char *xp_root_dir;
-      int l = strlen(root_dir);
-      if (l < 1) {
-        scr_LogPrint(LPRINT_LOGNORM, "Error: logging dir name too short");
-        UseFileLogging = FileLoadLogs = FALSE;
-        return;
-      }
-      xp_root_dir = expand_filename(root_dir);
-      // RootDir must be slash-terminated
-      if (root_dir[l-1] == '/') {
-        RootDir = xp_root_dir;
-      } else {
-        RootDir = g_strdup_printf("%s/", xp_root_dir);
-        g_free(xp_root_dir);
-      }
+  g_free(RootDir);
+  RootDir = NULL;
+
+  if (!enable && !loadfiles)
+    return;
+
+  if (root_dir) {
+    char *xp_root_dir;
+    int l = strlen(root_dir);
+    if (l < 1) {
+      scr_LogPrint(LPRINT_LOGNORM, "Error: logging dir name too short");
+      UseFileLogging = FileLoadLogs = FALSE;
+      return;
+    }
+    xp_root_dir = expand_filename(root_dir);
+    // RootDir must be slash-terminated
+    if (root_dir[l-1] == '/') {
+      RootDir = xp_root_dir;
     } else {
-      const char *cfgdir = settings_get_mcabber_config_dir();
-      const char *hdir = "/histo/";
-      RootDir = g_strdup_printf("%s%s", cfgdir, hdir);
+      RootDir = g_strdup_printf("%s/", xp_root_dir);
+      g_free(xp_root_dir);
     }
-    // Check directory permissions (should not be readable by group/others)
-    if (checkset_perm(RootDir, TRUE) == -1) {
-      // The directory does not actually exists
-      g_free(RootDir);
-      RootDir = NULL;
-      scr_LogPrint(LPRINT_LOGNORM, "ERROR: Cannot access "
-                   "history log directory, logging DISABLED");
-      UseFileLogging = FileLoadLogs = FALSE;
-    }
-  } else {  // Disable history logging
+  } else {
+    const char *cfgdir = settings_get_mcabber_config_dir();
+    const char *hdir = "/histo/";
+    RootDir = g_strdup_printf("%s%s", cfgdir, hdir);
+  }
+
+  // Check directory permissions (should not be readable by group/others)
+  if (checkset_perm(RootDir, TRUE) == -1) {
+    // The directory does not actually exists
     g_free(RootDir);
     RootDir = NULL;
+    scr_LogPrint(LPRINT_LOGNORM, "ERROR: Cannot access "
+                 "history log directory, logging DISABLED");
+    UseFileLogging = FileLoadLogs = FALSE;
   }
 }