{-# LANGUAGE CPP #-}
module UnliftIO.Directory (
createDirectory
, createDirectoryIfMissing
, removeDirectory
, removeDirectoryRecursive
#if MIN_VERSION_directory(1,2,7)
, removePathForcibly
#endif
, renameDirectory
#if MIN_VERSION_directory(1,2,5)
, listDirectory
#endif
, getDirectoryContents
, getCurrentDirectory
, setCurrentDirectory
#if MIN_VERSION_directory(1,2,3)
, withCurrentDirectory
#endif
, getHomeDirectory
#if MIN_VERSION_directory(1,2,3)
, XdgDirectory(..)
, getXdgDirectory
#endif
, getAppUserDataDirectory
, getUserDocumentsDirectory
, getTemporaryDirectory
, removeFile
, renameFile
#if MIN_VERSION_directory(1,2,7)
, renamePath
#endif
, copyFile
#if MIN_VERSION_directory(1,2,6)
, copyFileWithMetadata
#endif
, canonicalizePath
#if MIN_VERSION_directory(1,2,2)
, makeAbsolute
#endif
, makeRelativeToCurrentDirectory
, findExecutable
#if MIN_VERSION_directory(1,2,2)
, findExecutables
#endif
#if MIN_VERSION_directory(1,2,4)
, findExecutablesInDirectories
#endif
, findFile
#if MIN_VERSION_directory(1,2,1)
, findFiles
#endif
#if MIN_VERSION_directory(1,2,6)
, findFileWith
#endif
#if MIN_VERSION_directory(1,2,1)
, findFilesWith
#endif
#if MIN_VERSION_directory(1,2,4)
, exeExtension
#endif
#if MIN_VERSION_directory(1,2,7)
, getFileSize
#endif
#if MIN_VERSION_directory(1,2,7)
, doesPathExist
#endif
, doesFileExist
, doesDirectoryExist
#if MIN_VERSION_directory(1,3,0)
, pathIsSymbolicLink
#endif
, Permissions
, emptyPermissions
, readable
, writable
, executable
, searchable
, setOwnerReadable
, setOwnerWritable
, setOwnerExecutable
, setOwnerSearchable
, getPermissions
, setPermissions
, copyPermissions
#if MIN_VERSION_directory(1,2,3)
, getAccessTime
#endif
, getModificationTime
#if MIN_VERSION_directory(1,2,3)
, setAccessTime
, setModificationTime
#endif
) where
import Control.Monad.IO.Unlift
import Data.Time.Clock
import qualified System.Directory as D
import System.Directory
( Permissions
#if MIN_VERSION_directory(1,2,3)
, XdgDirectory(..)
#endif
, emptyPermissions
#if MIN_VERSION_directory(1,2,4)
, exeExtension
#endif
, executable
, readable
, searchable
, setOwnerExecutable
, setOwnerReadable
, setOwnerSearchable
, setOwnerWritable
, writable
)
{-# INLINE createDirectory #-}
createDirectory :: MonadIO m => FilePath -> m ()
createDirectory = liftIO . D.createDirectory
{-# INLINE createDirectoryIfMissing #-}
createDirectoryIfMissing :: MonadIO m => Bool -> FilePath -> m ()
createDirectoryIfMissing create_parents path0 =
liftIO (D.createDirectoryIfMissing create_parents path0)
{-# INLINE removeDirectory #-}
removeDirectory :: MonadIO m => FilePath -> m ()
removeDirectory = liftIO . D.removeDirectory
{-# INLINE removeDirectoryRecursive #-}
removeDirectoryRecursive :: MonadIO m => FilePath -> m ()
removeDirectoryRecursive = liftIO . D.removeDirectoryRecursive
#if MIN_VERSION_directory(1,2,7)
{-# INLINE removePathForcibly #-}
removePathForcibly :: MonadIO m => FilePath -> m ()
removePathForcibly = liftIO . D.removePathForcibly
#endif
{-# INLINE renameDirectory #-}
renameDirectory :: MonadIO m => FilePath -> FilePath -> m ()
renameDirectory opath npath = liftIO (D.renameDirectory opath npath)
#if MIN_VERSION_directory(1,2,5)
{-# INLINE listDirectory #-}
listDirectory :: MonadIO m => FilePath -> m [FilePath]
listDirectory = liftIO . D.listDirectory
#endif
{-# INLINE getDirectoryContents #-}
getDirectoryContents :: MonadIO m => FilePath -> m [FilePath]
getDirectoryContents = liftIO . D.getDirectoryContents
{-# INLINE getCurrentDirectory #-}
getCurrentDirectory :: MonadIO m => m FilePath
getCurrentDirectory = liftIO D.getCurrentDirectory
{-# INLINE setCurrentDirectory #-}
setCurrentDirectory :: MonadIO m => FilePath -> m ()
setCurrentDirectory = liftIO . D.setCurrentDirectory
#if MIN_VERSION_directory(1,2,3)
{-# INLINE withCurrentDirectory #-}
withCurrentDirectory :: MonadUnliftIO m => FilePath -> m a -> m a
withCurrentDirectory dir action =
withRunInIO (\u -> D.withCurrentDirectory dir (u action))
#endif
{-# INLINE getHomeDirectory #-}
getHomeDirectory :: MonadIO m => m FilePath
getHomeDirectory = liftIO D.getHomeDirectory
#if MIN_VERSION_directory(1,2,3)
{-# INLINE getXdgDirectory #-}
getXdgDirectory :: MonadIO m => XdgDirectory -> FilePath -> m FilePath
getXdgDirectory xdgDir suffix = liftIO (D.getXdgDirectory xdgDir suffix)
#endif
{-# INLINE getAppUserDataDirectory #-}
getAppUserDataDirectory :: MonadIO m => FilePath -> m FilePath
getAppUserDataDirectory = liftIO . D.getAppUserDataDirectory
{-# INLINE getUserDocumentsDirectory #-}
getUserDocumentsDirectory :: MonadIO m => m FilePath
getUserDocumentsDirectory = liftIO D.getUserDocumentsDirectory
{-# INLINE getTemporaryDirectory #-}
getTemporaryDirectory :: MonadIO m => m FilePath
getTemporaryDirectory = liftIO D.getTemporaryDirectory
{-# INLINE removeFile #-}
removeFile :: MonadIO m => FilePath -> m ()
removeFile = liftIO . D.removeFile
{-# INLINE renameFile #-}
renameFile :: MonadIO m => FilePath -> FilePath -> m ()
renameFile opath npath = liftIO (D.renameFile opath npath)
#if MIN_VERSION_directory(1,2,7)
{-# INLINE renamePath #-}
renamePath :: MonadIO m => FilePath -> FilePath -> m ()
renamePath opath npath = liftIO (D.renamePath opath npath)
#endif
{-# INLINE copyFile #-}
copyFile :: MonadIO m => FilePath -> FilePath -> m ()
copyFile fromFPath toFPath = liftIO (D.copyFile fromFPath toFPath)
#if MIN_VERSION_directory(1,2,6)
{-# INLINE copyFileWithMetadata #-}
copyFileWithMetadata :: MonadIO m => FilePath -> FilePath -> m ()
copyFileWithMetadata src dst = liftIO (D.copyFileWithMetadata src dst)
#endif
{-# INLINE canonicalizePath #-}
canonicalizePath :: MonadIO m => FilePath -> m FilePath
canonicalizePath = liftIO . D.canonicalizePath
#if MIN_VERSION_directory(1,2,2)
{-# INLINE makeAbsolute #-}
makeAbsolute :: MonadIO m => FilePath -> m FilePath
makeAbsolute = liftIO . D.makeAbsolute
#endif
{-# INLINE makeRelativeToCurrentDirectory #-}
makeRelativeToCurrentDirectory :: MonadIO m => FilePath -> m FilePath
makeRelativeToCurrentDirectory = liftIO . D.makeRelativeToCurrentDirectory
{-# INLINE findExecutable #-}
findExecutable :: MonadIO m => String -> m (Maybe FilePath)
findExecutable = liftIO . D.findExecutable
#if MIN_VERSION_directory(1,2,2)
{-# INLINE findExecutables #-}
findExecutables :: MonadIO m => String -> m [FilePath]
findExecutables = liftIO . D.findExecutables
#endif
#if MIN_VERSION_directory(1,2,4)
{-# INLINE findExecutablesInDirectories #-}
findExecutablesInDirectories ::
MonadIO m => [FilePath] -> String -> m [FilePath]
findExecutablesInDirectories path binary =
liftIO (D.findExecutablesInDirectories path binary)
#endif
{-# INLINE findFile #-}
findFile :: MonadIO m => [FilePath] -> String -> m (Maybe FilePath)
findFile ds name = liftIO (D.findFile ds name)
#if MIN_VERSION_directory(1,2,1)
{-# INLINE findFiles #-}
findFiles :: MonadIO m => [FilePath] -> String -> m [FilePath]
findFiles ds name = liftIO (D.findFiles ds name)
#endif
#if MIN_VERSION_directory(1,2,6)
{-# INLINE findFileWith #-}
findFileWith ::
MonadUnliftIO m
=> (FilePath -> m Bool)
-> [FilePath]
-> String
-> m (Maybe FilePath)
findFileWith f ds name = withRunInIO (\u -> D.findFileWith (u . f) ds name)
#endif
#if MIN_VERSION_directory(1,2,1)
{-# INLINE findFilesWith #-}
findFilesWith ::
MonadUnliftIO m
=> (FilePath -> m Bool)
-> [FilePath]
-> String
-> m [FilePath]
findFilesWith f ds name = withRunInIO (\u -> D.findFilesWith (u . f) ds name)
#endif
#if MIN_VERSION_directory(1,2,7)
{-# INLINE getFileSize #-}
getFileSize :: MonadIO m => FilePath -> m Integer
getFileSize = liftIO . D.getFileSize
#endif
#if MIN_VERSION_directory(1,2,7)
{-# INLINE doesPathExist #-}
doesPathExist :: MonadIO m => FilePath -> m Bool
doesPathExist = liftIO . D.doesPathExist
#endif
{-# INLINE doesFileExist #-}
doesFileExist :: MonadIO m => FilePath -> m Bool
doesFileExist = liftIO . D.doesFileExist
{-# INLINE doesDirectoryExist #-}
doesDirectoryExist :: MonadIO m => FilePath -> m Bool
doesDirectoryExist = liftIO . D.doesDirectoryExist
#if MIN_VERSION_directory(1,3,0)
{-# INLINE pathIsSymbolicLink #-}
pathIsSymbolicLink :: MonadIO m => FilePath -> m Bool
pathIsSymbolicLink = liftIO . D.pathIsSymbolicLink
#endif
{-# INLINE getPermissions #-}
getPermissions :: MonadIO m => FilePath -> m Permissions
getPermissions = liftIO . D.getPermissions
{-# INLINE setPermissions #-}
setPermissions :: MonadIO m => FilePath -> Permissions -> m ()
setPermissions name p = liftIO (D.setPermissions name p)
{-# INLINE copyPermissions #-}
copyPermissions :: MonadIO m => FilePath -> FilePath -> m ()
copyPermissions source dest = liftIO (D.copyPermissions source dest)
#if MIN_VERSION_directory(1,2,3)
{-# INLINE getAccessTime #-}
getAccessTime :: MonadIO m => FilePath -> m UTCTime
getAccessTime = liftIO . D.getAccessTime
#endif
{-# INLINE getModificationTime #-}
getModificationTime :: MonadIO m => FilePath -> m UTCTime
getModificationTime = liftIO . D.getModificationTime
#if MIN_VERSION_directory(1,2,3)
{-# INLINE setAccessTime #-}
setAccessTime :: MonadIO m => FilePath -> UTCTime -> m ()
setAccessTime path atime = liftIO (D.setAccessTime path atime)
setModificationTime :: MonadIO m => FilePath -> UTCTime -> m ()
setModificationTime path mtime = liftIO (D.setModificationTime path mtime)
#endif