1#**************************************************************
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20#**************************************************************
21
22package installer::patch::FileSequenceList;
23
24use XML::LibXML;
25use strict;
26
27=head1 NAME
28
29    FileSequenceList.pm - Class for retrieving and processing the 'Sequence' values of the MSI 'File' table.
30
31=cut
32
33=head2 new($class)
34
35    Create a new FileSequenceList object.
36
37=cut
38sub new ($)
39{
40    my ($class) = @_;
41
42    my $self = {
43        'data' => undef
44    };
45    bless($self, $class);
46
47    return $self;
48}
49
50
51
52
53sub SetFromFileList ($$)
54{
55    my ($self, $files) = @_;
56
57    my %data = map {$_->{'uniquename'} => $_->{'sequencenumber'}} @$files;
58    $self->{'data'} = \%data;
59}
60
61
62
63
64sub SetFromMap ($$)
65{
66    my ($self, $map) = @_;
67
68    $self->{'data'} = $map;
69}
70
71
72
73
74sub GetFileCount ($)
75{
76    my ($self) = @_;
77
78    return scalar keys %{$self->{'data'}};
79}
80
81
82
83
84=head2 GetSequenceNumbers ($files)
85
86    $files is a hash that maps unique file names (File->File) to sequence
87    numbers (File->Sequence). The later is (expected to be) initially unset and
88    is set in this method.
89
90    For new files -- entries in the given $files that do not exist in the 'data'
91    member -- no sequence numbers are defined.
92
93    When there are removed files -- entries in the 'data' member that do not
94    exist in the given $files -- then a list of these files is returned.  In
95    that case the given $files remain unmodified.
96
97    The returned list is empty when everyting is OK.
98
99=cut
100sub GetSequenceNumbers ($$)
101{
102    my ($self, $files) = @_;
103
104    # Check if files have been removed.
105    my @missing = ();
106    foreach my $name (keys %{$self->{'data'}})
107    {
108        if ( ! defined $files->{$name})
109        {
110            push @missing, $name;
111        }
112    }
113    if (scalar @missing > 0)
114    {
115        # Yes.  Return the names of the removed files.
116        return @missing;
117    }
118
119    # No files where removed.  Set the sequence numbers.
120    foreach my $name (keys %$files)
121    {
122        $files->{$name} = $self->{'data'}->{$name};
123    }
124    return ();
125}
126
127
128
129
130sub GetDifference ($$)
131{
132    my ($self, $other) = @_;
133
134    # Create maps for easy reference.
135    my (@files_in_both, @files_in_self, @files_in_other);
136    foreach my $name (keys %{$self->{'data'}})
137    {
138        if (defined $other->{'data'}->{$name})
139        {
140            push @files_in_both, $name;
141        }
142        else
143        {
144            push @files_in_self, $name;
145        }
146    }
147    foreach my $name (keys %{$self->{'data'}})
148    {
149        if ( ! defined $self->{'data'}->{$name})
150        {
151            push @files_in_other, $name;
152        }
153    }
154
155    return (\@files_in_both, \@files_in_self, \@files_in_other);
156}
157
158
1591;
160