mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-25 07:00:43 +00:00
777cb35eb8
For example graphviz has chained symlinked manpages: dot2gxl.1 is a symlink to gv2gxl.1 which is a symlink to gxl2gv.1 The second loop replaces each non-compressed symlink to a compressed symlink. The target is determined with 'readlink -f', which follows links recursively until the first name that is not a link (so either the 'target name' or the first 'dangling' symlink). This means that if the loop converted dot2gxl.1 before converting gv2gxl.1 it would add a symlink `dot2gxl.1.gz->gxl2gv.1.gz`. When it converted gv2gxl.1 first, it would then add a `dot2gxl.1.gz->gv2gxl.1.gz` symlink. Both are 'correct', but it's weird the result depends on the order in which 'find' returns the files. This PR makes the behaviour deterministic. fixes #104708
34 lines
966 B
Bash
34 lines
966 B
Bash
fixupOutputHooks+=('if [ -z "${dontGzipMan-}" ]; then compressManPages "$prefix"; fi')
|
|
|
|
compressManPages() {
|
|
local dir="$1"
|
|
|
|
if [ -L "$dir"/share ] || [ -L "$dir"/share/man ] || [ ! -d "$dir/share/man" ]
|
|
then return
|
|
fi
|
|
echo "gzipping man pages under $dir/share/man/"
|
|
|
|
# Compress all uncompressed manpages. Don't follow symlinks, etc.
|
|
find "$dir"/share/man/ -type f -a '!' -regex '.*\.\(bz2\|gz\)$' -print0 \
|
|
| while IFS= read -r -d $'\0' f
|
|
do
|
|
if gzip -c -n "$f" > "$f".gz; then
|
|
rm "$f"
|
|
else
|
|
rm "$f".gz
|
|
fi
|
|
done
|
|
|
|
# Point symlinks to compressed manpages.
|
|
find "$dir"/share/man/ -type l -a '!' -regex '.*\.\(bz2\|gz\)$' -print0 \
|
|
| sort -z \
|
|
| while IFS= read -r -d $'\0' f
|
|
do
|
|
local target
|
|
target="$(readlink -f "$f")"
|
|
if [ -f "$target".gz ]; then
|
|
ln -sf "$target".gz "$f".gz && rm "$f"
|
|
fi
|
|
done
|
|
}
|