Make "tinc add" idempotent.
When calling "tinc add" multiple times with the same variable and value, make sure only one unique line is added to the configuration file.
This commit is contained in:
parent
0b310bf406
commit
4b2ddded2c
3 changed files with 8 additions and 1 deletions
|
@ -88,6 +88,7 @@ To set a variable for a specific host, use the notation
|
|||
.Ar host Ns Li . Ns Ar variable .
|
||||
.It add Ar variable Ar value
|
||||
As above, but without removing any previously existing configuration variables.
|
||||
If the variable already exists with the given value, nothing happens.
|
||||
.It del Ar variable Op Ar value
|
||||
Remove configuration variables with the same name and
|
||||
.Ar value .
|
||||
|
|
|
@ -2293,6 +2293,7 @@ To set a variable for a specific host, use the notation @var{host}.@var{variable
|
|||
@cindex add
|
||||
@item add @var{variable} @var{value}
|
||||
As above, but without removing any previously existing configuration variables.
|
||||
If the variable already exists with the given value, nothing happens.
|
||||
|
||||
@cindex del
|
||||
@item del @var{variable} [@var{value}]
|
||||
|
|
|
@ -1610,6 +1610,11 @@ static int cmd_config(int argc, char *argv[]) {
|
|||
}
|
||||
set = true;
|
||||
continue;
|
||||
// Add
|
||||
} else if(action > 0) {
|
||||
// Check if we've already seen this variable with the same value
|
||||
if(!strcasecmp(bvalue, value))
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1642,7 +1647,7 @@ static int cmd_config(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
// Add new variable if necessary.
|
||||
if(action > 0 || (action == 0 && !set)) {
|
||||
if((action > 0 && !found)|| (action == 0 && !set)) {
|
||||
if(fprintf(tf, "%s = %s\n", variable, value) < 0) {
|
||||
fprintf(stderr, "Error writing to temporary file %s: %s\n", tmpfile, strerror(errno));
|
||||
return 1;
|
||||
|
|
Loading…
Reference in a new issue