Parcourir la source

scripts: Use new pkg_name_is_illegal() instead of ad-hoc checks

Guillem Jover il y a 14 ans
Parent
commit
2e62609bbe
3 fichiers modifiés avec 17 ajouts et 19 suppressions
  1. 5 11
      scripts/Dpkg/Vars.pm
  2. 6 4
      scripts/dpkg-gencontrol.pl
  3. 6 4
      scripts/dpkg-gensymbols.pl

+ 5 - 11
scripts/Dpkg/Vars.pm

@@ -1,3 +1,4 @@
+# Copyright © 2007-2009,2012 Guillem Jover <guillem@debian.org>
 # Copyright © 2007 Raphaël Hertzog <hertzog@debian.org>
 #
 # This program is free software; you can redistribute it and/or modify
@@ -18,29 +19,22 @@ package Dpkg::Vars;
 use strict;
 use warnings;
 
-our $VERSION = "0.01";
+our $VERSION = "0.02";
 
 use Dpkg::ErrorHandling;
 use Dpkg::Gettext;
+use Dpkg::Package;
 
 use base qw(Exporter);
 our @EXPORT = qw($sourcepackage set_source_package);
 
 our $sourcepackage;
 
-sub check_package_name {
-    my $name = shift || '';
-    $name =~ m/[^-+.0-9a-z]/o &&
-        error(_g("source package name `%s' contains illegal character `%s'"),
-              $name, $&);
-    $name =~ m/^[0-9a-z]/o ||
-        error(_g("source package name `%s' starts with non-alphanum"), $name);
-}
-
 sub set_source_package {
     my $v = shift;
+    my $err = pkg_name_is_illegal($v);
+    error(_g("source package name '%s' is illegal: %s"), $v, $err) if $err;
 
-    check_package_name($v);
     if (defined($sourcepackage)) {
         $v eq $sourcepackage ||
             error(_g("source package has two conflicting values - %s and %s"),

+ 6 - 4
scripts/dpkg-gencontrol.pl

@@ -4,6 +4,7 @@
 #
 # Copyright © 1996 Ian Jackson
 # Copyright © 2000,2002 Wichert Akkerman
+# Copyright © 2006-2012 Guillem Jover <guillem@debian.org>
 #
 # 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
@@ -28,6 +29,7 @@ use Dpkg;
 use Dpkg::Gettext;
 use Dpkg::ErrorHandling;
 use Dpkg::Arch qw(get_host_arch debarch_eq debarch_is);
+use Dpkg::Package;
 use Dpkg::Deps;
 use Dpkg::Control;
 use Dpkg::Control::Info;
@@ -91,10 +93,10 @@ Options:
 
 while (@ARGV) {
     $_=shift(@ARGV);
-    if (m/^-p([-+0-9a-z.]+)$/) {
-        $oppackage= $1;
-    } elsif (m/^-p(.*)/) {
-        error(_g("Illegal package name \`%s'"), $1);
+    if (m/^-p/) {
+        $oppackage = $';
+        my $err = pkg_name_is_illegal($oppackage);
+        error(_g("illegal package name '%s': %s"), $oppackage, $err) if $err;
     } elsif (m/^-c/) {
         $controlfile= $';
     } elsif (m/^-l/) {

+ 6 - 4
scripts/dpkg-gensymbols.pl

@@ -3,6 +3,7 @@
 # dpkg-gensymbols
 #
 # Copyright © 2007 Raphaël Hertzog
+# Copyright © 2007-2012 Guillem Jover <guillem@debian.org>
 #
 # 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
@@ -22,6 +23,7 @@ use warnings;
 
 use Dpkg;
 use Dpkg::Arch qw(get_host_arch);
+use Dpkg::Package;
 use Dpkg::Shlibs qw(@librarypaths);
 use Dpkg::Shlibs::Objdump;
 use Dpkg::Shlibs::SymbolFile;
@@ -95,8 +97,10 @@ Options:
 my @files;
 while (@ARGV) {
     $_ = shift(@ARGV);
-    if (m/^-p([-+0-9a-z.]+)$/) {
-	$oppackage = $1;
+    if (m/^-p/) {
+	$oppackage = $';
+	my $err = pkg_name_is_illegal($oppackage);
+	error(_g("illegal package name '%s': %s"), $oppackage, $err) if $err;
     } elsif (m/^-c(\d)?$/) {
 	$compare = defined($1) ? $1 : 1;
     } elsif (m/^-q$/) {
@@ -115,8 +119,6 @@ while (@ARGV) {
 	    warning(_g("pattern '%s' did not match any file"), $file)
 		unless scalar(@to_add);
 	}
-    } elsif (m/^-p(.*)/) {
-	error(_g("Illegal package name \`%s'"), $1);
     } elsif (m/^-P(.+)$/) {
 	$packagebuilddir = $1;
 	$packagebuilddir =~ s{/+$}{};