3 # Compresses files and makes sure that symlinks pointing to the
4 # compressed files get fixed.
7 BEGIN { push @INC, "debian", "/usr/share/debhelper" }
11 foreach $PACKAGE (@{$dh{DOPACKAGES}}) {
12 $TMP=tmpdir($PACKAGE);
13 $compress=pkgfile($PACKAGE,"compress");
15 # Run the file name gathering commands from within the directory
16 # structure that will be effected.
18 verbose_print("cd $TMP");
19 chdir($TMP) || error("Can't cd to $TMP: $!");
21 # Figure out what files to compress.
23 # First of all, deal with any files specified right on the command line.
24 if (($PACKAGE eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) {
28 # The config file is a sh script that outputs the files to be compressed
29 # (typically using find).
30 push @files, split(/\n/,`sh $olddir/$compress 2>/dev/null`);
33 # By default, fall back to what the policy manual says to compress.
34 # Note that all the excludes of odd things like _z are because
35 # gzip refuses to compress such files, assumming they are zip files.
36 # I looked at the gzip source to get the complete list of such
37 # extentions: ".gz", ".z", ".taz", ".tgz", "-gz", "-z", "_z"
39 push @files, split(/\n/,`
40 find usr/info usr/share/info usr/man usr/share/man usr/X11*/man -type f ! -name "*.gz" 2>/dev/null || true;
41 find usr/doc usr/share/doc -type f \\( -size +4k -or -name "changelog*" \\) \\
42 \\( -name changelog.html -or ! -name "*.htm*" \\) \\
43 ! -name "*.gif" ! -iname "*.gz" \\
44 ! -iname "*.taz" ! -iname "*.tgz" ! -iname "*.z" \\
45 ! -iname "*-gz" ! -iname "*-z" ! -iname "*_z" \\
46 ! -name "copyright" 2>/dev/null || true
50 # Exclude files from compression.
51 if (@files && defined($dh{EXCLUDE}) && $dh{EXCLUDE}) {
55 foreach $x (@{$dh{EXCLUDE}}) {
66 # Look for files with hard links. If we are going to compress both,
67 # we can preserve the hard link across the compression and save
72 ($dev, $inode, undef, $nlink)=stat($_);
74 if (! $seen{"$inode.$dev"}) {
75 $seen{"$inode.$dev"}=$_;
80 $hardlinks{$_}=$seen{"$inode.$dev"};
89 xargs(\@f,"gzip","-9f");
92 # Now change over any files we can that used to be hard links so
94 foreach (keys %hardlinks) {
98 doit("ln","$hardlinks{$_}.gz","$_.gz");
101 verbose_print("cd $olddir");
104 # Fix up symlinks that were pointing to the uncompressed files.
105 open (FIND,"find $TMP -type l |");
108 ($directory)=m:(.*)/:;
109 $linkval=readlink($_);
110 if (! -e "$directory/$linkval" && -e "$directory/$linkval.gz") {
112 doit("ln","-sf","$linkval.gz","$_.gz");