File tree 1 file changed +6
-8
lines changed
cabal-install/src/Distribution/Client 1 file changed +6
-8
lines changed Original file line number Diff line number Diff line change @@ -145,9 +145,7 @@ withEnv :: String -> String -> IO a -> IO a
145
145
withEnv k v m = do
146
146
mb_old <- lookupEnv k
147
147
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
151
149
152
150
-- | Executes the action with a list of environment variables and
153
151
-- corresponding overrides, where
@@ -160,15 +158,15 @@ withEnv k v m = do
160
158
withEnvOverrides :: [(String , Maybe FilePath )] -> IO a -> IO a
161
159
withEnvOverrides overrides m = do
162
160
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
165
163
where
166
164
envVars :: [String ]
167
165
envVars = map fst overrides
168
166
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
172
170
173
171
-- | Executes the action, increasing the PATH environment
174
172
-- in some way
You can’t perform that action at this time.
0 commit comments