From a87f9b63077c8b93f4b2284d494c0081bd938f8d Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 15 Oct 2014 20:33:52 -0400 Subject: 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. --- git-annex.hs | 39 +++++++++------------------------------ 1 file changed, 9 insertions(+), 30 deletions(-) (limited to 'git-annex.hs') diff --git a/git-annex.hs b/git-annex.hs index f1af0eea5..f2005e13e 100644 --- a/git-annex.hs +++ b/git-annex.hs @@ -19,9 +19,6 @@ import qualified Test #ifdef mingw32_HOST_OS import Utility.UserInfo import Utility.Env -import Config.Files -import System.Process -import System.Exit #endif main :: IO () @@ -33,7 +30,9 @@ main = do | isshell n = CmdLine.GitAnnexShell.run ps | otherwise = #ifdef mingw32_HOST_OS - winEnv gitannex ps + do + winEnv + gitannex ps #else gitannex ps #endif @@ -49,37 +48,17 @@ main = do #ifdef mingw32_HOST_OS {- On Windows, if HOME is not set, probe it and set it. - - This is a workaround for some Cygwin commands needing HOME to be set, - - and for there being no known way to set environment variables on - - Windows, except by passing an environment in each call to a program. - - While ugly, this workaround is easier than trying to ensure HOME is set - - in all calls to the affected programs. + - This is a workaround for some Cygwin commands needing HOME to be set. - - If TZ is set, unset it. - TZ being set can interfere with workarounds for Windows timezone - horribleness, and prevents getCurrentTimeZone from seeing the system - time zone. - - - - Due to Windows limitations, have to re-exec git-annex with the new - - environment. -} -winEnv :: ([String] -> IO ()) -> [String] -> IO () -winEnv a ps = do - e <- getEnvironment +winEnv :: IO () +winEnv = do home <- myHomeDir - let e' = wantedenv e home - if (e' /= e) - then do - cmd <- readProgramFile - (_, _, _, pid) <- createProcess (proc cmd ps) - { env = Just e' } - exitWith =<< waitForProcess pid - else a ps - where - wantedenv e home = delEntry "TZ" $ case lookup "HOME" e of - Nothing -> e - Just _ -> addEntries - [ ("HOME", home) - , ("CYGWIN", "nodosfilewarning") - ] e + setEnv "HOME" home False + setEnv "CYGWIN" "nodosfilewarning" True + unsetEnv "TZ" #endif -- cgit v1.2.3