#!/bin/bash
# Copyright 1999-2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id: prepalldocs 3483 2006-06-10 21:40:40Z genone $

source "${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"/isolated-functions.sh

z="$(find "${D}"usr/share/doc \( -type f -or -type l \) -not -name "*.gz" -not -name "*.js" 2>/dev/null)"

for y in ${z} ; do
	if [ -L "${y}" ] ; then
		# Symlink ...
		mylink="${y}"
		linkto="$(readlink "${y}")"

		if [ "${linkto##*.}" != "gz" ] ; then
			linkto="${linkto}.gz"
		fi
		if [ "${mylink##*.}" != "gz" ] ; then
			mylink="${mylink}.gz"
		fi

		vecho "fixing doc symlink: ${mylink##*/}"
		ln -snf "${linkto}" "${mylink}"
		if [ "${y}" != "${mylink}" ] ; then
			vecho "removing old symlink: ${y##*/}"
			rm -f "${y}"
		fi
	else
		if [ "${y##*.}" != "gz" ] ; then
			vecho "gzipping doc: ${y##*/}"
			gzip -f -9 "${y}"
		fi
	fi	
done
