diff options
author | Guillaume Rousse <guillomovitch@mandriva.org> | 2008-05-06 20:25:03 +0000 |
---|---|---|
committer | Guillaume Rousse <guillomovitch@mandriva.org> | 2008-05-06 20:25:03 +0000 |
commit | 88884d287a233a3d26bf860b1b8d6b2723ef640e (patch) | |
tree | 53861f281b2bb8222783f0528cedc01cfe3b9be4 /compress_files | |
parent | 5b808c8bfaf6e3f45fbbb4b040dd0b73ff24c4fa (diff) | |
download | spec-helper-88884d287a233a3d26bf860b1b8d6b2723ef640e.tar spec-helper-88884d287a233a3d26bf860b1b8d6b2723ef640e.tar.gz spec-helper-88884d287a233a3d26bf860b1b8d6b2723ef640e.tar.bz2 spec-helper-88884d287a233a3d26bf860b1b8d6b2723ef640e.tar.xz spec-helper-88884d287a233a3d26bf860b1b8d6b2723ef640e.zip |
don't use external find command, but File::Find everywhere, and honour EXCLUDE_FROM_COMPRESS variable
Diffstat (limited to 'compress_files')
-rwxr-xr-x | compress_files | 73 |
1 files changed, 68 insertions, 5 deletions
diff --git a/compress_files b/compress_files index 0e7beda..1837551 100755 --- a/compress_files +++ b/compress_files @@ -23,9 +23,23 @@ my $exclude_pattern = join('|', ); $exclude_pattern = qr/$exclude_pattern/; +my @sodirs = qw{ + usr/man + usr/X11R6/man + usr/lib/perl5/man +}; +my @mandirs = qw{ + usr/info + usr/share/info + usr/man + usr/share/man + usr/X11/man + usr/lib/perl5/man +}; + # Now the .so conversion. my (@sofiles, @sodests); -foreach my $dir (qw{usr/man usr/X11R6/man usr/lib/perl5/man}) { +foreach my $dir (@sodirs) { find(\&find_so_man, $dir) if -e $dir; } foreach my $sofile (@sofiles) { @@ -34,10 +48,17 @@ foreach my $sofile (@sofiles) { system "ln", "-sf",$sodest,$sofile; } -my @files = split(/\n/, `find usr/info usr/share/info usr/man usr/share/man usr/X11*/man usr/lib/perl5/man -type f ! -name "*.gz" -a ! -name "*.bz2" -a ! -name "*.lzma" ! -name 'dir' ! -name 'whatis' 2>/dev/null || true`); +my @files; +foreach my $dir (@mandirs) { + find(\&find_uncompressed_man, $dir) if -e $dir; +} if ($ext ne '.gz') { - my @gz_files = split(/\n/, `find usr/info usr/share/info usr/man usr/share/man usr/X11*/man usr/lib/perl5/man -type f -name "*.gz" 2>/dev/null || true`); + my @gz_files; + my $gz_function = get_find_compressed_man_function(\@gz_files, 'gz'); + foreach my $dir (@mandirs) { + find($gz_function, $dir) if -e $dir; + } if (@gz_files) { xargs(\@gz_files, "gzip", "-d"); die "Something wrong with the decompression of the gzip man/info file" @@ -46,7 +67,11 @@ if ($ext ne '.gz') { } } if ($ext ne '.bz2') { - my @bz_files = split(/\n/, `find usr/info usr/share/info usr/man usr/share/man usr/X11*/man usr/lib/perl5/man -type f -name "*.bz2" 2>/dev/null || true`); + my @bz_files; + my $bz_function = get_find_compressed_man_function(\@bz_files, 'bz2'); + foreach my $dir (@mandirs) { + find($bz_function, $dir) if -e $dir; + } if (@bz_files) { xargs(\@bz_files, "bzip2", "-d"); die "Something wrong with the decompression of the bzip2 man/info file" @@ -55,7 +80,11 @@ if ($ext ne '.bz2') { } } if ($ext ne '.lzma') { - my @lzma_files = split(/\n/, `find usr/info usr/share/info usr/man usr/share/man usr/X11*/man usr/lib/perl5/man -type f -name "*.lzma" 2>/dev/null || true`); + my @lzma_files; + my $lzma_function = get_find_compressed_man_function(\@lzma_files, 'lzma'); + foreach my $dir (@mandirs) { + find($lzma_function, $dir) if -e $dir; + } if (@lzma_files) { xargs(\@lzma_files, "lzmash", "-d"); die "Something wrong with the decompression of the lzma man/info file" @@ -188,3 +217,37 @@ sub find_so_man() { push @sodests, $solink; } } + +sub find_uncompressed_man { + # skip symlinks + return if -l $_; + # skip directories + return if -d $_; + # skip excluded files + return if $File::Find::name =~ $exclude_pattern; + # skip compressed files + return if $_ =~ /\.(?:gz|bz2|lzma)$/; + # skip particular files + return if $_ eq 'dir' || $_ eq 'whatis'; + + push @files, $File::Find::name; +} + +sub get_find_compressed_man_function { + my ($array, $extension) = @_; + + my $function = sub { + # skip symlinks + return if -l $_; + # skip directories + return if -d $_; + # skip excluded files + return if $File::Find::name =~ $exclude_pattern; + # skip everything but files with wanted extension + return if $_ !~ /\.$extension$/; + + push @$array, $File::Find::name; + }; + + return $function; +} |