summaryrefslogtreecommitdiff
path: root/Utility
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-10-15 20:33:52 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-10-15 20:33:52 -0400
commita87f9b63077c8b93f4b2284d494c0081bd938f8d (patch)
treed56e424b73aecfca32f24b637fcc0dcc2050adce /Utility
parent10ff3282ee60cc41ad9d9ac71a99eea7053cebaa (diff)
Use haskell setenv library to clean up several ugly workarounds for inability to manipulate the environment on windows.
Didn't know that this library existed! This includes making git-annex not re-exec itself on start on windows, and making the test suite on Windows run tests without forking.
Diffstat (limited to 'Utility')
-rw-r--r--Utility/Env.hs29
-rw-r--r--Utility/Gpg.hs2
-rw-r--r--Utility/Lsof.hs2
3 files changed, 17 insertions, 16 deletions
diff --git a/Utility/Env.hs b/Utility/Env.hs
index 6763c24e1..bfb61aa8d 100644
--- a/Utility/Env.hs
+++ b/Utility/Env.hs
@@ -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 True
#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
diff --git a/Utility/Gpg.hs b/Utility/Gpg.hs
index f880e55fa..50f78a1de 100644
--- a/Utility/Gpg.hs
+++ b/Utility/Gpg.hs
@@ -334,7 +334,7 @@ testHarness a = do
setup = do
base <- getTemporaryDirectory
dir <- mktmpdir $ base </> "gpgtmpXXXXXX"
- void $ setEnv var dir True
+ setEnv var dir True
-- For some reason, recent gpg needs a trustdb to be set up.
_ <- pipeStrict [Params "--trust-model auto --update-trustdb"] []
_ <- pipeStrict [Params "--import -q"] $ unlines
diff --git a/Utility/Lsof.hs b/Utility/Lsof.hs
index ee4036b16..e44d13197 100644
--- a/Utility/Lsof.hs
+++ b/Utility/Lsof.hs
@@ -32,7 +32,7 @@ setup = do
when (isAbsolute cmd) $ do
path <- getSearchPath
let path' = takeDirectory cmd : path
- void $ setEnv "PATH" (intercalate [searchPathSeparator] path') True
+ setEnv "PATH" (intercalate [searchPathSeparator] path') True
{- Checks each of the files in a directory to find open files.
- Note that this will find hard links to files elsewhere that are open. -}