Skip to content

Commit 6c0885e

Browse files
Fix warnings and enable Werror on Windows
1 parent 6c769d1 commit 6c0885e

6 files changed

Lines changed: 28 additions & 27 deletions

File tree

.github/workflows/haskell.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ jobs:
240240
pack_options: >-
241241
GHC_PATH=/c/ghcup/bin/ghc
242242
CABAL_PATH=/c/ghcup/bin/cabal
243+
CABAL_PROJECT=cabal.project.d/master-Werror
243244
DISABLE_SDIST_BUILD=y
244245
DISABLE_SDIST_PROJECT_CHECK=y
245246
DISABLE_SDIST_GIT_CHECK=y

src/Streamly/Coreutils/Common.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
{-# LANGUAGE CPP #-}
12
{-# LANGUAGE PatternSynonyms #-}
23

34
-- | This module is deprecated. Use 'Data.Bool' and 'Bool' instead.
45
module Streamly.Coreutils.Common
56
{-# DEPRECATED "This module is deprecated. Please use 'Bool' from 'Data.Bool' instead." #-}
67
( Switch
8+
#if __GLASGOW_HASKELL__ >= 914
9+
, data On
10+
, data Off
11+
#else
712
, pattern On
813
, pattern Off
14+
#endif
915
) where
1016

1117
-- Define Switch as a Bool alias

src/Streamly/Coreutils/FileTest.hs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@
6868
-- > test path (size (> 4096))
6969
-- > test path (modifyTimeComparedTo (>) "reference.txt")
7070

71-
-- $setup
72-
-- >>> import Prelude hiding (or, and)
73-
-- >>> import Data.Time.Clock (NominalDiffTime)
74-
-- >>> import Data.Time.Clock.POSIX (POSIXTime)
75-
7671
module Streamly.Coreutils.FileTest
7772
(
7873
-- * File Test Predicate Type
@@ -251,12 +246,16 @@ import qualified System.PosixCompat.Files as Files
251246
import qualified Streamly.Coreutils.FileTest.Posix as FileTest
252247
#else
253248
import qualified Streamly.Coreutils.FileTest.Windows as FileTest
254-
import System.Win32.Types
255249
#endif
256250

257251
import Streamly.Coreutils.FileTest.Common
258252
import Prelude hiding (and, or)
259253

254+
-- $setup
255+
-- >>> import Prelude hiding (or, and)
256+
-- >>> import Data.Time.Clock (NominalDiffTime)
257+
-- >>> import Data.Time.Clock.POSIX (POSIXTime)
258+
260259
-------------------------------------------------------------------------------
261260
-- User and group ownerships
262261
-------------------------------------------------------------------------------
@@ -334,7 +333,7 @@ isOwnedByCurrentGroup = FileTest.isOwnedByCurrentGroup
334333
-------------------------------------------------------------------------------
335334

336335
hasPermissions :: (FileMode, FileMode, FileMode) -> FileTest
337-
hasPermissions (user, group, other) = withStateM $ \fp st -> do
336+
hasPermissions (user, _group, _other) = withStateM $ \fp st -> do
338337
isOwner <- testWithStatus fp st isOwnedByCurrentUser
339338
let checkMode = testWithStatus fp st . hasMode
340339
if isOwner
@@ -344,8 +343,8 @@ hasPermissions (user, group, other) = withStateM $ \fp st -> do
344343
-- XXX need to check access via other group memberships as well
345344
isGroup <- testWithStatus fp st FileTest.isOwnedByCurrentGroup
346345
if isGroup
347-
then checkMode group
348-
else checkMode other
346+
then checkMode _group
347+
else checkMode _other
349348
#else
350349
else return False
351350
#endif

src/Streamly/Coreutils/FileTest/Windows.hsc

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
{-# LANGUAGE ScopedTypeVariables #-}
44

55
module Streamly.Coreutils.FileTest.Windows
6-
( Uid
7-
, Gid
8-
, sameFileAs
6+
( sameFileAs
97
, isTerminalFd
108
{-
9+
, Uid
10+
, Gid
1111
, isOwnedByUserId
1212
, isOwnedByGroupId
1313
-}
@@ -35,10 +35,7 @@ import Control.Exception
3535
, throwIO
3636
)
3737

38-
import Data.Bits (shiftL, (.|.), (.&.))
39-
import Data.Word (Word64)
4038
import Foreign.C.Types (CInt(..))
41-
import Foreign.Ptr (nullPtr)
4239
import System.PosixCompat.Files (FileStatus, isSymbolicLink, ownerWriteMode)
4340
import System.Posix.Types (Fd(..))
4441
import System.Win32.Console (getConsoleMode)
@@ -68,7 +65,6 @@ import System.Win32.File
6865
)
6966
import System.Win32.Security
7067
( PSID
71-
, SID
7268
, dACL_SECURITY_INFORMATION
7369
, oWNER_SECURITY_INFORMATION
7470
)
@@ -91,12 +87,12 @@ import Streamly.Coreutils.FileTest.Common
9187
-- Types
9288
-------------------------------------------------------------------------------
9389

90+
{-
9491
-- | Wraps a Windows SID pointer representing a user identity.
9592
newtype Uid = Uid PSID
9693
-- | Wraps a Windows SID pointer representing a group identity.
9794
newtype Gid = Gid PSID
9895
99-
{-
10096
isOwnedByUserId :: Uid -> FileTest
10197
isOwnedByUserId (Uid uid) = withPathM $ \fp -> undefined
10298
@@ -269,7 +265,7 @@ fileId path =
269265
withFileHandle path $ \h -> do
270266
info <- getFileInformationByHandle h
271267
let vol = bhfiVolumeSerialNumber info
272-
idx = fromIntegral (bhfiFileIndex info) :: Word64
268+
idx = bhfiFileIndex info
273269
pure (vol, idx)
274270

275271
-- | True if both paths refer to the same underlying file or directory,
@@ -306,7 +302,7 @@ isConsoleHandle h =
306302
isTerminalFd :: Fd -> FileTest
307303
isTerminalFd (Fd fd) =
308304
withPathM $ \_ -> do
309-
h <- c_get_osfhandle (fromIntegral fd)
305+
h <- c_get_osfhandle fd
310306
if h == iNVALID_HANDLE_VALUE
311307
then pure False
312308
else do
@@ -576,9 +572,6 @@ isExecutable = withPathM pathIsExecutable
576572
fILE_ATTRIBUTE_DIRECTORY :: DWORD
577573
fILE_ATTRIBUTE_DIRECTORY = 0x10
578574

579-
fILE_ATTRIBUTE_REPARSE_POINT :: DWORD
580-
fILE_ATTRIBUTE_REPARSE_POINT = 0x400
581-
582575
-- | True iff the path is a reparse point (symlink or junction) that the OS
583576
-- also marks as a directory object.
584577
isPathDirSymLink :: FilePath -> FileStatus -> IO Bool

src/Streamly/Coreutils/Rm.hs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,16 @@ where
8787
import Control.Monad (forM_, when)
8888
import Streamly.Coreutils.FileTest
8989
(doesItExist, test, testl, isDir, isWritableByMode)
90-
#if defined(mingw32_HOST_OS)
90+
#if defined(CABAL_OS_WINDOWS)
9191
import Streamly.Coreutils.FileTest.Windows (isDirSymLink)
9292
#endif
9393
import System.Directory
9494
( getPermissions
9595
, removeFile
9696
, removeDirectory
97+
#if !defined(CABAL_OS_WINDOWS)
9798
, removeDirectoryRecursive
99+
#endif
98100
, removePathForcibly
99101
, setPermissions
100102
, listDirectory
@@ -175,7 +177,7 @@ rmdir options path =
175177
case rmForce options of
176178
FullForce -> removePathForcibly path
177179
Force ->
178-
#if defined(mingw32_HOST_OS)
180+
#if defined(CABAL_OS_WINDOWS)
179181
-- On Unix removePathForcibly makes directories writable to
180182
-- facilitate removal of files in them, but on Windows
181183
-- directory attributes do not affect file deletion, it
@@ -212,7 +214,7 @@ rmfile options path =
212214
FullForce -> removePathForcibly path
213215
NoForce -> withWriteProtectionCheck path removeFile "regular file"
214216
Force -> do
215-
#if defined(mingw32_HOST_OS)
217+
#if defined(CABAL_OS_WINDOWS)
216218
-- On Windows, file deletability is tied to the file's own
217219
-- read-only attribute (unlike POSIX where only parent-dir write
218220
-- matters). Force must clear it before unlinking.
@@ -227,7 +229,7 @@ performRm options path = do
227229
if dir
228230
then rmdir options path
229231
else do
230-
#if defined(mingw32_HOST_OS)
232+
#if defined(CABAL_OS_WINDOWS)
231233
dirSymLink <- testl path isDirSymLink
232234
if dirSymLink
233235
then do

test/Streamly/Test/Coreutils/Rm.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ mode___ = nullFileMode
143143
-- the action is run but its result is ignored.
144144
parentDirPermCheck :: IO () -> IO ()
145145
parentDirPermCheck =
146-
#if defined(mingw32_HOST_OS)
146+
#if defined(CABAL_OS_WINDOWS)
147147
-- On Windows, we do not check parent dir permission as they are controlled
148148
-- by ACLs, not permission modes.
149149
id

0 commit comments

Comments
 (0)