6 Copyright - http://wiki.cyberleo.net/wiki/CyberLeo/COPYRIGHT?version=4
8 Set the following variables before sourcing this library:
10 kvs - Path and filename of the kvdb database file
17 [ -s "${kvs}" ] || echo "${t}${t}# KVSv0 id-key-value database" > "${kvs}"
19 # Add or replace a value stored for a given key and id in the kvs
21 [ "${1}" -a "${2}" ] || return 255
25 printf "%s\t%s\t%s\n" "${id}" "${var}" "${val}" >> "${kvs}"
28 # Fetch the most recent value stored for a given key and id from the kvs
30 [ "${1}" -a "${2}" ] || return 255
33 grep "^${id}${t}${var}${t}" "${kvs}" | tail -n 1 | cut -d"${t}" -f3-
36 # Does the kvs have any entries for a given ID?
38 [ "${1}" ] || return 255
40 grep -q "^${id}${t}" "${kvs}"
43 # Does the kvs have a given key for a given ID?
45 [ "${1}" -a "${2}" ] || return 255
48 grep -q "^${id}${t}${var}${t}" "${kvs}"
51 # Remove a given key with a given ID from the kvs
53 [ "${1}" -a "${2}" ] || return 255
56 grep -v "^${id}${t}${var}${t}" "${kvs}" > "${kvs}.tmp" && mv -f "${kvs}.tmp" "${kvs}" || rm -f "${kvs}.tmp"
59 # Remove all keys with a given ID from the kvs
61 [ "${1}" ] || return 255
63 grep -v "^${id}${t}" "${kvs}" > "${kvs}.tmp" && mv -f "${kvs}.tmp" "${kvs}" || rm -f "${kvs}.tmp"