On Sun, Nov 29, 2020 at 02:47:15PM +0100, Oswald Buddenhagen wrote: > On Sun, Nov 29, 2020 at 08:23:45AM +0100, Andreas Grapentin wrote: > > 2.) it attempts to open the config file at location > > $XDG_CONFIG_HOME/mbsync/config > > > any particular reason why this isn't simply $XDG_CONFIG_HOME/mbsyncrc? i see > that a lot of apps have the extra dir, but that's just pointless noise when > only one file is expected (of course, in principle, there can be also ssl > certificates, but storing auxiliary files with the same file name stem > directly in $XDG_CONFIG_HOME also has many precedents, and it would be the > rare case here).
I have not found any text in the specification on whether any format is to be preferred here. I think the subdirectory has the advantage of being extendable in the future, in case of a change that adds more configuration files I think all of the following would be fine: - XDG_CONFIG_HOME/mbsync/mbsyncrc - XDG_CONFIG_HOME/mbsync/config - XDG_CONFIG_HOME/isync/mbsyncrc - XDG_CONFIG_HOME/mbsyncrc and probably more. maybe the version XDG_CONFIG_HOME/isync/mbsyncrc makes sense, in case any other utilities that are part of isync will provide config files in the future? > > If this change is welcome, I can look into using XDG_DATA_HOME for > > ~/.local/share/mbsync as well, as requested in the original feature > > request. > > > yes, absolutely. In the interest of granularity, I'll prepare a separate patch for that, is that ok? Thank you for the feedback on the code changes! I have attached an updated version of the patch below. Best, Andreas -- ------------------------------------------------------------------------------ my GPG Public Key: https://files.grapentin.org/.gpg/public.key ------------------------------------------------------------------------------
From 28b6d72671b05c4f1dfae3ba33fbe71270f8aa09 Mon Sep 17 00:00:00 2001 From: Andreas Grapentin <andr...@grapentin.org> Date: Sun, 29 Nov 2020 07:51:20 +0100 Subject: [PATCH] src/config.c: added XDG_CONFIG_HOME support --- src/config.c | 30 +++++++++++++++++++++++++----- src/mbsync.1 | 6 ++++-- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/config.c b/src/config.c index dec47b2..cd9d833 100644 --- a/src/config.c +++ b/src/config.c @@ -33,6 +33,7 @@ #include <string.h> #include <stdlib.h> #include <stdio.h> +#include <errno.h> static store_conf_t *stores; @@ -331,17 +332,36 @@ load_config( const char *where ) char buf[1024]; if (!where) { - nfsnprintf( path, sizeof(path), "%s/." EXE "rc", Home ); + const char *config_home = getenv("XDG_CONFIG_HOME"); + if (config_home) + nfsnprintf( path, sizeof(path), "%s/" EXE "/config", config_home ); + else + nfsnprintf( path, sizeof(path), "%s/.config/" EXE "/config", Home ); cfile.file = path; - } else + + info( "Reading configuration file %s\n", cfile.file ); + cfile.fp = fopen( cfile.file, "r" ); + + if (!cfile.fp && errno == ENOENT) { + errno = 0; + nfsnprintf( path, sizeof(path), "%s/." EXE "rc", Home ); + cfile.file = path; + + info( "Reading configuration file %s\n", cfile.file ); + cfile.fp = fopen( cfile.file, "r" ); + } + } else { cfile.file = where; - info( "Reading configuration file %s\n", cfile.file ); + info( "Reading configuration file %s\n", cfile.file ); + cfile.fp = fopen( cfile.file, "r" ); + } - if (!(cfile.fp = fopen( cfile.file, "r" ))) { - sys_error( "Cannot open config file '%s'", cfile.file ); + if (!cfile.fp) { + sys_error( "Cannot open user config file '%s'", cfile.file ); return 1; } + buf[sizeof(buf) - 1] = 0; cfile.buf = buf; cfile.bufl = sizeof(buf) - 1; diff --git a/src/mbsync.1 b/src/mbsync.1 index 65a213e..e7b9bae 100644 --- a/src/mbsync.1 +++ b/src/mbsync.1 @@ -47,7 +47,8 @@ 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. +By default, the configuration is read from the first file found in the list +of default locations. See \fBFILES\fR below for a complete list. .TP \fB-a\fR, \fB--all\fR Select all configured channels. Any channel/group specifications on the command @@ -803,8 +804,9 @@ There is no risk as long as the IMAP mailbox is accessed by only one client . .SH FILES .TP +.B $XDG_CONFIG_HOME/mbsync/config .B ~/.mbsyncrc -Default configuration file +Default configuration files .TP .B ~/.mbsync/ Directory containing synchronization state files -- 2.29.2
signature.asc
Description: PGP signature
_______________________________________________ isync-devel mailing list isync-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/isync-devel