~ubuntu-branches/ubuntu/utopic/dpkg/utopic

« back to all changes in this revision

Viewing changes to scripts/Dpkg/Index.pm

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2013-11-17 10:42:09 UTC
  • mfrom: (1.6.2 sid) (1.5.18 jessie)
  • Revision ID: package-import@ubuntu.com-20131117104209-ixwjosuxm5q99qt7
Tags: 1.17.1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Change the multiarch downgrade version checks in prerm/postrm
    from 1.16.2 to 1.16.0~ to reflect when multiarch landed in Ubuntu.
  - Migrate dpkg multiarch conffile (and other multi-arch-related
    conf settings) to the new DB with dpkg --add-architecture, but
    keep a copy of the old conffile if it was modified.
  - Out of paranoia, keep an option handler for foreign-architecture
    that informs people that they need to scrub their config files
    and upgrade, on the off chance that the above migration fails
    for some reason (this mitigates the chances of leaving users with
    a dpkg that fails to run due to a broken config).
  - Add DPKG_UNTRANSLATED_MESSAGES environment check so that higher-level
    tools can get untranslated dpkg terminal log messages while at the
    same time having translated debconf prompts.  This is useful for tools
    that hide the dpkg terminal by default and use apport for bug
    reporting with the untranslated error message.
  - Apply patch from Steve McIntyre to special-case armhf/armel ELF
    objects in Shlibs/Objdump.pm, so we don't get incorrect deps.
  - lib/dpkg/pkg-spec.c: map unqualified package names of multiarch-same
    packages to the native arch instead of throwing an error, so that we
    don't break on upgrade when there are unqualified names stored in
    dpkg's own trigger database.
  - Add logic to the postinst to `dpkg --add-architecture i386' on new
    installs on amd64, and to also do so on upgrades from pre-conffile
    Ubuntu versions, mimicking our previous behaviour with the conffile.
  - Apply a workaround from mvo to consider RC packages as multiarch,
    during the dpkg consistency checks. (see LP: 1015567 and 1057367).
  - Add ppc64el/powerpc64le support to cputable (backported from 1.17.2).
* Forward-port manpages-it dpkg/dpkg-dev/dselect Replaces from 1.16.12.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
use strict;
19
19
use warnings;
20
20
 
21
 
our $VERSION = "1.00";
 
21
our $VERSION = '1.00';
22
22
 
23
23
use Dpkg::Gettext;
24
24
use Dpkg::ErrorHandling;
25
25
use Dpkg::Control;
26
26
use Dpkg::Compression::FileHandle;
27
27
 
28
 
use base qw(Dpkg::Interface::Storable);
 
28
use parent qw(Dpkg::Interface::Storable);
29
29
 
30
30
use overload
31
 
    '@{}' => sub { return $_[0]->{'order'} },
 
31
    '@{}' => sub { return $_[0]->{order} },
32
32
    fallback => 1;
33
33
 
34
34
=encoding utf8
63
63
    };
64
64
    bless $self, $class;
65
65
    $self->set_options(%opts);
66
 
    if (exists $opts{'load'}) {
67
 
        $self->load($opts{'load'});
 
66
    if (exists $opts{load}) {
 
67
        $self->load($opts{load});
68
68
    }
69
69
 
70
70
    return $self;
91
91
    my ($self, %opts) = @_;
92
92
 
93
93
    # Default values based on type
94
 
    if (exists $opts{'type'}) {
95
 
        my $t = $opts{'type'};
 
94
    if (exists $opts{type}) {
 
95
        my $t = $opts{type};
96
96
        if ($t == CTRL_INFO_PKG or $t == CTRL_INDEX_SRC or
97
97
                 $t == CTRL_INDEX_PKG or $t == CTRL_PKG_DEB) {
98
98
            $self->{get_key_func} = sub { return $_[0]->{Package}; };
100
100
            $self->{get_key_func} = sub { return $_[0]->{Source}; };
101
101
        } elsif ($t == CTRL_CHANGELOG) {
102
102
            $self->{get_key_func} = sub {
103
 
                return $_[0]->{Source} . "_" . $_[0]->{Version};
 
103
                return $_[0]->{Source} . '_' . $_[0]->{Version};
104
104
            };
105
105
        } elsif ($t == CTRL_FILE_CHANGES) {
106
106
            $self->{get_key_func} = sub {
107
 
                return $_[0]->{Source} . "_" . $_[0]->{Version} . "_" .
 
107
                return $_[0]->{Source} . '_' . $_[0]->{Version} . '_' .
108
108
                       $_[0]->{Architecture};
109
109
            };
110
110
        } elsif ($t == CTRL_FILE_VENDOR) {
111
111
            $self->{get_key_func} = sub { return $_[0]->{Vendor}; };
112
112
        } elsif ($t == CTRL_FILE_STATUS) {
113
113
            $self->{get_key_func} = sub {
114
 
                return $_[0]->{Package} . "_" . $_[0]->{Architecture};
 
114
                return $_[0]->{Package} . '_' . $_[0]->{Architecture};
115
115
            };
116
116
        }
117
117
    }
129
129
 
130
130
sub get_type {
131
131
    my ($self) = @_;
132
 
    return $self->{'type'};
 
132
    return $self->{type};
133
133
}
134
134
 
135
135
=item $index->add($item, [$key])
143
143
sub add {
144
144
    my ($self, $item, $key) = @_;
145
145
    unless (defined $key) {
146
 
        $key = $self->{'get_key_func'}($item);
147
 
    }
148
 
    if (not exists $self->{'items'}{$key}) {
149
 
        push @{$self->{'order'}}, $key;
150
 
    }
151
 
    $self->{'items'}{$key} = $item;
 
146
        $key = $self->{get_key_func}($item);
 
147
    }
 
148
    if (not exists $self->{items}{$key}) {
 
149
        push @{$self->{order}}, $key;
 
150
    }
 
151
    $self->{items}{$key} = $item;
152
152
}
153
153
 
154
154
=item $index->load($file)
190
190
 
191
191
sub new_item {
192
192
    my ($self) = @_;
193
 
    return Dpkg::Control->new(type => $self->{'type'});
 
193
    return Dpkg::Control->new(type => $self->{type});
194
194
}
195
195
 
196
196
=item my $item = $index->get_by_key($key)
201
201
 
202
202
sub get_by_key {
203
203
    my ($self, $key) = @_;
204
 
    return $self->{'items'}{$key} if exists $self->{'items'}{$key};
205
 
    return undef;
 
204
    return $self->{items}{$key} if exists $self->{items}{$key};
 
205
    return;
206
206
}
207
207
 
208
208
=item my @keys = $index->get_keys(%criteria)
219
219
    my ($self, %crit) = @_;
220
220
    my @selected = @{$self->{order}};
221
221
    foreach my $s_crit (keys %crit) { # search criteria
222
 
        if (ref($crit{$s_crit}) eq "Regexp") {
 
222
        if (ref($crit{$s_crit}) eq 'Regexp') {
223
223
            @selected = grep {
224
 
                $self->{'items'}{$_}{$s_crit} =~ $crit{$s_crit}
 
224
                $self->{items}{$_}{$s_crit} =~ $crit{$s_crit}
225
225
            } @selected;
226
 
        } elsif (ref($crit{$s_crit}) eq "CODE") {
 
226
        } elsif (ref($crit{$s_crit}) eq 'CODE') {
227
227
            @selected = grep {
228
 
                &{$crit{$s_crit}}($self->{'items'}{$_}{$s_crit});
 
228
                &{$crit{$s_crit}}($self->{items}{$_}{$s_crit});
229
229
            } @selected;
230
230
        } else {
231
231
            @selected = grep {
232
 
                $self->{'items'}{$_}{$s_crit} eq $crit{$s_crit}
 
232
                $self->{items}{$_}{$s_crit} eq $crit{$s_crit}
233
233
            } @selected;
234
234
        }
235
235
    }
244
244
 
245
245
sub get {
246
246
    my ($self, %crit) = @_;
247
 
    return map { $self->{'items'}{$_} } $self->get_keys(%crit);
 
247
    return map { $self->{items}{$_} } $self->get_keys(%crit);
248
248
}
249
249
 
250
250
=item $index->remove_by_key($key)
255
255
 
256
256
sub remove_by_key {
257
257
    my ($self, $key) = @_;
258
 
    @{$self->{'order'}} = grep { $_ ne $key } @{$self->{'order'}};
259
 
    return delete $self->{'items'}{$key};
 
258
    @{$self->{order}} = grep { $_ ne $key } @{$self->{order}};
 
259
    return delete $self->{items}{$key};
260
260
}
261
261
 
262
262
=item my @items = $index->remove(%criteria)
271
271
    my (%keys, @ret);
272
272
    foreach my $key (@keys) {
273
273
        $keys{$key} = 1;
274
 
        push @ret, $self->{'items'}{$key} if defined wantarray;
275
 
        delete $self->{'items'}{$key};
 
274
        push @ret, $self->{items}{$key} if defined wantarray;
 
275
        delete $self->{items}{$key};
276
276
    }
277
 
    @{$self->{'order'}} = grep { not exists $keys{$_} } @{$self->{'order'}};
 
277
    @{$self->{order}} = grep { not exists $keys{$_} } @{$self->{order}};
278
278
    return @ret;
279
279
}
280
280
 
289
289
 
290
290
sub merge {
291
291
    my ($self, $other, %opts) = @_;
292
 
    $opts{'keep_keys'} = 1 unless exists $opts{'keep_keys'};
 
292
    $opts{keep_keys} = 1 unless exists $opts{keep_keys};
293
293
    foreach my $key ($other->get_keys()) {
294
 
        $self->add($other->get_by_key($key), $opts{'keep_keys'} ? $key : undef);
 
294
        $self->add($other->get_by_key($key), $opts{keep_keys} ? $key : undef);
295
295
    }
296
296
}
297
297
 
306
306
sub sort {
307
307
    my ($self, $func) = @_;
308
308
    if (defined $func) {
309
 
        @{$self->{'order'}} = sort {
310
 
            &$func($self->{'items'}{$a}, $self->{'items'}{$b})
311
 
        } @{$self->{'order'}};
 
309
        @{$self->{order}} = sort {
 
310
            &$func($self->{items}{$a}, $self->{items}{$b})
 
311
        } @{$self->{order}};
312
312
    } else {
313
 
        @{$self->{'order'}} = sort @{$self->{'order'}};
 
313
        @{$self->{order}} = sort @{$self->{order}};
314
314
    }
315
315
}
316
316
 
330
330
 
331
331
sub output {
332
332
    my ($self, $fh) = @_;
333
 
    my $str = "";
 
333
    my $str = '';
334
334
    foreach my $key ($self->get_keys()) {
335
335
        if (defined $fh) {
336
336
            print $fh $self->get_by_key($key) . "\n";