RawFilePath version of getCurrentDirectory
This commit was sponsored by Jochen Bartl on Patreon
This commit is contained in:
parent
08cbaee1f8
commit
6c29817748
5 changed files with 26 additions and 8 deletions
|
@ -1,4 +1,5 @@
|
|||
{- Portability shim around System.Posix.Files.ByteString
|
||||
{- Portability shim around System.Posix.Files.ByteString and
|
||||
- System.Posix.Directory.ByteString
|
||||
-
|
||||
- On unix, this makes syscalls using RawFilesPaths as efficiently as
|
||||
- possible.
|
||||
|
@ -7,7 +8,7 @@
|
|||
- decoded. So this library will work, but less efficiently than using
|
||||
- FilePath would.
|
||||
-
|
||||
- Copyright 2019 Joey Hess <id@joeyh.name>
|
||||
- Copyright 2019-2020 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- License: BSD-2-clause
|
||||
-}
|
||||
|
@ -17,20 +18,26 @@
|
|||
module Utility.RawFilePath (
|
||||
RawFilePath,
|
||||
readSymbolicLink,
|
||||
createSymbolicLink,
|
||||
getFileStatus,
|
||||
getSymbolicLinkStatus,
|
||||
doesPathExist,
|
||||
getCurrentDirectory,
|
||||
) where
|
||||
|
||||
#ifndef mingw32_HOST_OS
|
||||
import Utility.FileSystemEncoding (RawFilePath)
|
||||
import System.Posix.Files.ByteString
|
||||
import System.Posix.Directory.ByteString
|
||||
|
||||
-- | Checks if a file or directoy exists. Note that a dangling symlink
|
||||
-- will be false.
|
||||
doesPathExist :: RawFilePath -> IO Bool
|
||||
doesPathExist = fileExist
|
||||
|
||||
getCurrentDirectory :: IO RawFilePath
|
||||
getCurrentDirectory = getWorkingDirectory
|
||||
|
||||
#else
|
||||
import qualified Data.ByteString as B
|
||||
import System.PosixCompat (FileStatus)
|
||||
|
@ -41,6 +48,11 @@ import Utility.FileSystemEncoding
|
|||
readSymbolicLink :: RawFilePath -> IO RawFilePath
|
||||
readSymbolicLink f = toRawFilePath <$> P.readSymbolicLink (fromRawFilePath f)
|
||||
|
||||
createSymbolicLink :: RawFilePath -> RawFilePath -> IO ()
|
||||
createSymbolicLink a b = P.createSymbolicLink
|
||||
(fromRawFilePath a)
|
||||
(fromRawFilePath b)
|
||||
|
||||
getFileStatus :: RawFilePath -> IO FileStatus
|
||||
getFileStatus = P.getFileStatus . fromRawFilePath
|
||||
|
||||
|
@ -49,4 +61,7 @@ getSymbolicLinkStatus = P.getSymbolicLinkStatus . fromRawFilePath
|
|||
|
||||
doesPathExist :: RawFilePath -> IO Bool
|
||||
doesPathExist = D.doesPathExist . fromRawFilePath
|
||||
|
||||
getCurrentDirectory :: IO RawFilePath
|
||||
getCurrentDirectory = toRawFilePath <$> D.getCurrentDirectory
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue