Преглед изворни кода

scripts: Use length instead of defined when checking environment variables

In these cases we are not interested if the variables are defined, but
if they have actual content.
Guillem Jover пре 12 година
родитељ
комит
b572af443f

+ 2 - 0
debian/changelog

@@ -16,6 +16,8 @@ dpkg (1.17.12) UNRELEASED; urgency=low
   * Use «tar --format=gnu» when creating source archives. This makes sure we
     get a deterministic output format, regardless of what tar defaults to.
     Thanks to Jan Blunck <jblunck@infradead.org>..
+  * Use perl's length instead of defined when checking some environment
+    variables, if we require them to have content.
 
   [ Updated programs translations ]
   * German (Sven Joachim).

+ 2 - 2
scripts/Dpkg/BuildFlags.pm

@@ -131,8 +131,8 @@ Update flags from the user configuration.
 sub load_user_config {
     my ($self) = @_;
     my $confdir = $ENV{XDG_CONFIG_HOME};
-    $confdir ||= $ENV{HOME} . '/.config' if defined $ENV{HOME};
-    if (defined $confdir) {
+    $confdir ||= $ENV{HOME} . '/.config' if length $ENV{HOME};
+    if (length $confdir) {
         $self->update_from_conffile("$confdir/dpkg/buildflags.conf", 'user');
     }
 }

+ 1 - 1
scripts/Dpkg/Source/Package.pm

@@ -400,7 +400,7 @@ sub check_signature {
         push @exec, 'gpg', '--no-default-keyring', '-q', '--verify';
     }
     if (scalar(@exec)) {
-        if (defined $ENV{HOME} and -r "$ENV{HOME}/.gnupg/trustedkeys.gpg") {
+        if (length $ENV{HOME} and -r "$ENV{HOME}/.gnupg/trustedkeys.gpg") {
             push @exec, '--keyring', "$ENV{HOME}/.gnupg/trustedkeys.gpg";
         }
         foreach my $vendor_keyring (run_vendor_hook('keyrings')) {

+ 1 - 1
scripts/Dpkg/Vendor/Ubuntu.pm

@@ -58,7 +58,7 @@ sub run_hook {
         if (defined($fields->{'Version'}) and defined($fields->{'Maintainer'}) and
            $fields->{'Version'} =~ /ubuntu/) {
            if ($fields->{'Maintainer'} !~ /ubuntu/i) {
-               if (defined ($ENV{DEBEMAIL}) and $ENV{DEBEMAIL} =~ /\@ubuntu\.com/) {
+               if (length $ENV{DEBEMAIL} and $ENV{DEBEMAIL} =~ /\@ubuntu\.com/) {
                    error(_g('Version number suggests Ubuntu changes, but Maintainer: does not have Ubuntu address'));
                } else {
                    warning(_g('Version number suggests Ubuntu changes, but Maintainer: does not have Ubuntu address'));

+ 1 - 1
scripts/dpkg-architecture.pl

@@ -254,7 +254,7 @@ if (action_needs(DEB_HOST | DEB_GNU_INFO)) {
 
 
 for my $k (keys %arch_vars) {
-    $v{$k} = $ENV{$k} if (defined ($ENV{$k}) && !$force);
+    $v{$k} = $ENV{$k} if (length $ENV{$k} && !$force);
 }
 
 if ($action eq 'l') {