blob: 34313b08417a8e02336bdc6c02c144699c02379f (
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
|
#!/bin/bash
# Copyright (C) 2025 taitep
# Part of aoctools (gitea.taitep.se/taitep/aoctools or github.com/taitep/aoctools)
# SPDX-License-Identifier: MIT
set -euo pipefail
AOC_DIR="${AOC_DIR:-$HOME/.aoc}"
CACHE_DIR="$AOC_DIR/cache"
usage() {
pname=$(basename "$0")
echo "Usage: $pname <year> <day?>" >&2
echo " $pname all"
exit 1
}
verify_int() {
if ! [[ "$1" =~ ^[0-9]+$ ]]; then
echo "'$1' is not an integer" >&2
usage
fi
}
if [ $# -gt 2 ] || [ $# -lt 1 ]; then
usage
fi
if [ "$1" = all ]; then
if [ ! -d "$CACHE_DIR" ]; then
echo "No cache present" >&2
exit 1
fi
echo "Clearing full cache" >&2
rm -rf "$CACHE_DIR"
exit
fi
year="$1"
verify_int "$year"
year_cache_dir="$CACHE_DIR/$year"
if [ $# -eq 1 ]; then
if [ ! -d "$year_cache_dir" ]; then
echo "No cache for $year present" >&2
exit 1
fi
echo "Clearing cache for year $year" >&2
rm -rf "$year_cache_dir"
exit
fi
day="$2"
verify_int "$day"
cache_file=$year_cache_dir/d$day.in
if [ ! -f "$cache_file" ]; then
echo "No cache for $year day $day present"
exit 1
fi
echo "Clearing cache for $year day $day" >&2
rm $cache_file
|