diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2023-03-03 13:49:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-03 13:49:56 +0100 |
commit | 0507462c0626d19b59b78e490b7b203df29e7bb0 (patch) | |
tree | ab53f035b878cd54be8cd93031c4669eba2201a5 /src/libutil | |
parent | 19c1a4699b2a19e38c9d3953e75c029b4faee2ce (diff) | |
parent | dc8820c71f841df49568099bf3889c7cfb2d92a9 (diff) |
Merge pull request #7918 from zimbatm/fix-empty-nix-store-env
treat empty NIX_STORE_DIR env vars as unset
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/util.cc | 5 | ||||
-rw-r--r-- | src/libutil/util.hh | 4 |
2 files changed, 9 insertions, 0 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc index e4af702a3..17ccf3554 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -54,6 +54,11 @@ std::optional<std::string> getEnv(const std::string & key) return std::string(value); } +std::optional<std::string> getEnvNonEmpty(const std::string & key) { + auto value = getEnv(key); + if (value == "") return {}; + return value; +} std::map<std::string, std::string> getEnv() { diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 75959d7e3..326c6b143 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -39,6 +39,10 @@ extern const std::string nativeSystem; /* Return an environment variable. */ std::optional<std::string> getEnv(const std::string & key); +/* Return a non empty environment variable. Returns nullopt if the env +variable is set to "" */ +std::optional<std::string> getEnvNonEmpty(const std::string & key); + /* Get the entire environment. */ std::map<std::string, std::string> getEnv(); |