-
Notifications
You must be signed in to change notification settings - Fork 0
Add Chown module #63
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
base: master
Are you sure you want to change the base?
Add Chown module #63
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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} | ||
|
|
||
| setOwnerAndGroup :: (Chown -> Chown) -> FilePath -> Word32 -> Word32 -> IO () | ||
| setOwnerAndGroup f path uid gid = do | ||
|
rnjtranjan marked this conversation as resolved.
Outdated
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should be able to take username and groupname too as arguments.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
Uh oh!
There was an error while loading. Please reload this page.