summaryrefslogtreecommitdiffstats
path: root/src/tests/mandb-purge-updates-timestamp
blob: 48666d80060d6fd42dfc010ad50c4d058acd9380 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#! /bin/sh

# If mandb purges missing pages, it updates the database's timestamp,
# without confusing itself into not scanning for newer pages.

: "${srcdir=.}"
# shellcheck source-path=SCRIPTDIR
. "$srcdir/testlib.sh"

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

init
fake_config /usr/share/man
MANPATH="$tmpdir/usr/share/man"
export MANPATH
db_ext="$(db_ext)"
case $DBTYPE in
	ndbm)	full_db_ext=.pag ;;
	*)	full_db_ext="$db_ext" ;;
esac

write_page test1 1 "$tmpdir/usr/share/man/man1/test1.1.gz" \
	UTF-8 gz t 'test1 \- test1(1)'
write_page test2 1 "$tmpdir/usr/share/man/man1/test2.1.gz" \
	UTF-8 gz t 'test2 \- test2(1)'
write_page test3 1 "$tmpdir/usr/share/man/man1/test3.1.gz" \
	UTF-8 gz t 'test3 \- test3(1)'
run $MANDB -C "$tmpdir/manpath.config" -u -q "$tmpdir/usr/share/man"
cat >"$tmpdir/1.exp" <<EOF
test1 -> "- 1 1 MTIME A - - gz test1(1)"
test2 -> "- 1 1 MTIME A - - gz test2(1)"
test3 -> "- 1 1 MTIME A - - gz test3(1)"
EOF
accessdb_filter "$tmpdir/usr/share/man/index$db_ext" >"$tmpdir/1.out"
expect_files_equal 'setup' "$tmpdir/1.exp" "$tmpdir/1.out"
mtime1="$(./get-mtime "$tmpdir/usr/share/man/index$full_db_ext")"

./fspause
rm -f "$tmpdir/usr/share/man/man1/test3.1.gz"
# Fool mandb into believing that this directory was not modified.  It will
# still run its purge step.
touch -r "$tmpdir/usr/share/man/index$db_ext" "$tmpdir/usr/share/man/man1"
run $MANDB -C "$tmpdir/manpath.config" -u -q "$tmpdir/usr/share/man"
cat >"$tmpdir/2.exp" <<EOF
test1 -> "- 1 1 MTIME A - - gz test1(1)"
test2 -> "- 1 1 MTIME A - - gz test2(1)"
EOF
accessdb_filter "$tmpdir/usr/share/man/index$db_ext" >"$tmpdir/2.out"
expect_files_equal 'remove test3' "$tmpdir/2.exp" "$tmpdir/2.out"
mtime2="$(./get-mtime "$tmpdir/usr/share/man/index$full_db_ext")"
test "$mtime1" != "$mtime2"
report 'mtime changed (1)' "$?"

./fspause
rm -f "$tmpdir/usr/share/man/man1/test2.1.gz"
write_page test4 1 "$tmpdir/usr/share/man/man1/test4.1.gz" \
	UTF-8 gz t 'test4 \- test4(1)'
run $MANDB -C "$tmpdir/manpath.config" -u -q "$tmpdir/usr/share/man"
cat >"$tmpdir/3.exp" <<EOF
test1 -> "- 1 1 MTIME A - - gz test1(1)"
test4 -> "- 1 1 MTIME A - - gz test4(1)"
EOF
accessdb_filter "$tmpdir/usr/share/man/index$db_ext" >"$tmpdir/3.out"
expect_files_equal 'remove test2, add test4' "$tmpdir/3.exp" "$tmpdir/3.out"
mtime3="$(./get-mtime "$tmpdir/usr/share/man/index$full_db_ext")"
test "$mtime2" != "$mtime3"
report 'mtime changed (2)' "$?"

finish