[xen-tools-dev] [PATCH v2 07/13] Harden this test.
Stéphane Jourdois
sjourdois at gmail.com
Sun Jul 18 22:04:17 CEST 2010
From: Stéphane Jourdois <stephane at jourdois.fr>
Read and test only the shebang, not the whole file, +typos.
Ignore empty files.
---
t/shell-syntax.t | 24 +++++++++++++-----------
1 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/t/shell-syntax.t b/t/shell-syntax.t
index a53a228..836eb45 100755
--- a/t/shell-syntax.t
+++ b/t/shell-syntax.t
@@ -34,26 +34,28 @@ sub checkFile
# We don't care about directories
return if ( ! -f $file );
- # Finally mercurial files are fine.
- return if ( $file =~ /\.(hg|git)\// );
+ # We don't care about empty files
+ return unless -s $file;
+
+ # Finally mercurial/git files are fine.
+ return if ( $file =~ /^\.\/\.(hg|git)\// );
# See if it is a shell script.
my $isShell = 0;
- # Read the file.
+ # Read the shebang
open( INPUT, "<", $file );
- foreach my $line ( <INPUT> )
+ my $line = <INPUT>;
+ close( INPUT );
+
+ # Check if it is really a shell file
+ if ( $line =~ /^#! ?\/bin\/(ba)?sh/ )
{
- if ( ( $line =~ /\/bin\/sh/ ) ||
- ( $line =~ /\/bin\/bash/ ) )
- {
- $isShell = 1;
- }
+ $isShell = 1;
}
- close( INPUT );
#
- # Return if it wasn't a perl file.
+ # Return if it wasn't a shell file.
#
return if ( ! $isShell );
--
1.7.1.1
More information about the xen-tools-dev
mailing list