diff options
author | An-Cheng Huang <ancheng@vyatta.com> | 2008-02-05 11:19:35 -0800 |
---|---|---|
committer | An-Cheng Huang <ancheng@vyatta.com> | 2008-02-05 11:19:35 -0800 |
commit | efe5aea36400ea839c38055576a8fb44bab6a04e (patch) | |
tree | 8a3fb69c5f0d2fa556ff034c7961368909f920a2 /scripts | |
parent | f61275805c551b81337b90c91da957a428f6bcaf (diff) | |
download | vyatta-cfg-efe5aea36400ea839c38055576a8fb44bab6a04e.tar.gz vyatta-cfg-efe5aea36400ea839c38055576a8fb44bab6a04e.zip |
fix for bug 2734: different messages for "empty" and "invalid".
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/VyattaConfig.pm | 16 | ||||
-rwxr-xr-x | scripts/VyattaConfigOutput.pm | 4 |
2 files changed, 14 insertions, 6 deletions
diff --git a/scripts/VyattaConfig.pm b/scripts/VyattaConfig.pm index 6c37073..9020af0 100644 --- a/scripts/VyattaConfig.pm +++ b/scripts/VyattaConfig.pm @@ -402,8 +402,9 @@ sub createNewConfigDOMTree { ###### functions for templates ###### -# $1: array representing the config path (note that path must be present -# in current config) +# $1: array representing the config node path. +# returns the filesystem path to the template of the specified node, +# or undef if the specified node path is not valid. sub getTmplPath { my $self = shift; my @cfg_path = @{$_[0]}; @@ -417,8 +418,8 @@ sub getTmplPath { $tpath .= "/node.tag"; next; } - # the path is not valid! not supposed to happen! - die "Node path \"" . (join ' ', @cfg_path) . "\" is not valid"; + # the path is not valid! + return undef; } return $tpath } @@ -427,6 +428,7 @@ sub isTagNode { my $self = shift; my $cfg_path_ref = shift; my $tpath = $self->getTmplPath($cfg_path_ref); + return undef if (!defined($tpath)); if (-d "$tpath/node.tag") { return 1; } @@ -437,6 +439,7 @@ sub hasTmplChildren { my $self = shift; my $cfg_path_ref = shift; my $tpath = $self->getTmplPath($cfg_path_ref); + return undef if (!defined($tpath)); opendir(TDIR, $tpath) or return 0; my @tchildren = grep !/^node\.def$/, (grep !/^\./, (readdir TDIR)); closedir TDIR; @@ -446,12 +449,15 @@ sub hasTmplChildren { return 0; } -# returns ($is_multi, $is_text) +# $cfg_path_ref: ref to array containing the node path. +# returns ($is_multi, $is_text, $default), +# or undef if specified node is not valid. sub parseTmpl { my $self = shift; my $cfg_path_ref = shift; my ($is_multi, $is_text, $default) = (0, 0, undef); my $tpath = $self->getTmplPath($cfg_path_ref); + return undef if (!defined($tpath)); if (! -r "$tpath/node.def") { return ($is_multi, $is_text); } diff --git a/scripts/VyattaConfigOutput.pm b/scripts/VyattaConfigOutput.pm index 861316a..5f92c15 100755 --- a/scripts/VyattaConfigOutput.pm +++ b/scripts/VyattaConfigOutput.pm @@ -283,8 +283,10 @@ sub outputNewConfig { if (defined($config->existsOrig()) && !defined($config->exists())) { # this is a deleted node print 'Configuration under "' . (join ' ', @_) . "\" has been deleted\n"; + } elsif (!defined($config->getTmplPath(\@_))) { + print "Specified configuration path is not valid\n"; } else { - print "Current configuration is empty\n"; + print 'Configuration under "' . (join ' ', @_) . "\" is empty\n"; } } } |