Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <mike@mikegerwitz.com>2014-06-14 23:05:01 -0400
committerMike Gerwitz <mike@mikegerwitz.com>2014-06-17 01:44:08 -0400
commitd03ddbfa7a88b49c737c80f6ae0e097efc6705b8 (patch)
tree3eb88b500193b60de67e4ea3419387779899dc74
parent4152425af3369e0d15ff5cc7dd2e6635de4d861b (diff)
downloadpkgsh-ns.tar.gz
pkgsh-ns.tar.bz2
pkgsh-ns.zip
*is-cached abstraction for envmonns
-rw-r--r--src/envmon.sh23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/envmon.sh b/src/envmon.sh
index 40c2f1e..770f376 100644
--- a/src/envmon.sh
+++ b/src/envmon.sh
@@ -71,6 +71,21 @@ __pkgsh-envmon-envload()
##
+# Exits with a zero status if $name exists in the environment cache and is
+# not empty
+#
+# Otherwise, exits with a non-zero status.
+#
+_pkgsh-envmon-is-cached()
+{
+ local -r name="$1"
+
+ # FIXME: this will fail if the in-memory value is empty
+ [ -n "${__pkgsh_envmon_env[$var]}" ]
+}
+
+
+##
# Output null-byte-delimited names and values of variables added to the
# environment since the last diff and update the environment cache
#
@@ -87,12 +102,12 @@ __pkgsh-envmon-dodiff-adds()
{
local -r var="$1" val="$2"
- # ignore if it already exists (FIXME: this will fail if the in-memory
- # value is empty)
- [ -z "${__pkgsh_envmon_env[$var]}" ] || return 0
+ if _pkgsh-envmon-is-cached "$var"; then
+ return 0
+ fi
# output the difference and immediately add to the environment in memory
echo -ne "$var=$val\000"
- __pkgsh_envmon_env[$var]="$val"
+ __pkgsh-envmon-envload "$var" "$val"
}