clean up from windows porting

This commit is contained in:
Joey Hess 2013-05-11 18:23:41 -04:00
parent d6bf05a66d
commit 18bdff3fae
28 changed files with 57 additions and 72 deletions

View file

@ -14,8 +14,9 @@ import Utility.LogFile
#ifndef __WINDOWS__
import System.Posix
#endif
#else
import System.Posix.Types
#endif
{- Run an action as a daemon, with all output sent to a file descriptor.
-

View file

@ -10,28 +10,35 @@
module Utility.Env where
#ifdef __WINDOWS__
import qualified System.Environment as E
import Utility.Exception
import qualified System.Environment as E
#else
import qualified System.Posix.Env as E
import qualified System.Posix.Env as PE
#endif
{- Posix getEnv is faster than the one in System.Environment,
- so use when available. -}
getEnv :: String -> IO (Maybe String)
#ifndef __WINDOWS__
getEnv = E.getEnv
getEnv = PE.getEnv
#else
getEnv = catchMaybeIO . E.getEnv
#endif
getEnvDefault :: String -> String -> IO String
#ifndef __WINDOWS__
getEnvDefault = E.getEnvDefault
getEnvDefault = PE.getEnvDefault
#else
getEnvDefault var fallback = fromMaybe fallback <$> getEnv var
#endif
getEnvironment :: IO [(String, String)]
#ifndef __WINDOWS__
getEnvironment = PE.getEnvironment
#else
getEnvironment = E.getEnvironment
#endif
{- Returns True if it could successfully set the environment variable.
-
- There is, apparently, no way to do this in Windows. Instead,
@ -39,8 +46,18 @@ getEnvDefault var fallback = fromMaybe fallback <$> getEnv var
setEnv :: String -> String -> Bool -> IO Bool
#ifndef __WINDOWS__
setEnv var val overwrite = do
E.setEnv var val overwrite
PE.setEnv var val overwrite
return True
#else
setEnv _ _ _ = return False
#endif
{- Returns True if it could successfully unset the environment variable. -}
unsetEnv :: String -> IO Bool
#ifndef __WINDOWS__
unsetEnv var = do
PE.unsetEnv var
return True
#else
unsetEnv _ _ _ = return False
#endif

View file

@ -12,9 +12,10 @@ module Utility.FileMode where
import Common
import Control.Exception (bracket)
import Utility.Exception
import System.PosixCompat.Types
import System.PosixCompat.Files
#ifndef __WINDOWS__
import System.Posix.Files
#endif
import Foreign (complement)
{- Applies a conversion function to a file's mode. -}

View file

@ -13,11 +13,9 @@ import System.Posix.Types
import Control.Applicative
import Control.Concurrent
import Control.Exception (bracket)
#ifndef mingw32_HOST_OS
import System.Posix.Env (setEnv, unsetEnv, getEnv)
#endif
import Common
import Utility.Env
newtype KeyIds = KeyIds [String]
deriving (Ord, Eq)
@ -229,7 +227,7 @@ testHarness a = do
setup = do
base <- getTemporaryDirectory
dir <- mktmpdir $ base </> "gpgtmpXXXXXX"
setEnv var dir True
void $ setEnv var dir True
_ <- pipeStrict [Params "--import -q"] $ unlines
[testSecretKey, testKey]
return dir

View file

@ -9,7 +9,6 @@ module Utility.InodeCache where
import Common
import System.PosixCompat.Types
import System.PosixCompat.Files
import Utility.QuickCheck
data InodeCachePrim = InodeCachePrim FileID FileOffset EpochTime

View file

@ -12,7 +12,6 @@ module Utility.LogFile where
import Common
import System.Posix.Types
import System.PosixCompat.Files
openLog :: FilePath -> IO Fd
#ifndef __WINDOWS__

View file

@ -11,9 +11,9 @@ module Utility.Lsof where
import Common
import Build.SysConfig as SysConfig
import Utility.Env
import System.Posix.Types
import System.Posix.Env
data LsofOpenMode = OpenReadWrite | OpenReadOnly | OpenWriteOnly | OpenUnknown
deriving (Show, Eq)
@ -32,7 +32,7 @@ setupLsof = do
when (isAbsolute cmd) $ do
path <- getSearchPath
let path' = takeDirectory cmd : path
setEnv "PATH" (intercalate [searchPathSeparator] path') True
void $ 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. -}

View file

@ -20,7 +20,6 @@ import Network.URI
import qualified Network.Browser as Browser
import Network.HTTP
import Data.Either
import System.PosixCompat.Files
import qualified Build.SysConfig

View file

@ -14,7 +14,6 @@ module Utility.UserInfo (
) where
import Control.Applicative
import System.Posix.Types
import System.PosixCompat
import Utility.Env