Skip to content

Commit a1f5d32

Browse files
Fix the Windows module for FileTest
1 parent f2b31e8 commit a1f5d32

1 file changed

Lines changed: 12 additions & 15 deletions

File tree

src/Streamly/Coreutils/FileTest/Windows.hsc

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{-# LANGUAGE ForeignFunctionInterface #-}
33
{-# LANGUAGE ScopedTypeVariables #-}
44

5-
module Streamly.Coreutils.Filetest.Windows
5+
module Streamly.Coreutils.FileTest.Windows
66
( Uid
77
, Gid
88
, sameFileAs
@@ -25,6 +25,7 @@ module Streamly.Coreutils.Filetest.Windows
2525

2626
import Control.Exception
2727
( AsyncException
28+
, IOException
2829
, SomeException
2930
, bracket
3031
, catch
@@ -36,17 +37,14 @@ import Data.Bits (shiftL, (.|.))
3637
import Data.Word (Word64)
3738
import Foreign.C.Types (CInt(..))
3839
import Foreign.Ptr (nullPtr)
39-
import System.IO.Error (IOException)
40-
import System.PosixCompat.Files (FileStatus)
41-
import System.Posix.Types (Fd(..), ownerWriteMode)
40+
import System.PosixCompat.Files (FileStatus, ownerWriteMode)
41+
import System.Posix.Types (Fd(..))
4242
import System.Win32.Console (getConsoleMode)
4343

4444
import System.Win32.File
45-
( ..
46-
, getFileInformationByHandle
45+
( getFileInformationByHandle
4746
, bhfiVolumeSerialNumber
48-
, bhfiFileIndexHigh
49-
, bhfiFileIndexLow
47+
, bhfiFileIndex
5048
, BY_HANDLE_FILE_INFORMATION(..)
5149
)
5250
import System.Win32.File (fILE_TYPE_CHAR, getFileType)
@@ -80,6 +78,7 @@ import System.Win32.Types
8078
, LPDWORD
8179
, failIfFalse_
8280
, iNVALID_HANDLE_VALUE
81+
, toBool
8382
, withFilePath
8483
)
8584

@@ -269,10 +268,8 @@ fileId :: FilePath -> IO (DWORD, Word64)
269268
fileId path =
270269
withFileHandle path $ \h -> do
271270
info <- getFileInformationByHandle h
272-
let vol = bhfiVolumeSerialNumber info
273-
high = fromIntegral (bhfiFileIndexHigh info) :: Word64
274-
low = fromIntegral (bhfiFileIndexLow info) :: Word64
275-
idx = (high `shiftL` 32) .|. low
271+
let vol = bhfiVolumeSerialNumber info
272+
idx = fromIntegral (bhfiFileIndex info) :: Word64
276273
pure (vol, idx)
277274

278275
-- | True if both paths refer to the same underlying file or directory,
@@ -378,7 +375,7 @@ isPathOwnedByCurrentUser :: FilePath -> IO Bool
378375
isPathOwnedByCurrentUser path =
379376
withFileOwnerSID path $ \fileSid ->
380377
withEffectiveUserSID $ \userSid ->
381-
(/= 0) <$> c_EqualSid fileSid userSid
378+
toBool <$> c_EqualSid fileSid userSid
382379

383380
isOwnedByCurrentUser :: FileTest
384381
isOwnedByCurrentUser = withPathM isPathOwnedByCurrentUser
@@ -434,10 +431,10 @@ isReadableNow = withPathM isPathReadableNow
434431
--
435432
isFileWritableNow :: FilePath -> FileStatus -> IO Bool
436433
isFileWritableNow path st = do
437-
isDirectory <- testGeneral path st isDir
434+
isDirectory <- testWithStatus path st isDir
438435
-- Under unix-compat on Windows, ownerWriteMode corresponds to the
439436
-- FILE_ATTRIBUTE_READONLY flag being unset.
440-
writable <- testGeneral path st (hasMode ownerWriteMode)
437+
writable <- testWithStatus path st (hasMode ownerWriteMode)
441438
-- The READONLY attribute on directories does not prevent creating
442439
-- files inside the directory.
443440
if not writable && not isDirectory

0 commit comments

Comments
 (0)