Skip to content

Commit d5dbf56

Browse files
andreasabelmergify[bot]
authored andcommitted
Cosmetics in cabal-install...Utils: factor out setOrUnsetEnv
1 parent a47b0ad commit d5dbf56

File tree

1 file changed

+6
-8
lines changed
  • cabal-install/src/Distribution/Client

1 file changed

+6
-8
lines changed

cabal-install/src/Distribution/Client/Utils.hs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,7 @@ withEnv :: String -> String -> IO a -> IO a
145145
withEnv k v m = do
146146
mb_old <- lookupEnv k
147147
setEnv k v
148-
m `Exception.finally` (case mb_old of
149-
Nothing -> unsetEnv k
150-
Just old -> setEnv k old)
148+
m `Exception.finally` setOrUnsetEnv k mb_old
151149

152150
-- | Executes the action with a list of environment variables and
153151
-- corresponding overrides, where
@@ -160,15 +158,15 @@ withEnv k v m = do
160158
withEnvOverrides :: [(String, Maybe FilePath)] -> IO a -> IO a
161159
withEnvOverrides overrides m = do
162160
mb_olds <- traverse lookupEnv envVars
163-
traverse_ (uncurry update) overrides
164-
m `Exception.finally` zipWithM_ update envVars mb_olds
161+
traverse_ (uncurry setOrUnsetEnv) overrides
162+
m `Exception.finally` zipWithM_ setOrUnsetEnv envVars mb_olds
165163
where
166164
envVars :: [String]
167165
envVars = map fst overrides
168166

169-
update :: String -> Maybe FilePath -> IO ()
170-
update var Nothing = unsetEnv var
171-
update var (Just val) = setEnv var val
167+
setOrUnsetEnv :: String -> Maybe String -> IO ()
168+
setOrUnsetEnv var Nothing = unsetEnv var
169+
setOrUnsetEnv var (Just val) = setEnv var val
172170

173171
-- | Executes the action, increasing the PATH environment
174172
-- in some way

0 commit comments

Comments
 (0)