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