mbsync: create nested-let function to generate channel pattern
This pattern is required to either NOT be present, which means the master pattern is used to match, or it has a list of patterns to use beneath the master maildir to match against. This function checks to ensure that if patterns is not empty, ONLY then is the `Pattern` keyword printed. Otherwise, there are many, many problems. If there IS a list of patterns, then we use proper escaping methods to ensure that the exact string is constructed.
This commit is contained in:
parent
97a6961db2
commit
2ce482d187
|
@ -87,10 +87,22 @@ let
|
|||
# Given the name of the group this channel is part of and the channel
|
||||
# itself, generate the string for the desired configuration.
|
||||
genChannelString = groupName: channel:
|
||||
let
|
||||
escapeValue = escape [ ''\"'' ];
|
||||
hasSpace = v: builtins.match ".* .*" v != null;
|
||||
# Given a list of patterns, will return the string requested.
|
||||
# Only prints if the pattern is NOT the empty list, the default.
|
||||
genChannelPatterns = patterns: if (length patterns) != 0 then
|
||||
"Pattern " + concatStringsSep " " (map
|
||||
(pat: if hasSpace pat then escapeValue pat else pat) patterns) + "\n"
|
||||
else "";
|
||||
in
|
||||
genSection "Channel ${groupName}-${channel.name}" ({
|
||||
Master = ":${storeName}-remote:${channel.masterPattern}";
|
||||
Slave = ":${storeName}-local:${channel.slavePattern}";
|
||||
}) + "\n";
|
||||
} // channel.extraConfig)
|
||||
+ genChannelPatterns channel.patterns
|
||||
+ "\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:
|
||||
|
|
Loading…
Reference in a new issue