summaryrefslogtreecommitdiff
path: root/dh_compress
diff options
context:
space:
mode:
authorRafael Kitover <rkitover@gmail.com>2015-08-07 14:04:58 -0400
committerNiels Thykier <niels@thykier.net>2015-09-26 08:57:53 +0200
commit60f59661194029a6bba28ebf39d0bf5193789bc5 (patch)
treefe67cce2ac04e8a022eff2dc76e0316d7a419581 /dh_compress
parent0df8fdb046add9ddd72a7fbfd2d36fc949b1faa8 (diff)
downloaddebhelper-60f59661194029a6bba28ebf39d0bf5193789bc5.tar.gz
fix file lists and abspaths for dh_compress w/test
Fix dh_compress to accept file names on the command line that it would otherwise compress anyway, by removing duplicates. Also allow dh_compress to accept absolute paths, by stripping the leading slashes. Add tests for the desired behavior in t/dh_compress.t . Fix an undefined warning in dh_compress that is sometimes triggered. Add a . -> lib symlink so that prove -vwlr t works. Signed-off-by: Niels Thykier <niels@thykier.net>
Diffstat (limited to 'dh_compress')
-rwxr-xr-xdh_compress13
1 files changed, 10 insertions, 3 deletions
diff --git a/dh_compress b/dh_compress
index 1b33ac9a..a587454a 100755
--- a/dh_compress
+++ b/dh_compress
@@ -8,7 +8,8 @@ dh_compress - compress files and fix symlinks in package build directories
use strict;
use warnings;
-use Cwd;
+use Cwd qw(getcwd abs_path);
+use File::Spec::Functions qw(abs2rel);
use Debian::Debhelper::Dh_Lib;
=head1 SYNOPSIS
@@ -92,7 +93,7 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
my @files;
# First of all, deal with any files specified right on the command line.
if (($package eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) {
- push @files, @ARGV;
+ push @files, map { s{^/+}{}; $_ } @ARGV;
}
if ($compress) {
# The compress file is a sh script that outputs the files to be compressed
@@ -155,7 +156,7 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
my %seen;
foreach (@files) {
my ($dev, $inode, undef, $nlink)=stat($_);
- if ($nlink > 1) {
+ if (defined $nlink && $nlink > 1) {
if (! $seen{"$inode.$dev"}) {
$seen{"$inode.$dev"}=$_;
push @f, $_;
@@ -170,6 +171,12 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
}
}
+ # normalize file names and remove duplicates
+ my @normalized = map abs2rel(abs_path($_)), @f;
+ my %uniq_f; @uniq_f{@normalized} = ();
+ @f = sort keys %uniq_f;
+
+ # do it
if (@f) {
# Make executables not be anymore.
xargs(\@f,"chmod","a-x");