{-# LANGUAGE NoImplicitPrelude #-}

-- | The module of this name differs as between Windows and non-Windows builds.

-- This is the non-Windows version.

module System.Permissions
  ( osIsMacOS
  , osIsWindows
  , setFileExecutable
  , setScriptPerms
  ) where

import           RIO
import qualified System.Posix.Files as Posix
import           System.Info ( os )

-- | True if using macOS.

osIsMacOS :: Bool
osIsMacOS :: Bool
osIsMacOS = String
os String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"darwin"

-- | False if not using Windows.

osIsWindows :: Bool
osIsWindows :: Bool
osIsWindows = Bool
False

setFileExecutable :: MonadIO m => FilePath -> m ()
setFileExecutable :: forall (m :: * -> *). MonadIO m => String -> m ()
setFileExecutable String
fp = IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ String -> FileMode -> IO ()
Posix.setFileMode String
fp FileMode
0o755

setScriptPerms :: MonadIO m => FilePath -> m ()
setScriptPerms :: forall (m :: * -> *). MonadIO m => String -> m ()
setScriptPerms String
fp =
  IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ String -> FileMode -> IO ()
Posix.setFileMode String
fp (FileMode -> IO ()) -> FileMode -> IO ()
forall a b. (a -> b) -> a -> b
$
    FileMode
Posix.ownerReadMode FileMode -> FileMode -> FileMode
`Posix.unionFileModes`
    FileMode
Posix.ownerWriteMode FileMode -> FileMode -> FileMode
`Posix.unionFileModes`
    FileMode
Posix.groupReadMode FileMode -> FileMode -> FileMode
`Posix.unionFileModes`
    FileMode
Posix.otherReadMode