Skip to content

Commit

Permalink
Merge pull request #7686 from DanielG/replace-posix-internals
Browse files Browse the repository at this point in the history
addFileMode: Replace use of Posix.Internals module with public API
  • Loading branch information
mergify[bot] authored Feb 2, 2022
2 parents ba7b324 + 2837b00 commit 9694036
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 30 deletions.
18 changes: 5 additions & 13 deletions Cabal/src/Distribution/Compat/CopyFile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,8 @@ import Foreign

import System.Posix.Types
( FileMode )
import System.Posix.Internals
( withFilePath
, c_chmod
, c_stat, sizeof_stat, st_mode )
import Foreign.C
( throwErrnoPathIfMinus1_ )
import System.Posix.Files
( getFileStatus, fileMode, setFileMode )

#else /* else mingw32_HOST_OS */

Expand Down Expand Up @@ -81,13 +77,9 @@ setFileOrdinary path = addFileMode path 0o644 -- file perms -rw-r--r--
setFileExecutable path = addFileMode path 0o755 -- file perms -rwxr-xr-x

addFileMode :: FilePath -> FileMode -> IO ()
addFileMode name m =
withFilePath name $ \s -> allocaBytes sizeof_stat $ \ptr_stat -> do
throwErrnoPathIfMinus1_ "addFileMode: stat" name $
c_stat s ptr_stat
o <- st_mode ptr_stat
throwErrnoPathIfMinus1_ "addFileMode: chmod" name $
c_chmod s (m .|. o)
addFileMode name m = do
o <- fileMode <$> getFileStatus name
setFileMode name (m .|. o)
#else
setFileOrdinary _ = return ()
setFileExecutable _ = return ()
Expand Down
26 changes: 9 additions & 17 deletions cabal-install/src/Distribution/Client/Compat/FilePerms.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,15 @@ module Distribution.Client.Compat.FilePerms (
setFileHidden,
) where

import Prelude (FilePath, IO, return, ($))
import Data.Bits ((.|.))
import Prelude (FilePath, IO, return)

#ifndef mingw32_HOST_OS
import Prelude ((<$>))
import Data.Bits ((.|.))
import System.Posix.Types
( FileMode )
import System.Posix.Internals
( withFilePath
, c_chmod
, c_stat, sizeof_stat, st_mode )
import Foreign.C
( throwErrnoPathIfMinus1_ )
import Foreign.Marshal.Alloc
( allocaBytes )
import System.Posix.Files
( getFileStatus, fileMode, setFileMode )
#else
import System.Win32.File (setFileAttributes, fILE_ATTRIBUTE_HIDDEN)
#endif /* mingw32_HOST_OS */
Expand All @@ -33,13 +28,10 @@ setFileExecutable path = addFileMode path 0o755 -- file perms -rwxr-xr-x
setFileHidden _ = return ()

addFileMode :: FilePath -> FileMode -> IO ()
addFileMode name m =
withFilePath name $ \s -> allocaBytes sizeof_stat $ \ptr_stat -> do
throwErrnoPathIfMinus1_ "addFileMode: stat" name $
c_stat s ptr_stat
o <- st_mode ptr_stat
throwErrnoPathIfMinus1_ "addFileMode: chmod" name $
c_chmod s (m .|. o)
addFileMode name m = do
o <- fileMode <$> getFileStatus name
setFileMode name (m .|. o)

#else
setFileOrdinary _ = return ()
setFileExecutable _ = return ()
Expand Down

0 comments on commit 9694036

Please sign in to comment.