On Sun, Nov 29, 2020 at 08:23:45AM +0100, Andreas Grapentin wrote:
The patch changes the way that mbsync looks for a config file in the
following way:
1.) it expands XDG_CONFIG_HOME, if set, and otherwise defaults to $HOME/.config
as per the specification
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).
3.) if that failed, it will fall back to $HOME/.mbsyncrc
I should note this approach still falls short of the specification in
that the directories in $XDG_CONFIG_DIRS are not considered.
that appears acceptable.
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.
--- a/src/config.c
+++ b/src/config.c
@@ -329,21 +329,45 @@ load_config( const char *where, int pseudo )
int cops, gcops, fn, i;
char path[_POSIX_PATH_MAX];
char buf[1024];
+ const char *config_home;
that can be local to the assignment - we rely on C99 now.
if (!where) {
assert( !pseudo );
whoops, i should push out some pending patches, as there are some
conflicts here ...
+ config_home = getenv("XDG_CONFIG_HOME");
+ if (config_home) {
excess braces.
+ nfsnprintf( path, sizeof(path), "%s/" EXE "/config",
config_home );
+ } else {
+ nfsnprintf( path, sizeof(path), "%s/.config/" EXE
"/config", Home );
+ }
cfile.file = path;
- } else
- cfile.file = where;
- if (!pseudo)
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 );
- return 1;
+ if (!cfile.fp) {
that should also check for errno == ENOFILE.
+ 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" );
+ }
+
+ if (!cfile.fp) {
+ sys_error( "Cannot open user config file" );
+ return 1;
+ }
+ } else {
+ cfile.file = where;
+
+ if (!pseudo)
+ info( "Reading configuration file %s\n", cfile.file );
+
+ if (!(cfile.fp = fopen( cfile.file, "r" ))) {
+ sys_error( "Cannot open config file '%s'", cfile.file );
+ return 1;
+ }
i don't like the repetitiveness of this code. it should be easier to fix
that after you rebase.
}
--- 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 $XDG_CONFIG_HOME/mbsync/config,
+or alternatively ~/.mbsyncrc.
this sounds like the precedence would be undefined. "with a fallback to"
or something like that would do.
_______________________________________________
isync-devel mailing list
isync-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/isync-devel