#! /bin/sh

# What happens when a manual page changes from a regular file to a symbolic
# link?
#   http://bugs.debian.org/490582

: ${srcdir=.}
. "$srcdir/testlib.sh"

: ${MANDB=mandb}
: ${ACCESSDB=accessdb}

init
fake_config /usr/share/man
db_ext="$(db_ext)"

write_page fs 5 "$tmpdir/usr/share/man/man5/fs.5.gz" \
	UTF-8 gz t 'fs \- fs(5)'
run_clean_path $MANDB -C "$tmpdir/manpath.config" -u -q "$tmpdir/usr/share/man"
cat >"$tmpdir/1.exp" <<EOF
fs -> "- 5 5 MTIME A - - gz fs(5)"
EOF
accessdb_filter "$tmpdir/usr/share/man/index$db_ext" >"$tmpdir/1.out"
expect_pass 'fs(5) setup' 'diff "$tmpdir/1.exp" "$tmpdir/1.out"'

next_second
write_page filesystems 5 "$tmpdir/usr/share/man/man5/filesystems.5.gz" \
	UTF-8 gz t 'filesystems \- filesystems(5)'
ln -sf filesystems.5.gz "$tmpdir/usr/share/man/man5/fs.5.gz"
run_clean_path $MANDB -C "$tmpdir/manpath.config" -u -q "$tmpdir/usr/share/man"
cat >"$tmpdir/2.exp" <<EOF
filesystems -> "- 5 5 MTIME A - - gz filesystems(5)"
fs -> "- 5 5 MTIME B - - gz filesystems(5)"
EOF
accessdb_filter "$tmpdir/usr/share/man/index$db_ext" >"$tmpdir/2.out"
expect_pass 'mandb notices regular file -> symlink' \
	'diff "$tmpdir/2.exp" "$tmpdir/2.out"'

finish
