@@ -6,20 +6,15 @@ module Distribution.Client.Compat.FilePerms (
6
6
setFileHidden ,
7
7
) where
8
8
9
- import Prelude (FilePath , IO , return , ($) )
10
- import Data.Bits ((.|.) )
9
+ import Prelude (FilePath , IO , return )
11
10
12
11
#ifndef mingw32_HOST_OS
12
+ import Prelude ((<$>) )
13
+ import Data.Bits ((.|.) )
13
14
import System.Posix.Types
14
15
( FileMode )
15
- import System.Posix.Internals
16
- ( withFilePath
17
- , c_chmod
18
- , c_stat , sizeof_stat , st_mode )
19
- import Foreign.C
20
- ( throwErrnoPathIfMinus1_ )
21
- import Foreign.Marshal.Alloc
22
- ( allocaBytes )
16
+ import System.Posix.Files
17
+ ( getFileStatus , fileMode , setFileMode )
23
18
#else
24
19
import System.Win32.File (setFileAttributes , fILE_ATTRIBUTE_HIDDEN )
25
20
#endif /* mingw32_HOST_OS */
@@ -33,13 +28,10 @@ setFileExecutable path = addFileMode path 0o755 -- file perms -rwxr-xr-x
33
28
setFileHidden _ = return ()
34
29
35
30
addFileMode :: FilePath -> FileMode -> IO ()
36
- addFileMode name m =
37
- withFilePath name $ \ s -> allocaBytes sizeof_stat $ \ ptr_stat -> do
38
- throwErrnoPathIfMinus1_ " addFileMode: stat" name $
39
- c_stat s ptr_stat
40
- o <- st_mode ptr_stat
41
- throwErrnoPathIfMinus1_ " addFileMode: chmod" name $
42
- c_chmod s (m .|. o)
31
+ addFileMode name m = do
32
+ o <- fileMode <$> getFileStatus name
33
+ setFileMode name (m .|. o)
34
+
43
35
#else
44
36
setFileOrdinary _ = return ()
45
37
setFileExecutable _ = return ()
0 commit comments