-
Notifications
You must be signed in to change notification settings - Fork 0
/
shlibs_hash
executable file
·68 lines (58 loc) · 1.02 KB
/
shlibs_hash
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
#! /bin/sh
# brings hash API to SH
#
# Usage :
# HASH=$(hash_create)
# hash_set $HASH foo bar
# hash_get $HASH foo
# ...
# hash_destroy $HASH
hash_check() {
[ -z "$1" ] && return 1
[ ! -e "$1/0_shlib_hash.canary" ] && return 2
return 0
}
hash_create() {
HASH_DIR=$(mktemp -d)
echo "hash for $0 : $$" > ${HASH_DIR}/0_shlib_hash.canary
echo $HASH_DIR
}
hash_destroy() {
hash_check "$@" && HASH_DIR="$1" || return 1
shift
rm -Rf "$HASH_DIR"
}
hash_len()
{
hash_check "$@" && HASH_DIR="$1" || return 1
shift
(
cd "$HASH_DIR"
LAST_ELEM=$(ls -1r | head -n 1)
[ "$LAST_ELEM" = "0_shlib_hash.canary" ] && echo 0 || echo $LAST_ELEM
)
}
hash_set()
{
hash_check "$@" && HASH_DIR="$1" || return 1
shift
(
cd "$HASH_DIR"
# XXX - Should be escaped !
HASH_ELEM="$1"
shift
echo "$@" > $HASH_ELEM
)
}
hash_get()
{
hash_check "$@" && HASH_DIR="$1" || return 1
shift
(
cd "$HASH_DIR"
# XXX - Should be escaped !
HASH_ELEM="$1"
shift
[ -r $HASH_ELEM ] && cat "$HASH_ELEM"
)
}