From d03ddbfa7a88b49c737c80f6ae0e097efc6705b8 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Sat, 14 Jun 2014 23:05:01 -0400 Subject: [PATCH] *is-cached abstraction for envmon --- src/envmon.sh | 23 +++++++++++++++++++---- 1 file 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 @@ -70,6 +70,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" }