blob: 21550a98b4ba8c04c259d14a67a28e5b1f41663b (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
#!/bin/sh
#
# Example hook that drops cgit's output cache after a push, so new commits
# show up right away instead of once the cache-*-ttl minutes have passed.
#
# This only matters when cache-size in your 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.
#
# This hook assumes the default cache-root of "/var/cache/cgit".  If you
# change the value in your cgitrc then you must also change it 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 the file "hooks/post-receive" in
# each of your repositories.  Git runs one post-receive per repository, so
# fold this together with the agefile hook if you want both.
#

set -eu

cache_root=/var/cache/cgit

[ -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