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
2626import Control.Exception
2727 ( AsyncException
28+ , IOException
2829 , SomeException
2930 , bracket
3031 , catch
@@ -36,17 +37,14 @@ import Data.Bits (shiftL, (.|.))
3637import Data.Word (Word64 )
3738import Foreign.C.Types (CInt (.. ))
3839import 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 (.. ))
4242import System.Win32.Console (getConsoleMode )
4343
4444import System.Win32.File
45- ( ..
46- , getFileInformationByHandle
45+ ( getFileInformationByHandle
4746 , bhfiVolumeSerialNumber
48- , bhfiFileIndexHigh
49- , bhfiFileIndexLow
47+ , bhfiFileIndex
5048 , BY_HANDLE_FILE_INFORMATION (.. )
5149 )
5250import 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)
269268fileId 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
378375isPathOwnedByCurrentUser path =
379376 withFileOwnerSID path $ \ fileSid ->
380377 withEffectiveUserSID $ \ userSid ->
381- ( /= 0 ) <$> c_EqualSid fileSid userSid
378+ toBool <$> c_EqualSid fileSid userSid
382379
383380isOwnedByCurrentUser :: FileTest
384381isOwnedByCurrentUser = withPathM isPathOwnedByCurrentUser
@@ -434,10 +431,10 @@ isReadableNow = withPathM isPathReadableNow
434431--
435432isFileWritableNow :: FilePath -> FileStatus -> IO Bool
436433isFileWritableNow 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