diff options
| author | Joey Hess <joeyh@joeyh.name> | 2015-01-15 14:03:50 -0400 |
|---|---|---|
| committer | Joey Hess <joeyh@joeyh.name> | 2015-01-15 14:03:50 -0400 |
| commit | 47fdb99fbba21f724a2cb6e909c3801e3cc7ab22 (patch) | |
| tree | 6b97363e81def50d20a1e5aefb6a2a2519bfdcfa /src/Utility/Env.hs | |
| parent | 16031a7c26464485e7c11afdec7d0b80dfe2f5bf (diff) | |
| parent | 35cd06e4e6cad5bc6c9bbbd33642450dbd2de10c (diff) | |
Merge branch 'joeyconfig'
Conflicts:
privdata.joey/privdata.gpg
Diffstat (limited to 'src/Utility/Env.hs')
| -rw-r--r-- | src/Utility/Env.hs | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/Utility/Env.hs b/src/Utility/Env.hs index dd502fd3..ff6644fb 100644 --- a/src/Utility/Env.hs +++ b/src/Utility/Env.hs @@ -1,6 +1,6 @@ {- portable environment variables - - - Copyright 2013 Joey Hess <id@joeyh.name> + - Copyright 2013 Joey Hess <joey@kitenet.net> - - License: BSD-2-clause -} @@ -14,6 +14,7 @@ import Utility.Exception import Control.Applicative import Data.Maybe import qualified System.Environment as E +import qualified System.SetEnv #else import qualified System.Posix.Env as PE #endif @@ -39,27 +40,27 @@ getEnvironment = PE.getEnvironment getEnvironment = E.getEnvironment #endif -{- Returns True if it could successfully set the environment variable. +{- Sets an environment variable. To overwrite an existing variable, + - overwrite must be True. - - - There is, apparently, no way to do this in Windows. Instead, - - environment varuables must be provided when running a new process. -} -setEnv :: String -> String -> Bool -> IO Bool + - On Windows, setting a variable to "" unsets it. -} +setEnv :: String -> String -> Bool -> IO () #ifndef mingw32_HOST_OS -setEnv var val overwrite = do - PE.setEnv var val overwrite - return True +setEnv var val overwrite = PE.setEnv var val overwrite #else -setEnv _ _ _ = return False +setEnv var val True = System.SetEnv.setEnv var val +setEnv var val False = do + r <- getEnv var + case r of + Nothing -> setEnv var val True + Just _ -> return () #endif -{- Returns True if it could successfully unset the environment variable. -} -unsetEnv :: String -> IO Bool +unsetEnv :: String -> IO () #ifndef mingw32_HOST_OS -unsetEnv var = do - PE.unsetEnv var - return True +unsetEnv = PE.unsetEnv #else -unsetEnv _ = return False +unsetEnv = System.SetEnv.unsetEnv #endif {- Adds the environment variable to the input environment. If already |
