Fix precedence of command line arguments
Previously, when autogenerating the config file, the name of config itself was included in the YAML contents. This in turn caused the config file to be re-parsed again and any command line arguments were overwritten with values from the config file. Now the name of config file is not dumped if it is equal to the file being written, and the config file is not reparsed if it is the same file. FossilOrigin-Name: 9c4483633c8bcf36f4e98ce41ab0f54ea4620a4b7f21ccf07e563e49afbe0da6
This commit is contained in:
parent
da79de2320
commit
4448213735
1 changed files with 26 additions and 2 deletions
28
shelldap
28
shelldap
|
|
@ -667,8 +667,7 @@ You may try connecting insecurely, or install the module and try again.\n} if $@
|
|||
print "Would you like to cache your connection information? [Yn]: ";
|
||||
chomp( my $response = <STDIN> );
|
||||
unless ( $response =~ /^n/i ) {
|
||||
YAML::Syck::DumpFile( $conf->{'configfile'}, $conf );
|
||||
chmod 0600, $conf->{'configfile'};
|
||||
main::save_config($conf->{configfile});
|
||||
print "Connection info cached to $conf->{'configfile'}.\n";
|
||||
}
|
||||
}
|
||||
|
|
@ -2454,8 +2453,33 @@ sub load_config
|
|||
eval { $conf = YAML::Syck::Load( $data ) };
|
||||
die "Invalid YAML in $confpath\n" if $@;
|
||||
|
||||
# remove reference to itself, if somehow it got dumped
|
||||
# into YAML.
|
||||
if( $conf->{configfile} and ($confpath eq $conf->{configfile})) {
|
||||
delete $conf->{'configfile'}
|
||||
}
|
||||
|
||||
return $conf;
|
||||
}
|
||||
|
||||
### dump YAML config into conf file while making sure that
|
||||
### name of configfile itself is not dumped if it is equal
|
||||
### to the file being written.
|
||||
###
|
||||
sub save_config
|
||||
{
|
||||
my $confpath = shift;
|
||||
|
||||
my %conf2 = %$conf;
|
||||
if( $confpath eq $conf->{configfile}) {
|
||||
delete $conf2{'configfile'}
|
||||
}
|
||||
|
||||
YAML::Syck::DumpFile( $conf->{'configfile'}, \%conf2 );
|
||||
chmod 0600, $conf->{'configfile'};
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
### EOF
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue