summaryrefslogtreecommitdiff
path: root/lib/Vyatta/Config.pm
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2009-02-04 10:11:56 -0800
committerStephen Hemminger <stephen.hemminger@vyatta.com>2009-02-04 10:11:56 -0800
commitf72dabfeeb0d99681535f9d60ecf84e861df8889 (patch)
tree73f77dd837e004481b6409b4a3f45289a20922cf /lib/Vyatta/Config.pm
parentc576910412880516a4c3c4717fd8370612cdefb3 (diff)
downloadvyatta-cfg-f72dabfeeb0d99681535f9d60ecf84e861df8889.tar.gz
vyatta-cfg-f72dabfeeb0d99681535f9d60ecf84e861df8889.zip
Revert "Cleanup confg library"
Save is broken by this, so do in smaller chunks.
Diffstat (limited to 'lib/Vyatta/Config.pm')
-rwxr-xr-xlib/Vyatta/Config.pm91
1 files changed, 51 insertions, 40 deletions
diff --git a/lib/Vyatta/Config.pm b/lib/Vyatta/Config.pm
index 3f2191b..9e57448 100755
--- a/lib/Vyatta/Config.pm
+++ b/lib/Vyatta/Config.pm
@@ -206,17 +206,20 @@ sub returnValue {
$node =~ s/\//%2F/g;
$node =~ s/\s+/\//g;
- open (my $file, '<',
- "$self->{_new_config_dir_base}$self->{_current_dir_level}/$node/node.val")
- or return; # undefined
+ 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;
- read $file, $tmp, 16384;
- close $file;
-
- $tmp =~ s/\n$//;
- return $tmp;
+ $tmp =~ s/\n$//;
+ return $tmp;
+ }
+ else {
+ return undef;
+ }
}
+
## returnOrigValue("node")
# returns the original value of "node" (i.e., before the current change; i.e.,
# in "working") or undef if the node doesn't exist.
@@ -228,14 +231,16 @@ sub returnOrigValue {
$node =~ s/\//%2F/g;
$node =~ s/\s+/\//g;
my $filepath = "$self->{_active_dir_base}$self->{_current_dir_level}/$node";
-
- open my $file, '<', $filepath
- or return; # undef
- read $file, $tmp, 16384;
- close $file;
-
- $tmp =~ s/\n$//;
- return $tmp;
+ 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;
+ }
}
## returnValues("node")
@@ -271,7 +276,12 @@ sub exists {
$node =~ s/\//%2F/g;
$node =~ s/\s+/\//g;
- return ( -d "$self->{_new_config_dir_base}$self->{_current_dir_level}/$node" );
+ if ( -d "$self->{_new_config_dir_base}$self->{_current_dir_level}/$node" ) {
+ #print "DEBUG: the dir is there\n";
+ return !0;
+ } else {
+ return undef;
+ }
}
## existsOrig("node")
@@ -281,7 +291,11 @@ sub existsOrig {
$node =~ s/\//%2F/g;
$node =~ s/\s+/\//g;
- return ( -d "$self->{_active_dir_base}$self->{_current_dir_level}/$node" );
+ if ( -d "$self->{_active_dir_base}$self->{_current_dir_level}/$node" ) {
+ return 1;
+ } else {
+ return undef;
+ }
}
## isDeleted("node")
@@ -464,33 +478,34 @@ sub getTmplPath {
next;
}
# the path is not valid!
- return;
+ return undef;
}
- return $tpath;
+ return $tpath
}
sub isTagNode {
my $self = shift;
my $cfg_path_ref = shift;
my $tpath = $self->getTmplPath($cfg_path_ref);
- return unless $tpath; # undef;
- return (-d "$tpath/node.tag");
+ return undef if (!defined($tpath));
+ if (-d "$tpath/node.tag") {
+ return 1;
+ }
+ return 0;
}
sub hasTmplChildren {
my $self = shift;
my $cfg_path_ref = shift;
my $tpath = $self->getTmplPath($cfg_path_ref);
-
- return unless $tpath; # undefined
-
- opendir (my $tdir, $tpath)
- or return; # false
-
- my @tchildren = grep !/^node\.def$/, (grep !/^\./, (readdir $tdir));
- closedir $tdir;
-
- return (scalar(@tchildren) > 0);
+ return undef if (!defined($tpath));
+ opendir(TDIR, $tpath) or return 0;
+ my @tchildren = grep !/^node\.def$/, (grep !/^\./, (readdir TDIR));
+ closedir TDIR;
+ if (scalar(@tchildren) > 0) {
+ return 1;
+ }
+ return 0;
}
# $cfg_path_ref: ref to array containing the node path.
@@ -501,16 +516,12 @@ sub parseTmpl {
my $cfg_path_ref = shift;
my ($is_multi, $is_text, $default) = (0, 0, undef);
my $tpath = $self->getTmplPath($cfg_path_ref);
-
- return unless $tpath; # undef
+ return undef if (!defined($tpath));
if (! -r "$tpath/node.def") {
return ($is_multi, $is_text);
}
-
- open (my $tmp, '<', "$tpath/node.def")
- or return ($is_multi, $is_text);
-
- foreach (<$tmp>) {
+ open(TMPL, "<$tpath/node.def") or return ($is_multi, $is_text);
+ foreach (<TMPL>) {
if (/^multi:/) {
$is_multi = 1;
}
@@ -521,7 +532,7 @@ sub parseTmpl {
$default = $1;
}
}
- close $tmp;
+ close TMPL;
return ($is_multi, $is_text, $default);
}