Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Chown module #63

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/Streamly/Coreutils/Chown.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
-- |
-- Module : Streamly.Coreutils.Ls
-- Copyright : (c) 2022 Composewell Technologies
-- License : BSD-3-Clause
-- Maintainer : [email protected]
-- Stability : experimental
-- Portability : GHC
--
-- Change file owner and group.

module Streamly.Coreutils.Chown
(
chown

-- * Options
, Chown
, followLinks
) where

import qualified System.Posix.Files as Posix
import System.Posix.Types ( CUid (CUid), CGid (CGid) )
import GHC.Word (Word32)
import Streamly.Coreutils.Common (Switch(..))

newtype Chown = Chown{deRef :: Switch}

defaultConfig :: Chown
defaultConfig = Chown Off

followLinks :: Switch -> Chown -> Chown
followLinks opt cfg = cfg {deRef = opt}

chown :: (Chown -> Chown) -> FilePath -> Word32 -> Word32 -> IO ()
chown f path uid gid = do
let opt = f defaultConfig
case deRef opt of
Off -> Posix.setSymbolicLinkOwnerAndGroup path (CUid uid) (CGid gid)
On -> Posix.setOwnerAndGroup path (CUid uid) (CGid gid)
1 change: 1 addition & 0 deletions streamly-coreutils.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ library
hs-source-dirs: src
exposed-modules:
Streamly.Coreutils
, Streamly.Coreutils.Chown
, Streamly.Coreutils.Common
, Streamly.Coreutils.Cp
, Streamly.Coreutils.FileTest
Expand Down