aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShlomi Fish <shlomif@shlomifish.org>2015-07-25 16:55:57 +0300
committerShlomi Fish <shlomif@shlomifish.org>2015-07-25 16:55:57 +0300
commita9c0200fdad969907ec453e88d8242467c2b31fd (patch)
tree86e39e74c5aaeebeafa47f945feaaefcdf980092
parent84a02ca03cbd98e47388b4ab75ce27b3e0eb0239 (diff)
downloadspec-helper-a9c0200fdad969907ec453e88d8242467c2b31fd.tar
spec-helper-a9c0200fdad969907ec453e88d8242467c2b31fd.tar.gz
spec-helper-a9c0200fdad969907ec453e88d8242467c2b31fd.tar.bz2
spec-helper-a9c0200fdad969907ec453e88d8242467c2b31fd.tar.xz
spec-helper-a9c0200fdad969907ec453e88d8242467c2b31fd.zip
Fix $_ in compress_files.
-rw-r--r--NEWS4
-rwxr-xr-xcompress_files69
2 files changed, 43 insertions, 30 deletions
diff --git a/NEWS b/NEWS
index 99846ef..754ad95 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,7 @@
+2015-07-25 Shlomi Fish <shlomif@cpan.org> 0.31.10
+ * compress_files: More proper handling of $_. Convert as much as possible
+ to lexical variables.
+
2015-07-25 Shlomi Fish <shlomif@cpan.org> 0.31.9
* gprintf: eliminate warnings on perl-5.22.0-and-above.
* compress_files: Fix handling of $_ in the File::Find::find() callback.
diff --git a/compress_files b/compress_files
index 9d5e50f..4695f64 100755
--- a/compress_files
+++ b/compress_files
@@ -40,19 +40,21 @@ my @mandirs = map { "$buildroot/$_" } qw(
my (@sofiles, @sodests);
sub so_function {
- local ($_) = @_;
+ local $_ = $_;
+ my $fn = $_;
+
# skip symlinks
- return if -l $_;
+ return if -l $fn;
# skip directories
- return if -d $_;
+ return if -d $fn;
# The -s test is becuase a .so file tends to be small. We don't want
# to open every man page. 1024 is arbitrary.
- return if -s $_ > 1024;
+ return if -s $fn > 1024;
# skip excluded files
return if $exclude_pattern && $File::Find::name =~ $exclude_pattern;
# Test first line of file for the .so thing.
- open(my $in, $_);
+ open(my $in, $fn);
my $line = <$in>;
close($in);
if ($line =~ m/\.so\s+(.*)/) {
@@ -81,17 +83,19 @@ foreach my $sofile (@sofiles) {
# find non-compressed info/man pages
my @files;
sub function {
- local ($_) = @_;
+ local $_ = $_;
+ my $fn = $_;
+
# skip symlinks
- return if -l $_;
+ return if -l $fn;
# skip directories
- return if -d $_;
+ return if -d $fn;
# skip excluded files
return if $exclude_pattern && $File::Find::name =~ $exclude_pattern;
# skip compressed files
- return if /\.(?:gz|bz2|lzma|xz)$/;
+ return if $fn =~ /\.(?:gz|bz2|lzma|xz)$/;
# skip particular files
- return if $_ eq 'dir' || $_ eq 'whatis';
+ return if $fn eq 'dir' || $fn eq 'whatis';
push @files, $File::Find::name;
}
@@ -128,19 +132,21 @@ if (@files) {
sub link_function {
# $_ is already defined by File::Find.
#
+ local $_ = $_;
+ my $fn = $_;
# skip everything but symlinks
- return unless -l $_;
+ return unless -l $fn;
# skip non-dangling symlinks
- my $linkval = readlink($_);
+ my $linkval = readlink($fn);
return if -e "$File::Find::dir/$linkval";
if (-e "$File::Find::dir/$linkval$ext") {
- unlink $_;
- symlink "$linkval$ext", "$_$ext";
+ unlink $fn;
+ symlink "$linkval$ext", "$fn$ext";
} elsif ($File::Find::dir =~ m|man/|) {
# Bad link go on nowhere (any better idea) ?
- unlink $_;
+ unlink $fn;
}
return;
@@ -160,8 +166,8 @@ sub xargs {
# Figure out length of static portion of command.
my $static_length = 0;
- foreach (@_) {
- $static_length += length($_) + 1;
+ foreach my $str (@_) {
+ $static_length += length($str) + 1;
}
my @collect;
@@ -190,19 +196,22 @@ sub uncompress_files {
foreach my $dir (@mandirs) {
- File::Find::find(sub {
- local ($_) = @_;
- # skip symlinks
- return if -l $_;
- # skip directories
- return if -d $_;
- # skip excluded files
- return if $exclude_pattern && $File::Find::name =~ $exclude_pattern;
- # skip everything but files with wanted extension
- return if !/$extension$/;
-
- push @compressed_files, $File::Find::name;
- }, $dir) if -e $dir;
+ File::Find::find(
+ sub {
+ local $_ = $_;
+ my $fn = $_;
+ # skip symlinks
+ return if -l $fn;
+ # skip directories
+ return if -d $fn;
+ # skip excluded files
+ return if $exclude_pattern && $File::Find::name =~ $exclude_pattern;
+ # skip everything but files with wanted extension
+ return if $fn !~ /$extension$/;
+ push @compressed_files, $File::Find::name;
+ },
+ $dir
+ ) if -e $dir;
}
if (@compressed_files) {