Skip to content

Commit

Permalink
Migrate to System.Posix.User.ByteString
Browse files Browse the repository at this point in the history
  • Loading branch information
Rufflewind committed Jan 27, 2024
1 parent bb38707 commit 4cf7474
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions System/Directory/Internal/Posix.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ import System.Directory.Internal.Common
import System.Directory.Internal.Config (exeExtension)
import Data.Time (UTCTime)
import Data.Time.Clock.POSIX (POSIXTime)
import System.OsPath ((</>), encodeFS, isRelative, splitSearchPath)
import System.OsPath ((</>), isRelative, splitSearchPath)
import System.OsString.Internal.Types (OsString(OsString, getOsString))
import qualified Data.Time.Clock.POSIX as POSIXTime
import qualified System.OsPath.Internal as OsPath
import qualified System.Posix.Directory.PosixPath as Posix
import qualified System.Posix.Env.PosixString as Posix
import qualified System.Posix.Files.PosixString as Posix
import qualified System.Posix.IO.PosixString as Posix
import qualified System.Posix.PosixPath.FilePath as Posix
import qualified System.Posix.Types as Posix
import qualified System.Posix.User as Posix
import qualified System.Posix.User.ByteString as Posix

createDirectoryInternal :: OsPath -> IO ()
createDirectoryInternal (OsString path) = Posix.createDirectory path 0o777
Expand Down Expand Up @@ -335,13 +336,11 @@ getHomeDirectoryInternal :: IO OsPath
getHomeDirectoryInternal = do
e <- lookupEnvOs (os "HOME")
case e of
Just fp -> pure fp
-- TODO: os here is bad, but unix's System.Posix.User.UserEntry does not
-- have ByteString/OsString variants
Nothing ->
encodeFS =<<
Posix.homeDirectory <$>
(Posix.getEffectiveUserID >>= Posix.getUserEntryForID)
Just fp -> pure fp
Nothing ->
OsPath.fromBytes . Posix.homeDirectory =<<
Posix.getUserEntryForID =<<
Posix.getEffectiveUserID

getXdgDirectoryFallback :: IO OsPath -> XdgDirectory -> IO OsPath
getXdgDirectoryFallback getHomeDirectory xdgDir = do
Expand Down

0 comments on commit 4cf7474

Please sign in to comment.