*is-cached abstraction for envmon

ns
Mike Gerwitz 2014-06-14 23:05:01 -04:00
parent 4152425af3
commit d03ddbfa7a
1 changed files with 19 additions and 4 deletions

View File

@ -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 # Output null-byte-delimited names and values of variables added to the
# environment since the last diff and update the environment cache # environment since the last diff and update the environment cache
@ -87,12 +102,12 @@ __pkgsh-envmon-dodiff-adds()
{ {
local -r var="$1" val="$2" local -r var="$1" val="$2"
# ignore if it already exists (FIXME: this will fail if the in-memory if _pkgsh-envmon-is-cached "$var"; then
# value is empty) return 0
[ -z "${__pkgsh_envmon_env[$var]}" ] || return 0 fi
# output the difference and immediately add to the environment in memory # output the difference and immediately add to the environment in memory
echo -ne "$var=$val\000" echo -ne "$var=$val\000"
__pkgsh_envmon_env[$var]="$val" __pkgsh-envmon-envload "$var" "$val"
} }