diff options
| author | Joey Hess <joeyh@joeyh.name> | 2015-01-06 19:07:40 -0400 |
|---|---|---|
| committer | Joey Hess <joeyh@joeyh.name> | 2015-01-06 19:07:40 -0400 |
| commit | 16a5f561f52f35f95a59976b5ee61d99945b0d55 (patch) | |
| tree | 791803645efedbc481cafcd907d2bcf73c03d1af /src/Utility/UserInfo.hs | |
| parent | f4a57ca27d2009b3069c6b33904d198e6aa73f79 (diff) | |
Merge Utiity modules from git-annex.
Except for a few that are using the other exception handling library,
that propellor has not switched to yet.
Diffstat (limited to 'src/Utility/UserInfo.hs')
| -rw-r--r-- | src/Utility/UserInfo.hs | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/Utility/UserInfo.hs b/src/Utility/UserInfo.hs index e2c248b1..c82f0407 100644 --- a/src/Utility/UserInfo.hs +++ b/src/Utility/UserInfo.hs @@ -1,6 +1,6 @@ {- user info - - - Copyright 2012 Joey Hess <id@joeyh.name> + - Copyright 2012 Joey Hess <joey@kitenet.net> - - License: BSD-2-clause -} @@ -13,8 +13,10 @@ module Utility.UserInfo ( myUserGecos, ) where -import Control.Applicative import System.PosixCompat +#ifndef mingw32_HOST_OS +import Control.Applicative +#endif import Utility.Env @@ -40,16 +42,20 @@ myUserName = myVal env userName env = ["USERNAME", "USER", "LOGNAME"] #endif -myUserGecos :: IO String -#ifdef __ANDROID__ -myUserGecos = return "" -- userGecos crashes on Android +myUserGecos :: IO (Maybe String) +-- userGecos crashes on Android and is not available on Windows. +#if defined(__ANDROID__) || defined(mingw32_HOST_OS) +myUserGecos = return Nothing #else -myUserGecos = myVal [] userGecos +myUserGecos = Just <$> myVal [] userGecos #endif myVal :: [String] -> (UserEntry -> String) -> IO String -myVal envvars extract = maybe (extract <$> getpwent) return =<< check envvars +myVal envvars extract = go envvars where - check [] = return Nothing - check (v:vs) = maybe (check vs) (return . Just) =<< getEnv v - getpwent = getUserEntryForID =<< getEffectiveUserID +#ifndef mingw32_HOST_OS + go [] = extract <$> (getUserEntryForID =<< getEffectiveUserID) +#else + go [] = error $ "environment not set: " ++ show envvars +#endif + go (v:vs) = maybe (go vs) return =<< getEnv v |
