mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-20 01:07:18 +03:00
Change withEnv to not clear the whole env (#5281)
The way we use `withEnv` it is really intended to set a few environment variables in an already existing environment instead of clearing everything before. This PR changes it to do only that. changelog_begin changelog_end closes #5280
This commit is contained in:
parent
3fc1175436
commit
a84311ac39
@ -33,7 +33,9 @@ import qualified Data.Conduit.Tar as Tar
|
||||
-- unix specific
|
||||
import System.PosixCompat.Files (createSymbolicLink)
|
||||
|
||||
-- | Replace all environment variables for test action, then restore them.
|
||||
-- | Set the given environment variables, then restore them.
|
||||
-- Envirnoment variables not in the given list are unmodified.
|
||||
--
|
||||
-- Avoids System.Environment.setEnv because it treats empty strings as
|
||||
-- "delete environment variable", unlike main-tester's withEnv which
|
||||
-- consequently conflates (Just "") with Nothing.
|
||||
@ -41,11 +43,7 @@ withEnv :: [(String, Maybe String)] -> IO t -> IO t
|
||||
withEnv vs m = bracket pushEnv popEnv (const m)
|
||||
where
|
||||
pushEnv :: IO [(String, Maybe String)]
|
||||
pushEnv = do
|
||||
oldEnv <- getEnvironment
|
||||
let ks = map fst vs
|
||||
vs' = [(key, Nothing) | (key, _) <- oldEnv, key `notElem` ks] ++ vs
|
||||
replaceEnv vs'
|
||||
pushEnv = replaceEnv vs
|
||||
|
||||
popEnv :: [(String, Maybe String)] -> IO ()
|
||||
popEnv vs' = void $ replaceEnv vs'
|
||||
|
Loading…
Reference in New Issue
Block a user