blob: 148a3f3733e3395b677b796a85152ea6bd342a2e (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
#!/bin/sh

# Drops cgit's output cache after a push, so new commits show up right away
# instead of once the cache-*-ttl minutes have passed. It only matters when
# cache-size in cgitrc is above 0, which turns the cache on.
#
# cgit names each cache slot after a hash of the request url, so there is no
# way to expire one repository's pages on their own and this clears the lot.
# cgit refills a slot the next time something asks for it. The cached
# repository scan goes too, which is what makes a brand new repository appear
# without waiting out cache-scan-ttl.
#
# The path below is the default cache-root, so a cgitrc that changes the
# setting needs the same change here. The web server owns the cache root, so
# the pushing user needs write access to it. Nothing here exits nonzero when
# that access is missing, so the pusher is not shown an error over a stale
# page.
#
# To install the hook, copy or link it to hooks/post-receive in each
# repository. Git runs one post-receive per repository, so fold this together
# with the age-file hook to have both.

set -eu

cache_root=/var/cache/cgit

test -d "$cache_root" || exit 0

# Everything directly under the cache root is a cache file, so the only thing
# worth keeping is the lock files, which belong to writers still working.
# The "! -name . -prune" pair is how POSIX find stays out of subdirectories.
find "$cache_root"/. ! -name . -prune ! -name '*.lock' -type f \
	-exec rm -f {} + || exit 0