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" }