Просмотр исходного кода

add support for xdg base directory spec. compliant config file

Noah Vogt 3 лет назад
Родитель
Сommit
baf9b53f4e
3 измененных файлов с 31 добавлено и 7 удалено
  1. 3 0
      src/common.h
  2. 22 3
      src/config.c
  3. 6 4
      src/mbsync.1

+ 3 - 0
src/common.h

@@ -90,6 +90,9 @@ typedef unsigned long ulong;
 
 #define EXE "mbsync"
 
+#define DEFAULT_ISYNC_CONFIG_DIR "isync/" EXE "rc"
+#define DEDAULT_XDG_CONFIG_DIR ".config"
+
 /* main.c */
 
 #define DEBUG_CRASH     0x01

+ 22 - 3
src/config.c

@@ -330,11 +330,30 @@ load_config( const char *where )
 	char path[_POSIX_PATH_MAX];
 	char buf[1024];
 
-	if (!where) {
+    const char *default_xdg_dir = "/" DEDAULT_XDG_CONFIG_DIR;
+    const char *default_isync_config_dir = "/" DEFAULT_ISYNC_CONFIG_DIR;
+
+    char* xdg_user_specified_dir;
+    char xdg_path_to_check[_POSIX_PATH_MAX] = "";
+
+    /* find out where to look for xdg compliant config file */
+    if ((xdg_user_specified_dir = getenv("XDG_CONFIG_HOME"))) {
+        strcat(xdg_path_to_check, xdg_user_specified_dir);
+        strcat(xdg_path_to_check, default_isync_config_dir);
+    } else {
+        strcat(xdg_path_to_check, Home);
+        strcat(xdg_path_to_check, default_xdg_dir);
+        strcat(xdg_path_to_check, default_isync_config_dir);
+    }
+
+	if (where) {
+		cfile.file = where;
+	} else if (access( xdg_path_to_check, F_OK | R_OK ) == 0) {
+		cfile.file = xdg_path_to_check;
+	} else {
 		nfsnprintf( path, sizeof(path), "%s/." EXE "rc", Home );
 		cfile.file = path;
-	} else
-		cfile.file = where;
+	}
 
 	info( "Reading configuration file %s\n", cfile.file );
 

+ 6 - 4
src/mbsync.1

@@ -47,7 +47,6 @@ Multiple replicas of each mailbox can be maintained.
 .TP
 \fB-c\fR, \fB--config\fR \fIfile\fR
 Read configuration from \fIfile\fR.
-By default, the configuration is read from ~/.mbsyncrc.
 .TP
 \fB-a\fR, \fB--all\fR
 Select all configured channels. Any channel/group specifications on the command
@@ -802,9 +801,12 @@ There is no risk as long as the IMAP mailbox is accessed by only one client
 (including \fBmbsync\fR) at a time.
 .
 .SH FILES
-.TP
-.B ~/.mbsyncrc
-Default configuration file
+.P
+If the config file is not explicitly set with \fB-c\fR or \fB--config\fR,
+firstly \fB$XDG_CONFIG_HOME/isync/mbsyncrc\fR will be checked. If
+\fB$XDG_CONFIG_HOME\fR is not set or empty, \fB$HOME/.config/isync/mbsyncrc\fR
+will be tried. However when this file is empty, \fB~/.mbsyncrc\fR will be
+used instead.
 .TP
 .B ~/.mbsync/
 Directory containing synchronization state files