diff options
-rwxr-xr-x | Annex/Branch.hs | 6 | ||||
-rwxr-xr-x | Annex/Content/Direct.hs | 2 | ||||
-rwxr-xr-x | Annex/Direct.hs | 2 | ||||
-rwxr-xr-x | Annex/Environment.hs | 10 | ||||
-rwxr-xr-x | Annex/Link.hs | 2 | ||||
-rwxr-xr-x | Annex/Perms.hs | 1 | ||||
-rwxr-xr-x | Annex/Ssh.hs | 8 | ||||
-rw-r--r-- | Assistant/Install.hs | 3 | ||||
-rw-r--r-- | Assistant/XMPP/Git.hs | 2 | ||||
-rwxr-xr-x | Backend/SHA.hs | 1 | ||||
-rwxr-xr-x | Backend/WORM.hs | 2 | ||||
-rwxr-xr-x | Command/TransferKeys.hs | 2 | ||||
-rw-r--r-- | Command/WebApp.hs | 4 | ||||
-rwxr-xr-x | Common.hs | 2 | ||||
-rwxr-xr-x | Creds.hs | 6 | ||||
-rwxr-xr-x | Git/CurrentRepo.hs | 4 | ||||
-rw-r--r-- | Git/Index.hs | 2 | ||||
-rwxr-xr-x | Logs/Transfer.hs | 1 | ||||
-rwxr-xr-x | Test.hs | 20 | ||||
-rwxr-xr-x | Utility/Daemon.hs | 3 | ||||
-rwxr-xr-x | Utility/Env.hs | 27 | ||||
-rwxr-xr-x | Utility/FileMode.hs | 5 | ||||
-rwxr-xr-x | Utility/Gpg.hs | 6 | ||||
-rwxr-xr-x | Utility/InodeCache.hs | 1 | ||||
-rwxr-xr-x | Utility/LogFile.hs | 1 | ||||
-rw-r--r-- | Utility/Lsof.hs | 4 | ||||
-rwxr-xr-x | Utility/Url.hs | 1 | ||||
-rwxr-xr-x | Utility/UserInfo.hs | 1 |
28 files changed, 57 insertions, 72 deletions
diff --git a/Annex/Branch.hs b/Annex/Branch.hs index 8c3fb41f6..9a89a65c3 100755 --- a/Annex/Branch.hs +++ b/Annex/Branch.hs @@ -24,11 +24,6 @@ module Annex.Branch ( ) where import qualified Data.ByteString.Lazy.Char8 as L -#ifdef __ANDROID__ -import System.Posix.Env (getEnv) -#else -import System.Environment (getEnvironment) -#endif import Common.Annex import Annex.BranchState @@ -45,6 +40,7 @@ import Git.FilePath import Annex.CatFile import Annex.Perms import qualified Annex +import Utility.Env {- Name of the branch that is used to store git-annex's information. -} name :: Git.Ref diff --git a/Annex/Content/Direct.hs b/Annex/Content/Direct.hs index 1aa3c9105..54befdf73 100755 --- a/Annex/Content/Direct.hs +++ b/Annex/Content/Direct.hs @@ -33,8 +33,6 @@ import Utility.TempFile import Logs.Location import Utility.InodeCache -import System.PosixCompat.Files - {- Absolute FilePaths of Files in the tree that are associated with a key. -} associatedFiles :: Key -> Annex [FilePath] associatedFiles key = do diff --git a/Annex/Direct.hs b/Annex/Direct.hs index 5d679eee6..596c90994 100755 --- a/Annex/Direct.hs +++ b/Annex/Direct.hs @@ -27,8 +27,6 @@ import Utility.InodeCache import Utility.CopyFile import Annex.Perms -import System.PosixCompat.Files - {- Uses git ls-files to find files that need to be committed, and stages - them into the index. Returns True if some changes were staged. -} stageDirect :: Annex Bool diff --git a/Annex/Environment.hs b/Annex/Environment.hs index fd757ee2c..33569386e 100755 --- a/Annex/Environment.hs +++ b/Annex/Environment.hs @@ -10,16 +10,10 @@ module Annex.Environment where import Common.Annex -#ifndef __WINDOWS__ +import Utility.Env import Utility.UserInfo -#endif import qualified Git.Config -#ifndef __WINDOWS__ -import System.Posix.Env -#endif -import Network.BSD - {- Checks that the system's environment allows git to function. - Git requires a GECOS username, or suitable git configuration, or - environment variables. -} @@ -41,7 +35,7 @@ checkEnvironmentIO = where #ifndef __ANDROID__ -- existing environment is not overwritten - ensureEnv var val = setEnv var val False + ensureEnv var val = void $ setEnv var val False #else -- Environment setting is broken on Android, so this is dealt with -- in runshell instead. diff --git a/Annex/Link.hs b/Annex/Link.hs index 0a72f75ca..931836d31 100755 --- a/Annex/Link.hs +++ b/Annex/Link.hs @@ -19,8 +19,6 @@ import qualified Git.UpdateIndex import qualified Annex.Queue import Git.Types -import System.PosixCompat.Files - type LinkTarget = String {- Checks if a file is a link to a key. -} diff --git a/Annex/Perms.hs b/Annex/Perms.hs index de01ae0f8..f5925b741 100755 --- a/Annex/Perms.hs +++ b/Annex/Perms.hs @@ -22,7 +22,6 @@ import qualified Annex import Config import System.Posix.Types -import System.PosixCompat.Files withShared :: (SharedRepository -> Annex a) -> Annex a withShared a = maybe startup a =<< Annex.getState Annex.shared diff --git a/Annex/Ssh.hs b/Annex/Ssh.hs index 56109774b..1f924ecad 100755 --- a/Annex/Ssh.hs +++ b/Annex/Ssh.hs @@ -14,9 +14,6 @@ module Annex.Ssh ( ) where import qualified Data.Map as M -#ifndef __WINDOWS__ -import System.Posix.Env -#endif import Common.Annex import Annex.LockPool @@ -24,6 +21,7 @@ import Annex.Perms import qualified Build.SysConfig as SysConfig import qualified Annex import Config +import Utility.Env {- Generates parameters to ssh to a given host (or user@host) on a given - port, with connection caching. -} @@ -78,11 +76,7 @@ sshCacheDir ) | otherwise = return Nothing where -#ifndef __WINDOWS__ gettmpdir = liftIO $ getEnv "GIT_ANNEX_TMP_DIR" -#else - gettmpdir = return Nothing -#endif usetmpdir tmpdir = liftIO $ catchMaybeIO $ do createDirectoryIfMissing True tmpdir return tmpdir diff --git a/Assistant/Install.hs b/Assistant/Install.hs index 278190b35..227d1bc03 100644 --- a/Assistant/Install.hs +++ b/Assistant/Install.hs @@ -17,6 +17,7 @@ import Config.Files import Utility.FileMode import Utility.Shell import Utility.TempFile +import Utility.Env #ifdef darwin_HOST_OS import Utility.OSX @@ -24,8 +25,6 @@ import Utility.OSX import Utility.FreeDesktop #endif -import System.Posix.Env - standaloneAppBase :: IO (Maybe FilePath) standaloneAppBase = getEnv "GIT_ANNEX_APP_BASE" diff --git a/Assistant/XMPP/Git.hs b/Assistant/XMPP/Git.hs index f48178985..f087f6d1f 100644 --- a/Assistant/XMPP/Git.hs +++ b/Assistant/XMPP/Git.hs @@ -32,10 +32,10 @@ import qualified Remote as Remote import Remote.List import Utility.FileMode import Utility.Shell +import Utility.Env import Network.Protocol.XMPP import qualified Data.Text as T -import System.Posix.Env import System.Posix.Types import System.Process (std_in, std_out, std_err) import Control.Concurrent diff --git a/Backend/SHA.hs b/Backend/SHA.hs index f906dd3bb..a735ce1e5 100755 --- a/Backend/SHA.hs +++ b/Backend/SHA.hs @@ -18,7 +18,6 @@ import qualified Build.SysConfig as SysConfig import Data.Digest.Pure.SHA import qualified Data.ByteString.Lazy as L import Data.Char -import System.PosixCompat.Files type SHASize = Int diff --git a/Backend/WORM.hs b/Backend/WORM.hs index 03c7f9899..3471eedc1 100755 --- a/Backend/WORM.hs +++ b/Backend/WORM.hs @@ -12,8 +12,6 @@ import Types.Backend import Types.Key import Types.KeySource -import System.PosixCompat.Files - backends :: [Backend] backends = [backend] diff --git a/Command/TransferKeys.hs b/Command/TransferKeys.hs index d83170bbc..2f5ea1fe4 100755 --- a/Command/TransferKeys.hs +++ b/Command/TransferKeys.hs @@ -9,8 +9,6 @@ module Command.TransferKeys where -import System.PosixCompat.Files - import Common.Annex import Command import Annex.Content diff --git a/Command/WebApp.hs b/Command/WebApp.hs index b4307a21f..705ff6980 100644 --- a/Command/WebApp.hs +++ b/Command/WebApp.hs @@ -158,7 +158,11 @@ firstRun listenhost = do sendurlback v _origout _origerr url _htmlshim = putMVar v url openBrowser :: Maybe FilePath -> FilePath -> String -> Maybe Handle -> Maybe Handle -> IO () +#ifdef __ANDROID__ openBrowser mcmd htmlshim realurl outh errh = do +#else +openBrowser mcmd htmlshim _realurl outh errh = do +#endif hPutStrLn (fromMaybe stdout outh) $ "Launching web browser on " ++ url hFlush stdout environ <- cleanEnvironment @@ -16,8 +16,8 @@ import "MissingH" System.Path as X import System.FilePath as X import System.Directory as X import System.IO as X hiding (FilePath) +import System.PosixCompat.Files as X #ifndef mingw32_HOST_OS -import System.Posix.Files as X import System.Posix.IO as X #endif import System.Exit as X @@ -15,11 +15,9 @@ import Utility.FileMode import Crypto import Types.Remote (RemoteConfig, RemoteConfigKey) import Remote.Helper.Encryptable (remoteCipher, embedCreds) +import Utility.Env (setEnv) import System.Environment -#ifndef mingw32_HOST_OS -import System.Posix.Env (setEnv) -#endif import qualified Data.ByteString.Lazy.Char8 as L import qualified Data.Map as M import Utility.Base64 @@ -115,7 +113,7 @@ setEnvCredPair (l, p) storage = do set penv p where (uenv, penv) = credPairEnvironment storage - set var val = setEnv var val True + set var val = void $ setEnv var val True #else setEnvCredPair _ _ = error "setEnvCredPair TODO" #endif diff --git a/Git/CurrentRepo.hs b/Git/CurrentRepo.hs index 4b8c1fca8..769956aee 100755 --- a/Git/CurrentRepo.hs +++ b/Git/CurrentRepo.hs @@ -11,13 +11,13 @@ module Git.CurrentRepo where #ifndef __WINDOWS__ import System.Posix.Directory (changeWorkingDirectory) -import System.Posix.Env (getEnv, unsetEnv) #endif import Common import Git.Types import Git.Construct import qualified Git.Config +import Utility.Env {- Gets the current git repository. - @@ -51,7 +51,7 @@ get = do v <- getEnv s case v of Just d -> do - unsetEnv s + void $ unsetEnv s Just <$> absPath d Nothing -> return Nothing #else diff --git a/Git/Index.hs b/Git/Index.hs index 80196ef78..5b660bb30 100644 --- a/Git/Index.hs +++ b/Git/Index.hs @@ -7,7 +7,7 @@ module Git.Index where -import System.Posix.Env (setEnv, unsetEnv, getEnv) +import Utility.Env {- Forces git to use the specified index file. - diff --git a/Logs/Transfer.hs b/Logs/Transfer.hs index 3f36311a2..6f28ef115 100755 --- a/Logs/Transfer.hs +++ b/Logs/Transfer.hs @@ -20,7 +20,6 @@ import Utility.Percentage import Utility.QuickCheck import System.Posix.Types -import System.PosixCompat.Files import Data.Time.Clock import Data.Time.Clock.POSIX import Data.Time @@ -13,7 +13,6 @@ import Test.QuickCheck.Test import System.Posix.Directory (changeWorkingDirectory) import System.Posix.Files -import System.Posix.Env import Control.Exception.Extensible import qualified Data.Map as M import System.IO.HVFS (SystemFS(..)) @@ -53,6 +52,7 @@ import qualified Utility.Verifiable import qualified Utility.Process import qualified Utility.Misc import qualified Utility.InodeCache +import qualified Utility.Env main :: IO () main = do @@ -726,7 +726,7 @@ test_bup_remote = "git-annex bup remote" ~: intmpclonerepo $ when Build.SysConfi test_crypto :: Test test_crypto = "git-annex crypto" ~: intmpclonerepo $ when Build.SysConfig.gpg $ do -- force gpg into batch mode for the tests - setEnv "GPG_BATCH" "1" True + void $ Utility.Env.setEnv "GPG_BATCH" "1" True Utility.Gpg.testTestHarness @? "test harness self-test failed" Utility.Gpg.testHarness $ do createDirectory "dir" @@ -947,20 +947,20 @@ prepare = do -- and so does git_annex_output. Make sure that the just-built -- git annex is used. cwd <- getCurrentDirectory - p <- getEnvDefault "PATH" "" - setEnv "PATH" (cwd ++ ":" ++ p) True - setEnv "TOPDIR" cwd True + p <- Utility.Env.getEnvDefault "PATH" "" + void $ Utility.Env.setEnv "PATH" (cwd ++ ":" ++ p) True + void $Utility.Env.setEnv "TOPDIR" cwd True -- Avoid git complaining if it cannot determine the user's email -- address, or exploding if it doesn't know the user's name. - setEnv "GIT_AUTHOR_EMAIL" "test@example.com" True - setEnv "GIT_AUTHOR_NAME" "git-annex test" True - setEnv "GIT_COMMITTER_EMAIL" "test@example.com" True - setEnv "GIT_COMMITTER_NAME" "git-annex test" True + void $ Utility.Env.setEnv "GIT_AUTHOR_EMAIL" "test@example.com" True + void $ Utility.Env.setEnv "GIT_AUTHOR_NAME" "git-annex test" True + void $ Utility.Env.setEnv "GIT_COMMITTER_EMAIL" "test@example.com" True + void $ Utility.Env.setEnv "GIT_COMMITTER_NAME" "git-annex test" True changeToTmpDir :: FilePath -> IO () changeToTmpDir t = do -- Hack alert. Threading state to here was too much bother. - topdir <- getEnvDefault "TOPDIR" "" + topdir <- Utility.Env.getEnvDefault "TOPDIR" "" changeWorkingDirectory $ topdir ++ "/" ++ t tmpdir :: String diff --git a/Utility/Daemon.hs b/Utility/Daemon.hs index a01b078b8..b23a654cd 100755 --- a/Utility/Daemon.hs +++ b/Utility/Daemon.hs @@ -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. - diff --git a/Utility/Env.hs b/Utility/Env.hs index c6f051052..e1ab52415 100755 --- a/Utility/Env.hs +++ b/Utility/Env.hs @@ -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 diff --git a/Utility/FileMode.hs b/Utility/FileMode.hs index e9701d967..47247e2a1 100755 --- a/Utility/FileMode.hs +++ b/Utility/FileMode.hs @@ -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. -} diff --git a/Utility/Gpg.hs b/Utility/Gpg.hs index 0ed4b85da..d3460bdf7 100755 --- a/Utility/Gpg.hs +++ b/Utility/Gpg.hs @@ -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 diff --git a/Utility/InodeCache.hs b/Utility/InodeCache.hs index ec0f206d3..8037c61c8 100755 --- a/Utility/InodeCache.hs +++ b/Utility/InodeCache.hs @@ -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 diff --git a/Utility/LogFile.hs b/Utility/LogFile.hs index ccda429fc..339d6e8b9 100755 --- a/Utility/LogFile.hs +++ b/Utility/LogFile.hs @@ -12,7 +12,6 @@ module Utility.LogFile where import Common import System.Posix.Types -import System.PosixCompat.Files openLog :: FilePath -> IO Fd #ifndef __WINDOWS__ diff --git a/Utility/Lsof.hs b/Utility/Lsof.hs index 31da6781e..6d6b353f2 100644 --- a/Utility/Lsof.hs +++ b/Utility/Lsof.hs @@ -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. -} diff --git a/Utility/Url.hs b/Utility/Url.hs index 97862e370..b831b3f01 100755 --- a/Utility/Url.hs +++ b/Utility/Url.hs @@ -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 diff --git a/Utility/UserInfo.hs b/Utility/UserInfo.hs index 9781f584e..bc94ea8a1 100755 --- a/Utility/UserInfo.hs +++ b/Utility/UserInfo.hs @@ -14,7 +14,6 @@ module Utility.UserInfo ( ) where import Control.Applicative -import System.Posix.Types import System.PosixCompat import Utility.Env |