diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2009-02-04 10:15:50 -0800 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2009-02-04 10:15:50 -0800 |
commit | eaf4e68ae42b1e4e5c4f5ca0ea944c0ab383157b (patch) | |
tree | 5f175d2e9e193fc7da29588d16a63099efdbb2ff | |
parent | f72dabfeeb0d99681535f9d60ecf84e861df8889 (diff) | |
download | vyatta-cfg-eaf4e68ae42b1e4e5c4f5ca0ea944c0ab383157b.tar.gz vyatta-cfg-eaf4e68ae42b1e4e5c4f5ca0ea944c0ab383157b.zip |
Vyatta::Config::returnValue - change to three argument open
Using three argument open is safer against global handle clash,
and accidental scripting.
-rwxr-xr-x | lib/Vyatta/Config.pm | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/lib/Vyatta/Config.pm b/lib/Vyatta/Config.pm index 9e57448..77fb440 100755 --- a/lib/Vyatta/Config.pm +++ b/lib/Vyatta/Config.pm @@ -206,19 +206,16 @@ sub returnValue { $node =~ s/\//%2F/g; $node =~ s/\s+/\//g; - if ( -f "$self->{_new_config_dir_base}$self->{_current_dir_level}/$node/node.val" ) { - open FILE, "$self->{_new_config_dir_base}$self->{_current_dir_level}/$node/node.val" || return undef; - read FILE, $tmp, 16384; - close FILE; + return unless + open my $file, '<', + "$self->{_new_config_dir_base}$self->{_current_dir_level}/$node/node.val"; - $tmp =~ s/\n$//; - return $tmp; - } - else { - return undef; - } -} + read $file, $tmp, 16384; + close $file; + $tmp =~ s/\n$//; + return $tmp; +} ## returnOrigValue("node") # returns the original value of "node" (i.e., before the current change; i.e., @@ -231,16 +228,14 @@ sub returnOrigValue { $node =~ s/\//%2F/g; $node =~ s/\s+/\//g; my $filepath = "$self->{_active_dir_base}$self->{_current_dir_level}/$node"; - if ( -f "$filepath/node.val") { - open FILE, "$filepath/node.val" || return undef; - read FILE, $tmp, 16384; - close FILE; - $tmp =~ s/\n$//; - return $tmp; - } else { - return undef; - } + return unless open my $file, '<', "$filepath/node.val"; + + read $file, $tmp, 16384; + close $file; + + $tmp =~ s/\n$//; + return $tmp; } ## returnValues("node") |