Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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 : streamly@composewell.com
-- Stability : experimental
-- Portability : GHC
--
-- Change file owner and group.

module Streamly.Coreutils.Chown
(
setOwnerAndGroup

-- * Options
, Chown
, followLink
) 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

followLink :: Switch -> Chown -> Chown
followLink opt cfg = cfg {deRef = opt}
Comment thread
rnjtranjan marked this conversation as resolved.
Outdated

setOwnerAndGroup :: (Chown -> Chown) -> FilePath -> Word32 -> Word32 -> IO ()
setOwnerAndGroup f path uid gid = do
Comment thread
rnjtranjan marked this conversation as resolved.
Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to take username and groupname too as arguments.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to use streamly-process to get the userId from username ($ id -u username)?

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