Skip to content

Commit

Permalink
Update first occurrance of a directive https://www.virtualmin.com/nod…
Browse files Browse the repository at this point in the history
  • Loading branch information
jcameron committed Feb 18, 2013
1 parent 6f7226d commit 88bd898
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions dovecot/dovecot-lib.pl
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ sub read_config_file
return @rv;
}

# find(name, &config, [disabled-mode], [sectionname], [sectionvalue])
# find(name, &config, [disabled-mode], [sectionname], [sectionvalue], [first])
# Mode 0=enabled, 1=disabled, 2=both
sub find
{
local ($name, $conf, $mode, $sname, $svalue) = @_;
local ($name, $conf, $mode, $sname, $svalue, $first) = @_;
local @rv = grep { !$_->{'section'} &&
$_->{'name'} eq $name &&
($mode == 0 && $_->{'enabled'} ||
Expand All @@ -149,7 +149,7 @@ sub find
@rv = grep { $_->{'sectionname'} eq $sname &&
$_->{'sectionvalue'} eq $svalue } @rv;
}
return wantarray ? @rv : $rv[$#rv];
return wantarray ? @rv : $first ? $rv[0] : $rv[$#rv];
}

# find_value(name, &config, [disabled-mode], [sectionname], [sectionvalue])
Expand Down Expand Up @@ -190,7 +190,7 @@ sub find_section
sub save_directive
{
local ($conf, $name, $value, $sname, $svalue) = @_;
local $dir = ref($name) ? $name : &find($name, $conf, 0, $sname, $svalue);
local $dir = ref($name) ? $name : &find($name, $conf, 0, $sname, $svalue, 1);
local $newline = ref($name) ? "$name->{'name'} = $value" : "$name = $value";
if ($sname) {
$newline = " ".$newline;
Expand Down

0 comments on commit 88bd898

Please sign in to comment.