[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[SCM] Debian package checker branch, master, updated. 2.5.4-67-g42439a9



The following commit has been merged in the master branch:
commit 42439a9bb6e027a47703d7347ceb9ca4b3442db6
Author: Niels Thykier <niels@thykier.net>
Date:   Thu Dec 22 11:54:38 2011 +0100

    Find the cmd in the shebang line of executable dh config files
    
    It will allow checking syntax/semantics of the file based on the
    "executing cmd" (e.g. for dh-exec).
    
    Signed-off-by: Niels Thykier <niels@thykier.net>

diff --git a/checks/debhelper b/checks/debhelper
index 59a00df..a955bcd 100644
--- a/checks/debhelper
+++ b/checks/debhelper
@@ -344,7 +344,8 @@ foreach my $file (sort readdir(DEBIAN)) {
                 _tag_if_executable ($file, "$droot/$file");
             } else {
                 if (-x "$droot/$file") {
-                    unless (_can_be_run ("debian/$file", "$droot/$file")) {
+                    my $cmd =  _shebang_cmd  ("debian/$file", "$droot/$file");
+                    unless ( $cmd ) {
                         tag 'executable-debhelper-file-without-being-executable', "debian/$file";
                     }
 
@@ -482,24 +483,31 @@ sub _tag_if_executable {
     tag 'package-file-is-executable', "debian/$file" if -f $path && -x _;
 }
 
-sub _can_be_run {
+# Return the command after the #! in the file (if any).
+# - if there is no command or no #! line, the empty string is returned.
+sub _shebang_cmd {
     my ($pkgpath, $fspath) = @_;
     my $magic;
-    my $cbr = 0;
+    my $cmd = '';
     open my $fd, '<', $fspath or fail "opening $pkgpath: $!";
     if (read $fd, $magic, 2) {
         if ($magic eq '#!') {
-            my $sp = <$fd>;
-            chomp $sp;
+            $cmd = <$fd>;
+            chomp $cmd;
 
             # It is beyond me why anyone would place a lincity data
             # file here...  but if they do, we will handle it
             # correctly.
-            $cbr = 1 unless $sp =~ m/^#!/o;
+            $cmd = '' if $cmd =~ m/^#!/o;
+
+            # Strip whitespace if any
+            $cmd =~ s/^\s++//o;
+            $cmd =~ s/\s++$//o;
         }
     }
     close $fd;
 
+
     # We are not checking if it is an ELF executable.  While debhelper
     # allows this (i.e. it also checks for <pkg>.<file>.<arch>), it is
     # no cross-compilation safe.  This is because debhelper uses
@@ -509,7 +517,8 @@ sub _can_be_run {
     # Oh yeah, it is also a terrible waste to keep pre-compiled
     # binaries for all architectures in the source as well. :)
 
-    return $cbr;
+
+    return $cmd;
 }
 
 1;

-- 
Debian package checker


Reply to: