-
Notifications
You must be signed in to change notification settings - Fork 0
/
expireCaches
executable file
·120 lines (111 loc) · 3.37 KB
/
expireCaches
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/sh
basePath=`dirname $0`
export PATH="$basePath/utils:$PATH"
if test -s /etc/keengreeper.conf; then
. /etc/keengreeper.conf
fi
if test -z "$LOGDIR"; then
export LOGDIR=`pwd`/logs
fi
if test -z "$TMPDIR"; then
export TMPDIR=`pwd`/tmp
fi
if test -z "$WORKDIR"; then
export WORKDIR=/home/`id -un`/git
fi
if test -z "$DBDIR"; then
export DBDIR=$WORKDIR
fi
if test -z "$CACHETTL"; then
export CACHETTL=3600
fi
test -d $LOGDIR || mkdir -p $LOGDIR
test -d $TMPDIR || mkdir -p $TMPDIR
test -d $DBDIR || mkdir -p $DBDIR
if ! test -d $WORKDIR; then
echo "CRITICAL: $WORKDIR does not exist" >&2
exit 1
elif ! test -d $DBDIR; then
echo "CRITICAL: $DBDIR does not exist" >&2
exit 1
elif ! test -s $DBDIR/nodejs-update-db; then
cat <<EOF >&2
CRITICAL: nodejs-update-db absent or empty
use $basePath/configure to create an empty dataset, and configure
which repositories our job should be working with.
EOF
exit 1
elif ! checkTmpdir; then
exit 1
fi
TMPFILE=$TMPDIR/$1.$$
#if listRepository >/dev/null 2>&1; then
# echo "refreshing npmjs local cache"
# nodeDbExpireCache >/dev/null 2>&1 || true
#fi
echo "building active modules list"
for repository in `listRepository`
do
if test "$1"; then
if ! echo $repository | grep -E "$1" >/dev/null; then
test "$DEBUG" && echo "skipping $repository - does not match pattern" >&2
continue
fi
fi
if ! listDependencies $repository >/dev/null 2>&1; then
echo "skipping $repository - failed listing dependencies" >&2
continue
fi
echo "building dependencies tree for $repository" >&2
listDependencies $repository | while read dependency version
do
skipreason=
if echo $version | grep -E '(((http(s|)|ssh|file):)|/)' >/dev/null; then
skipreason="non-npm dependency"
elif ! nodeDbGetCache $dependency >/dev/null 2>&1; then
if ! getVersionFromNpmjs $dependency >/dev/null 2>&1; then
skipreason="failed getting last revision from npmjs.com"
elif ! nodeDbAddCache $dependency >/dev/null 2>&1; then
skipreason="failed updating npmjs cache"
fi
fi
if test "$skipreason"; then
test "$DEBUG" && echo "skipping $repository::$dependency - $skipreason" >&2
continue
elif test "$version" = latest; then
if resolveVersion $repository $dependency >/dev/null 2>/dev/null; then
localVersion=`resolveVersion $repository $dependency`
else
localVersion=`nodeDbGetCache $dependency 2>/dev/null`
fi
elif echo "$version" | grep -E '[~xX^]' >/dev/null; then
if resolveVersion $repository $dependency >/dev/null 2>/dev/null; then
localVersion=`resolveVersion $repository $dependency`
else
localVersion=`echo $version | sed -e 's|^[~^]||' -e 's|[xX]|0|g'`
fi
else
localVersion=$version
fi
test "$DEBUG" && echo "found $dependency $version -> $localVersion" >&2
echo "$dependency $localVersion"
done
done | sort -u >$TMPFILE
echo "pruning records from NMPJS cache"
nodeDbListCache | sed 's|^\([^ ]*\), .*|\1|' | while read module
do
if ! grep "^$module " $TMPFILE >/dev/null; then
nodeDbEvictCache $module
fi
done
echo "pruning records from Snyk cache"
snykDbListCache | sed 's|^\([^@]*\)@\([^: ]*\)[: ].*|\1 \2|' \
| sort -u | while read module version
do
if ! grep "^$module $version$" $TMPFILE >/dev/null; then
snykDbEvictCache $module $version
fi
done
rm -f $TMPFILE
echo done
exit 0