Commit e8e0b9e9 authored by Sören Tempel's avatar Sören Tempel Committed by Natanael Copa

abuild: rewrite hardlink handling when compressing man pages

The problem is that gzip refuses to run if it detects that a file has
more than 1 link. Our existing solution (removing hardlinks, compressing
the man page and recreating the hardlinks) made certain assumptions
about inode order that are only given on Unix v7 like filesystems
meaning it didn't work properly on 'tree-based' filesystems like BTRFS
or ZFS.

This patch has a different more bulletproof approach: It simply replaces
all hardlinks with symlinks. This is way easier because symlinks (unlike
hardlinks) can point to a file that doesn't exist, therefore we can
update all links before compressing the file in an easy way.
parent 042921b7
...@@ -1407,29 +1407,33 @@ default_doc() { ...@@ -1407,29 +1407,33 @@ default_doc() {
done done
# compress man pages # compress man pages
local previnode= prevname= mandir="$subpkgdir"/usr/share/man local mandir="$subpkgdir"/usr/share/man
[ -d "$mandir" ] && find "$subpkgdir"/usr/share/man \ [ -d "$mandir" ] && find "$mandir" -type f \
-type f \( -name \*.[0-8n] -o -name \*.[0-8][a-z]* \) \ -a \( -name \*.[0-8n] -o -name \*.[0-8][a-z]* \) \
-exec stat -c "%i %n" {} \; | sort -n \ -exec stat -c "%i %n" \{\} \; | while read inode name; do
| while read inode name; do
# Skip hardlinks removed in last iteration.
if [ "$inode" = "$previnode" ]; then [ -f "$name" ] || continue
# update hard link
rm "$name" local islink=0
ln "$prevname".gz "$name".gz find "$mandir" -type f -links +1 \
else -a \( -name \*.[0-8n] -o -name \*.[0-8][a-z]* \) \
gzip -9 "$name" -exec stat -c "%i %n" \{\} \; | while read linode lname; do
fi if [ "$linode" = "$inode" -a "$lname" != "$name" ]; then
rm -f "$lname"
ln -s "${name##*/}".gz "$lname".gz
previnode="$inode" [ $islink -eq 0 ] && gzip -9 "$name"
done done
[ -d "$mandir" ] && find "$subpkgdir"/usr/share/man \ [ -d "$mandir" ] && find "$mandir" -type l \
-type l \( -name \*.[0-8n] -o -name \*.[0-8][a-z]* \) \ -a \( -name \*.[0-8n] -o -name \*.[0-8][a-z]* \) \
| while read symlink; do | while read symlink; do
ln -s $(readlink $symlink).gz "$symlink".gz ln -s $(readlink $symlink).gz "$symlink".gz
rm "$symlink" rm -f "$symlink"
done done
rm -f "$subpkgdir/usr/share/info/dir" rm -f "$subpkgdir/usr/share/info/dir"
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment