2019-01-14 19:19:20 +00:00
|
|
|
{- Portability shim around System.Posix.Files.ByteString
|
2019-12-06 18:17:48 +00:00
|
|
|
-
|
|
|
|
- On unix, this makes syscalls using RawFilesPaths as efficiently as
|
|
|
|
- possible.
|
|
|
|
-
|
|
|
|
- On Windows, filenames are in unicode, so RawFilePaths have to be
|
|
|
|
- decoded. So this library will work, but less efficiently than using
|
|
|
|
- FilePath would.
|
2019-01-14 19:19:20 +00:00
|
|
|
-
|
|
|
|
- Copyright 2019 Joey Hess <id@joeyh.name>
|
|
|
|
-
|
|
|
|
- License: BSD-2-clause
|
|
|
|
-}
|
|
|
|
|
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
|
|
|
|
module Utility.RawFilePath (
|
|
|
|
RawFilePath,
|
|
|
|
readSymbolicLink,
|
2019-12-06 18:44:42 +00:00
|
|
|
getFileStatus,
|
2019-12-06 19:37:12 +00:00
|
|
|
getSymbolicLinkStatus,
|
2019-12-11 18:12:22 +00:00
|
|
|
doesPathExist,
|
2019-01-14 19:19:20 +00:00
|
|
|
) where
|
|
|
|
|
|
|
|
#ifndef mingw32_HOST_OS
|
2019-12-06 18:44:42 +00:00
|
|
|
import Utility.FileSystemEncoding (RawFilePath)
|
2019-01-14 19:19:20 +00:00
|
|
|
import System.Posix.Files.ByteString
|
2019-12-11 18:12:22 +00:00
|
|
|
|
|
|
|
doesPathExist :: RawFilePath -> IO Bool
|
|
|
|
doesPathExist = fileExist
|
|
|
|
|
2019-01-14 19:19:20 +00:00
|
|
|
#else
|
|
|
|
import qualified Data.ByteString as B
|
2020-01-01 16:24:31 +00:00
|
|
|
import System.PosixCompat (FileStatus)
|
2019-12-06 18:17:48 +00:00
|
|
|
import qualified System.PosixCompat as P
|
2019-12-11 18:12:22 +00:00
|
|
|
import qualified System.Directory as D
|
2019-12-06 18:17:48 +00:00
|
|
|
import Utility.FileSystemEncoding
|
2019-01-14 19:19:20 +00:00
|
|
|
|
|
|
|
readSymbolicLink :: RawFilePath -> IO RawFilePath
|
2019-12-06 18:17:48 +00:00
|
|
|
readSymbolicLink f = toRawFilePath <$> P.readSymbolicLink (fromRawFilePath f)
|
2019-12-06 18:44:42 +00:00
|
|
|
|
|
|
|
getFileStatus :: RawFilePath -> IO FileStatus
|
|
|
|
getFileStatus = P.getFileStatus . fromRawFilePath
|
2019-12-06 19:37:12 +00:00
|
|
|
|
|
|
|
getSymbolicLinkStatus :: RawFilePath -> IO FileStatus
|
|
|
|
getSymbolicLinkStatus = P.getSymbolicLinkStatus . fromRawFilePath
|
2019-12-11 18:12:22 +00:00
|
|
|
|
|
|
|
doesPathExist :: RawFilePath -> IO Bool
|
|
|
|
doesPathExist = D.doesPathExist . fromRawFilePath
|
2019-01-14 19:19:20 +00:00
|
|
|
#endif
|