Skip to content

Commit a170937

Browse files
TerrorJackBodigrim
authored andcommitted
Add missing autoconf checks for chown/fchdir/fchmod
These are not present in wasm32-wasi, and is needed for fixing GHC #22589.
1 parent 3fe57f3 commit a170937

File tree

6 files changed

+74
-3
lines changed

6 files changed

+74
-3
lines changed

System/Posix/Directory/Common.hsc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ import System.Posix.Types
3636
import Foreign hiding (void)
3737
import Foreign.C
3838

39+
#if !defined(HAVE_FCHDIR)
40+
import System.IO.Error ( ioeSetLocation )
41+
import GHC.IO.Exception ( unsupportedOperation )
42+
#endif
43+
3944
newtype DirStream = DirStream (Ptr CDir)
4045

4146
data {-# CTYPE "DIR" #-} CDir
@@ -111,9 +116,19 @@ foreign import ccall unsafe "telldir"
111116
c_telldir :: Ptr CDir -> IO CLong
112117
#endif
113118

119+
#if defined(HAVE_FCHDIR)
120+
114121
changeWorkingDirectoryFd :: Fd -> IO ()
115122
changeWorkingDirectoryFd (Fd fd) =
116123
throwErrnoIfMinus1Retry_ "changeWorkingDirectoryFd" (c_fchdir fd)
117124

118125
foreign import ccall unsafe "fchdir"
119126
c_fchdir :: CInt -> IO CInt
127+
128+
#else
129+
130+
{-# WARNING changeWorkingDirectoryFd "operation will throw 'IOError' \"unsupported operation\" (CPP guard: @#if HAVE_FCHDIR@)" #-}
131+
changeWorkingDirectoryFd :: Fd -> IO ()
132+
changeWorkingDirectoryFd _ = ioError (ioeSetLocation unsupportedOperation "changeWorkingDirectoryFd")
133+
134+
#endif // HAVE_FCHDIR

System/Posix/Files.hsc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ import Data.Monoid ((<>))
108108

109109
import Data.Time.Clock.POSIX (POSIXTime)
110110

111-
#if !defined(HAVE_MKNOD)
111+
#if !defined(HAVE_MKNOD) || !defined(HAVE_CHOWN)
112112
import System.IO.Error ( ioeSetLocation )
113113
import GHC.IO.Exception ( unsupportedOperation )
114114
#endif
@@ -323,6 +323,8 @@ foreign import ccall unsafe "rename"
323323
-- -----------------------------------------------------------------------------
324324
-- chown()
325325

326+
#if defined(HAVE_CHOWN)
327+
326328
-- | @setOwnerAndGroup path uid gid@ changes the owner and group of @path@ to
327329
-- @uid@ and @gid@, respectively.
328330
--
@@ -337,6 +339,14 @@ setOwnerAndGroup name uid gid = do
337339
foreign import ccall unsafe "chown"
338340
c_chown :: CString -> CUid -> CGid -> IO CInt
339341

342+
#else
343+
344+
{-# WARNING setOwnerAndGroup "operation will throw 'IOError' \"unsupported operation\" (CPP guard: @#if HAVE_CHOWN@)" #-}
345+
setOwnerAndGroup :: FilePath -> UserID -> GroupID -> IO ()
346+
setOwnerAndGroup _ _ _ = ioError (ioeSetLocation unsupportedOperation "setOwnerAndGroup")
347+
348+
#endif // HAVE_CHOWN
349+
340350
#if HAVE_LCHOWN
341351
-- | Acts as 'setOwnerAndGroup' but does not follow symlinks (and thus
342352
-- changes permissions on the link itself).

System/Posix/Files/ByteString.hsc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ import System.Posix.ByteString.FilePath
109109

110110
import Data.Time.Clock.POSIX (POSIXTime)
111111

112-
#if !defined(HAVE_MKNOD)
112+
#if !defined(HAVE_MKNOD) || !defined(HAVE_CHOWN)
113113
import System.IO.Error ( ioeSetLocation )
114114
import GHC.IO.Exception ( unsupportedOperation )
115115
#endif
@@ -319,6 +319,8 @@ foreign import ccall unsafe "rename"
319319
-- -----------------------------------------------------------------------------
320320
-- chown()
321321

322+
#if defined(HAVE_CHOWN)
323+
322324
-- | @setOwnerAndGroup path uid gid@ changes the owner and group of @path@ to
323325
-- @uid@ and @gid@, respectively.
324326
--
@@ -333,6 +335,14 @@ setOwnerAndGroup name uid gid = do
333335
foreign import ccall unsafe "chown"
334336
c_chown :: CString -> CUid -> CGid -> IO CInt
335337

338+
#else
339+
340+
{-# WARNING setOwnerAndGroup "operation will throw 'IOError' \"unsupported operation\" (CPP guard: @#if HAVE_CHOWN@)" #-}
341+
setOwnerAndGroup :: RawFilePath -> UserID -> GroupID -> IO ()
342+
setOwnerAndGroup _ _ _ = ioError (ioeSetLocation unsupportedOperation "setOwnerAndGroup")
343+
344+
#endif // HAVE_CHOWN
345+
336346
#if HAVE_LCHOWN
337347
-- | Acts as 'setOwnerAndGroup' but does not follow symlinks (and thus
338348
-- changes permissions on the link itself).

System/Posix/Files/Common.hsc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ import Foreign.Marshal (withArray)
9898
import Foreign.Ptr
9999
import Foreign.Storable
100100

101+
#if !defined(HAVE_FCHMOD) || !defined(HAVE_CHOWN)
102+
import System.IO.Error ( ioeSetLocation )
103+
import GHC.IO.Exception ( unsupportedOperation )
104+
#endif
105+
101106
-- -----------------------------------------------------------------------------
102107
-- POSIX file modes
103108

@@ -208,6 +213,8 @@ symbolicLinkMode = (#const S_IFLNK)
208213
socketMode :: FileMode
209214
socketMode = (#const S_IFSOCK)
210215

216+
#if defined(HAVE_FCHMOD)
217+
211218
-- | @setFdMode fd mode@ acts like 'setFileMode' but uses a file descriptor
212219
-- @fd@ instead of a 'FilePath'.
213220
--
@@ -219,6 +226,14 @@ setFdMode (Fd fd) m =
219226
foreign import ccall unsafe "fchmod"
220227
c_fchmod :: CInt -> CMode -> IO CInt
221228

229+
#else
230+
231+
{-# WARNING setFdMode "operation will throw 'IOError' \"unsupported operation\" (CPP guard: @#if HAVE_FCHMOD@)" #-}
232+
setFdMode :: Fd -> FileMode -> IO ()
233+
setFdMode _ _ = ioError (ioeSetLocation unsupportedOperation "setFdMode")
234+
235+
#endif // HAVE_FCHMOD
236+
222237
-- | @setFileCreationMask mode@ sets the file mode creation mask to @mode@.
223238
-- Modes set by this operation are subtracted from files and directories upon
224239
-- creation. The previous file creation mask is returned.
@@ -540,6 +555,8 @@ touchFd =
540555
-- -----------------------------------------------------------------------------
541556
-- fchown()
542557

558+
#if defined(HAVE_CHOWN)
559+
543560
-- | Acts as 'setOwnerAndGroup' but uses a file descriptor instead of a
544561
-- 'FilePath'.
545562
--
@@ -551,6 +568,14 @@ setFdOwnerAndGroup (Fd fd) uid gid =
551568
foreign import ccall unsafe "fchown"
552569
c_fchown :: CInt -> CUid -> CGid -> IO CInt
553570

571+
#else
572+
573+
{-# WARNING setFdOwnerAndGroup "operation will throw 'IOError' \"unsupported operation\" (CPP guard: @#if HAVE_CHOWN@)" #-}
574+
setFdOwnerAndGroup :: Fd -> UserID -> GroupID -> IO ()
575+
setFdOwnerAndGroup _ _ _ = ioError (ioeSetLocation unsupportedOperation "setFdOwnerAndGroup")
576+
577+
#endif // HAVE_CHOWN
578+
554579
-- -----------------------------------------------------------------------------
555580
-- ftruncate()
556581

System/Posix/Files/PosixString.hsc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ import System.Posix.PosixPath.FilePath
107107

108108
import Data.Time.Clock.POSIX (POSIXTime)
109109

110-
#if !defined(HAVE_MKNOD)
110+
#if !defined(HAVE_MKNOD) || !defined(HAVE_CHOWN)
111111
import System.IO.Error ( ioeSetLocation )
112112
import GHC.IO.Exception ( unsupportedOperation )
113113
#endif
@@ -316,6 +316,8 @@ foreign import ccall unsafe "rename"
316316
-- -----------------------------------------------------------------------------
317317
-- chown()
318318

319+
#if defined(HAVE_CHOWN)
320+
319321
-- | @setOwnerAndGroup path uid gid@ changes the owner and group of @path@ to
320322
-- @uid@ and @gid@, respectively.
321323
--
@@ -330,6 +332,14 @@ setOwnerAndGroup name uid gid = do
330332
foreign import ccall unsafe "chown"
331333
c_chown :: CString -> CUid -> CGid -> IO CInt
332334

335+
#else
336+
337+
{-# WARNING setOwnerAndGroup "operation will throw 'IOError' \"unsupported operation\" (CPP guard: @#if HAVE_CHOWN@)" #-}
338+
setOwnerAndGroup :: PosixPath -> UserID -> GroupID -> IO ()
339+
setOwnerAndGroup _ _ _ = ioError (ioeSetLocation unsupportedOperation "setOwnerAndGroup")
340+
341+
#endif // HAVE_CHOWN
342+
333343
#if HAVE_LCHOWN
334344
-- | Acts as 'setOwnerAndGroup' but does not follow symlinks (and thus
335345
-- changes permissions on the link itself).

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ AC_CHECK_FUNCS([mknod])
4242
AC_CHECK_FUNCS([mkstemp])
4343
AC_CHECK_FUNCS([pipe])
4444
AC_CHECK_FUNCS([times])
45+
AC_CHECK_FUNCS([chown fchdir fchmod])
4546

4647
AC_CHECK_TYPE([struct rlimit],[AC_DEFINE([HAVE_STRUCT_RLIMIT],[1],[HAVE_STRUCT_RLIMIT])],[],[#include <sys/resource.h>])
4748

0 commit comments

Comments
 (0)