diff options
author | Guillem Jover <guillem@debian.org> | 2014-04-02 16:11:19 +0200 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2014-04-21 16:29:58 +0200 |
commit | a580499ac5fa4e1e7feee69d08dfd044d790a275 (patch) | |
tree | 47e59280e8f11baf9749fb417708c7fb2472d49a | |
parent | 82d38b898e5d3ca243460f705c949c14a16a7c8a (diff) | |
download | dpkg-a580499ac5fa4e1e7feee69d08dfd044d790a275.tar.gz |
Dpkg::Vendor: Try to load Vendor modules from the parent vendors
If there's no available module for the requested vendor, try loading
a Parent until one is found, or we fallback to Default.
Closes: #735978
-rw-r--r-- | debian/changelog | 3 | ||||
-rw-r--r-- | scripts/Dpkg/Vendor.pm | 21 | ||||
-rw-r--r-- | scripts/Makefile.am | 2 | ||||
-rw-r--r-- | scripts/t/Dpkg_Vendor.t | 33 | ||||
-rw-r--r-- | scripts/t/origins/gnewsense | 4 |
5 files changed, 56 insertions, 7 deletions
diff --git a/debian/changelog b/debian/changelog index 78caa97ba..f8de5c8d4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -40,6 +40,9 @@ dpkg (1.17.7) UNRELEASED; urgency=low md5sum for the .changes file after signing the .dsc. Closes: #742535 * Cache vendor info Control::Hash objects in Dpkg::Vendor::get_vendor_info() when parsing the vendor file on each hook invocation. + * If the vendor does not have a Dpkg::Vendor module, try loading a module + from the parent vendors, before falling back to Dpkg::Vendor::Default. + Closes: #735978 [ Updated dpkg translations ] * German (Sven Joachim). diff --git a/scripts/Dpkg/Vendor.pm b/scripts/Dpkg/Vendor.pm index 12aa81279..81ff1f884 100644 --- a/scripts/Dpkg/Vendor.pm +++ b/scripts/Dpkg/Vendor.pm @@ -148,18 +148,25 @@ sub get_vendor_object { return $OBJECT_CACHE{$vendor} if exists $OBJECT_CACHE{$vendor}; my ($obj, @names); - if ($vendor ne 'Default') { - push @names, $vendor, lc($vendor), ucfirst($vendor), ucfirst(lc($vendor)); - } - foreach my $name (@names, 'Default') { + push @names, $vendor, lc($vendor), ucfirst($vendor), ucfirst(lc($vendor)); + + foreach my $name (@names) { eval qq{ require Dpkg::Vendor::$name; \$obj = Dpkg::Vendor::$name->new(); }; - last unless $@; + unless ($@) { + $OBJECT_CACHE{$vendor} = $obj; + return $obj; + } + } + + my $info = get_vendor_info($vendor); + if (defined $info and defined $info->{'Parent'}) { + return get_vendor_object($info->{'Parent'}); + } else { + return get_vendor_object('Default'); } - $OBJECT_CACHE{$vendor} = $obj; - return $obj; } =item Dpkg::Vendor::run_vendor_hook($hookid, @params) diff --git a/scripts/Makefile.am b/scripts/Makefile.am index f88eb0081..f8d94951a 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -195,6 +195,7 @@ test_cases = \ t/Dpkg_Deps.t \ t/Dpkg_Path.t \ t/Dpkg_Util.t \ + t/Dpkg_Vendor.t \ t/Dpkg_Changelog.t \ t/Dpkg_Changelog_Ubuntu.t \ t/Dpkg_Control.t \ @@ -263,6 +264,7 @@ test_data = \ t/merge_changelogs/ch-merged-pr-basic \ t/origins/debian \ t/origins/default \ + t/origins/gnewsense \ t/origins/ubuntu test_data_objects = \ diff --git a/scripts/t/Dpkg_Vendor.t b/scripts/t/Dpkg_Vendor.t new file mode 100644 index 000000000..658a83ea9 --- /dev/null +++ b/scripts/t/Dpkg_Vendor.t @@ -0,0 +1,33 @@ +#!/usr/bin/perl +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +use strict; +use warnings; + +use Test::More tests => 5; + +use_ok('Dpkg::Vendor', qw(get_current_vendor get_vendor_object)); + +my ($vendor, $obj); + +$vendor = get_current_vendor(); +is($vendor, 'Debian', 'Check current vendor name'); + +$obj = get_vendor_object(); +is(ref($obj), 'Dpkg::Vendor::Debian', 'Check current vendor object'); +$obj = get_vendor_object('gNewSense'); +is(ref($obj), 'Dpkg::Vendor::Debian', 'Check parent fallback vendor object'); +$obj = get_vendor_object('Ubuntu'); +is(ref($obj), 'Dpkg::Vendor::Ubuntu', 'Check specific vendor object'); diff --git a/scripts/t/origins/gnewsense b/scripts/t/origins/gnewsense new file mode 100644 index 000000000..e67f86296 --- /dev/null +++ b/scripts/t/origins/gnewsense @@ -0,0 +1,4 @@ +Vendor: gNewSense +Vendor-URL: http://www.gnewsense.org/ +Bugs: https://savannah.nongnu.org/bugs/?group=gnewsense +Parent: Debian |