Selaa lähdekoodia

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
Guillem Jover 12 vuotta sitten
vanhempi
commit
a580499ac5
5 muutettua tiedostoa jossa 56 lisäystä ja 7 poistoa
  1. 3 0
      debian/changelog
  2. 14 7
      scripts/Dpkg/Vendor.pm
  3. 2 0
      scripts/Makefile.am
  4. 33 0
      scripts/t/Dpkg_Vendor.t
  5. 4 0
      scripts/t/origins/gnewsense

+ 3 - 0
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).

+ 14 - 7
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)

+ 2 - 0
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 = \

+ 33 - 0
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');

+ 4 - 0
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