From 07c75b9c792b8ff48d07de77628c3619893eaf74 Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Thu, 20 Dec 2007 17:23:29 -0800 Subject: fix for bug 2340: detecting "deleted" nodes now does not depend on "whiteouts" created by unionfs. --- scripts/VyattaConfig.pm | 58 +++++-------------------------------------------- 1 file changed, 6 insertions(+), 52 deletions(-) diff --git a/scripts/VyattaConfig.pm b/scripts/VyattaConfig.pm index 4d0a90c..03869dc 100644 --- a/scripts/VyattaConfig.pm +++ b/scripts/VyattaConfig.pm @@ -268,58 +268,12 @@ sub isDeleted { # return array of deleted nodes in the "level" # "level" defaults to current sub listDeleted { - my ($self, $node) = @_; - my @return = (); - my $filepath = undef; - my $curpath = undef; - my @nodes = (); - my @curnodes = (); - - # setup the entire path with the new level - # use the change_dir - $node =~ s/\//%2F/g; - $node =~ s/\s+/\//g; - $filepath = "$self->{_changes_only_dir_base}$self->{_current_dir_level}/$node/"; - - $curpath = "$self->{_active_dir_base}$self->{_current_dir_level}/$node/"; - - # let's see if the directory exists and find the the whiteout files - if (! -d "$filepath") { return undef; } - else { - opendir DIR, "$filepath" or return undef; - @nodes = grep !/^\.wh\.\.wh\./, grep /^\.wh./, readdir DIR; - closedir DIR; - } - - if (! -d "$curpath") { - return undef; - } else { - opendir DIR, "$curpath" or return undef; - @curnodes = grep !/^\./, readdir DIR; - closedir DIR; - } - - # get rid of the whiteout prefix - my $dir_opq = 0; - foreach $node (@nodes) { - $node =~ s/^\.wh\.(.+)/$1/; - $_ = $node; - if (! /__dir_opaque/) { - push @return, $node; - } else { - $dir_opq = 1; - } - } - - if ($dir_opq) { - # if this node is "dir_opaque", it has been deleted and re-added. - # add all nodes in "active" to the return list (so that they will be - # marked "deleted"). note that if a node is also re-added, its status - # will be changed after the listDeleted call. - push @return, @curnodes; - } - - return @return; + my ($self, $path) = @_; + my @new_nodes = $self->listNodes("$path"); + my @orig_nodes = $self->listOrigNodes("$path"); + my %new_hash = map { $_ => 1 } @new_nodes; + my @deleted = grep { !defined($new_hash{$_}) } @orig_nodes; + return @deleted; } ## isChanged("node") -- cgit v1.2.3 From ab19102a564790b94c1919430fbdeb38a8c23377 Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Thu, 20 Dec 2007 17:26:50 -0800 Subject: Fixed 'isDeleted' method, related to Bug 2340 fix. --- scripts/VyattaConfig.pm | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/scripts/VyattaConfig.pm b/scripts/VyattaConfig.pm index 03869dc..ecaf545 100644 --- a/scripts/VyattaConfig.pm +++ b/scripts/VyattaConfig.pm @@ -241,27 +241,18 @@ sub existsOrig { # is the "node" deleted. node is relative. returns true or false sub isDeleted { my ($self, $node) = @_; - my $endnode = undef; - my $filepath = undef; - my @nodes = (); - - # split the string into an array - (@nodes) = split /\s+/, $node; - - # take the last node off the string - $endnode = pop @nodes; - # and modify it to match the whiteout name - $endnode = ".wh.$endnode"; - - # setup the path with the rest of the nodes - # use the change_dir $node =~ s/\//%2F/g; $node =~ s/\s+/\//g; - $filepath = "$self->{_changes_only_dir_base}$self->{_current_dir_level}/$node"; - # if the file exists, the node was deleted - if (-f "$filepath") { return 1; } - else { return 0; } + my $filepathAct + = "$self->{_active_dir_base}$self->{_current_dir_level}/$node"; + my $filepathNew + = "$self->{_new_config_dir_base}$self->{_current_dir_level}/$node"; + + if ((-e $filepathAct) && !(-e $filepathNew)) { + return 1; + } + return 0; } ## listDeleted("level") -- cgit v1.2.3 From 68df52c1edbf843e6fb56de3578f18fba80799c4 Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Thu, 20 Dec 2007 17:28:47 -0800 Subject: This loop should not be iterating over deleted nodes. Related to Bug 2340. --- scripts/VyattaConfig.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/VyattaConfig.pm b/scripts/VyattaConfig.pm index ecaf545..6f99329 100644 --- a/scripts/VyattaConfig.pm +++ b/scripts/VyattaConfig.pm @@ -330,9 +330,9 @@ sub listNodeStatus { foreach $node (@nodes) { if ($node =~ /.+/) { #print "DEBUG VyattaConfig->listNodeStatus(): node $node\n"; + # No deleted nodes -- added, changed, ot static only. if ($self->isAdded("$path $node")) { $nodehash{$node} = "added"; } elsif ($self->isChanged("$path $node")) { $nodehash{$node} = "changed"; } - elsif ($self->isDeleted("$path $node")) { $nodehash{$node} = "deleted"; } else { $nodehash{$node} = "static"; } } } -- cgit v1.2.3 From aac164fc48911b10e09b8d562e21aef90bad9699 Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Thu, 20 Dec 2007 17:32:19 -0800 Subject: Some checks for undefined references --- scripts/VyattaConfig.pm | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/VyattaConfig.pm b/scripts/VyattaConfig.pm index 6f99329..3a24579 100644 --- a/scripts/VyattaConfig.pm +++ b/scripts/VyattaConfig.pm @@ -190,8 +190,8 @@ sub returnOrigValue { # node is relative sub returnValues { my $val = returnValue(@_); - my @values; - if ($val) { + my @values = (); + if (defined($val)) { @values = split("\n", $val); } return @values; @@ -317,17 +317,16 @@ sub listNodeStatus { my ($self, $path) = @_; my @nodes = (); my %nodehash = (); - my $node = undef; # find deleted nodes first @nodes = $self->listDeleted("$path"); - foreach $node (@nodes) { + foreach my $node (@nodes) { if ($node =~ /.+/) { $nodehash{$node} = "deleted" }; } @nodes = (); @nodes = $self->listNodes("$path"); - foreach $node (@nodes) { + foreach my $node (@nodes) { if ($node =~ /.+/) { #print "DEBUG VyattaConfig->listNodeStatus(): node $node\n"; # No deleted nodes -- added, changed, ot static only. -- cgit v1.2.3 From 67aa6f38631f725e90dce71fb1ed59cb8ed7ac63 Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Thu, 20 Dec 2007 17:35:21 -0800 Subject: Added method 'isChangedOrDeleted'. Part of Bug 2324 fix. --- scripts/VyattaConfig.pm | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/scripts/VyattaConfig.pm b/scripts/VyattaConfig.pm index 3a24579..6c37073 100644 --- a/scripts/VyattaConfig.pm +++ b/scripts/VyattaConfig.pm @@ -283,6 +283,32 @@ sub isChanged { else { return 0; } } +## isChangedOrDeleted("node") +# is the "node" changed or deleted. node is relative. returns true or false +sub isChangedOrDeleted { + my ($self, $node) = @_; + + $node =~ s/\//%2F/g; + $node =~ s/\s+/\//g; + + my $filepathChg + = "$self->{_changes_only_dir_base}$self->{_current_dir_level}/$node"; + if (-e $filepathChg) { + return 1; + } + + my $filepathAct + = "$self->{_active_dir_base}$self->{_current_dir_level}/$node"; + my $filepathNew + = "$self->{_new_config_dir_base}$self->{_current_dir_level}/$node"; + + if ((-e $filepathAct) && !(-e $filepathNew)) { + return 1; + } + + return 0; +} + ## isAdded("node") # will compare the new_config_dir to the active_dir to see if the "node" has # been added. returns true or false. -- cgit v1.2.3