mbsync: only generate group/channel configuration if channels present

Typically, when a group is specified, channels will be specified as
well. However, if due to error or mistake, the user forgets to specify
ANY channels for a group, we should not generate that group's
information.

This means that no channels are specified (which maps the remote
master to local slave). In addition, the `Group <gName>` block (which
brings the separate channels together) is also not generated.

Another thing to consider is that a user might specify a group and a
channel, but perform no additional configuration of the channel.
In a configuration, this would be realized by
`accounts.email.accounts.<aName>.mbsync.groups.<gName>.channels.<cName>;`

This creates the channel with the name `<cName>` and the
`masterPattern`, `slavePattern`, and `patterns` fields use their defaults.
By definitions set within mbsync, these defaults actually specify that
the remote master's `INBOX` mail directory is synchronized to the
local slave's `INBOX` directory.

So, if there is a channel that has no fields specified, then we DO
want to generate its configuration. But if there is a group that has
no channels, then we do NOT generate it.
This commit is contained in:
Karl Hallsby 2020-06-27 15:26:11 +02:00
parent ddd47e1e1c
commit 82264461e5

View file

@ -99,8 +99,8 @@ let
+ "\n";
# Given the group name, and a attr set of channels within that group,
# Generate a list of strings for each channels' configuration.
genChannelStrings = groupName: channels:
mapAttrsToList (channelName: info: genChannelString groupName info) channels;
genChannelStrings = groupName: channels: optionals (channels != { })
(mapAttrsToList (channelName: info: genChannelString groupName info) channels);
# Given a group, return a string that configures all the channels within
# the group.
genGroupsChannels = group: concatStrings
@ -117,11 +117,11 @@ let
# make "Channel <grpName>-<chnName>" for each channel to list os strings
genChannelStrings = groupName: channels: mapAttrsToList
(name: info: "Channel ${groupName}-${name}") channels;
# Take in 1 group, construct the "Group <grpName>" header, and construct
# each of the channels.
genGroupChannelString = group:
[("Group " + group.name)] ++
(genChannelStrings group.name group.channels);
# Take in 1 group, construct the "Group <grpName>" header, and if the group
# is NOT empty, construct each of the channels.
genGroupChannelString = group: optionals (groups != { })
([("Group " + group.name)] ++
(genChannelStrings group.name group.channels));
# Given set of groups, generates list of strings, where each string is one
# of the groups and its consituent channels.
genGroupsStrings = mapAttrsToList (name: info: concatStringsSep "\n"