packages feed

filepather-0.5: src/System/FilePath/FilePather/Directory.hs

{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE NoImplicitPrelude #-}

module System.FilePath.FilePather.Directory(
  createDirectory
, createDirectoryIfMissing
, removeDirectory
, removeDirectoryRecursive
, removePathForcibly
, renameDirectory
, listDirectory
, getDirectoryContents
, withCurrentDirectory
, getXdgDirectory
, getAppUserDataDirectory
, removeFile
, renameFile
, renamePath
, copyFile
, copyFileWithMetadata
, getFileSize
, canonicalizePath
, makeAbsolute
, makeRelativeToCurrentDirectory
, doesPathExist
, doesFileExist
, doesDirectoryExist
, findExecutable
, findExecutables
, findExecutablesInDirectories
, findFile
, findFiles
, findFileWith
, findFilesWith
, createFileLink
, createDirectoryLink
, removeDirectoryLink
, pathIsSymbolicLink
, getSymbolicLinkTarget
, getPermissions
, setPermissions
, copyPermissions
, getAccessTime
, getModificationTime
, setAccessTime
, setModificationTime
, module SD
) where

import Control.Category ( Category((.)) )
import Control.Exception ( Exception )
import Control.Lens ( over, _Wrapped )
import Data.Maybe ( Maybe, maybe )
import Data.Bool ( Bool(..) )
import Data.Either ( Either(Right, Left), either )
import Data.Functor ( Functor(fmap) )
import Data.Time ( UTCTime )
import GHC.Num( Integer )
import qualified System.Directory as D
import System.Directory as SD(getCurrentDirectory, getHomeDirectory, XdgDirectory(..), XdgDirectoryList(..), getXdgDirectoryList, getUserDocumentsDirectory, getTemporaryDirectory, exeExtension, Permissions(..), emptyPermissions, readable, writable, executable, searchable, setOwnerReadable, setOwnerWritable, setOwnerExecutable, setOwnerSearchable)
import System.FilePath.FilePather.ReadFilePath
import System.FilePath ( FilePath )
import System.IO ( IO )

createDirectory ::
  Exception e =>
  ReadFilePathT1 e IO
createDirectory =
  tryReadFilePath D.createDirectory

createDirectoryIfMissing ::
  Exception e =>
  Bool
  -> ReadFilePathT1 e IO
createDirectoryIfMissing =
  tryReadFilePath . D.createDirectoryIfMissing

removeDirectory ::
  Exception e =>
  ReadFilePathT1 e IO
removeDirectory =
  tryReadFilePath D.removeDirectory

removeDirectoryRecursive ::
  Exception e =>
  ReadFilePathT1 e IO
removeDirectoryRecursive =
  tryReadFilePath D.removeDirectoryRecursive

removePathForcibly ::
  Exception e =>
  ReadFilePathT1 e IO
removePathForcibly =
  tryReadFilePath D.removePathForcibly

renameDirectory ::
  Exception e =>
  FilePath
  -> ReadFilePathT1 e IO
renameDirectory =
  tryReadFilePath . D.renameDirectory

listDirectory ::
  Exception e =>
  ReadFilePathT e IO [FilePath]
listDirectory =
  tryReadFilePath D.listDirectory

getDirectoryContents ::
  Exception e =>
  ReadFilePathT e IO [FilePath]
getDirectoryContents =
  tryReadFilePath D.listDirectory

withCurrentDirectory ::
  Exception e =>
  IO a
  -> ReadFilePathT e IO a
withCurrentDirectory io =
  tryReadFilePath (`D.withCurrentDirectory` io)

getXdgDirectory ::
  Exception e =>
  XdgDirectory
  -> ReadFilePathT e IO FilePath
getXdgDirectory xdg =
  tryReadFilePath (D.getXdgDirectory xdg)

getAppUserDataDirectory ::
  Exception e =>
  ReadFilePathT e IO FilePath
getAppUserDataDirectory =
  tryReadFilePath D.getAppUserDataDirectory

removeFile ::
  Exception e =>
  ReadFilePathT1 e IO
removeFile =
  tryReadFilePath D.removeFile

renameFile ::
  Exception e =>
  FilePath
  -> ReadFilePathT1 e IO
renameFile =
  tryReadFilePath . D.renameFile

renamePath ::
  Exception e =>
  FilePath
  -> ReadFilePathT1 e IO
renamePath =
  tryReadFilePath . D.renamePath

copyFile ::
  Exception e =>
  FilePath
  -> ReadFilePathT1 e IO
copyFile =
  tryReadFilePath . D.copyFile

copyFileWithMetadata ::
  Exception e =>
  FilePath
  -> ReadFilePathT1 e IO
copyFileWithMetadata =
  tryReadFilePath . D.copyFileWithMetadata

getFileSize ::
  Exception e =>
  ReadFilePathT e IO Integer
getFileSize =
  tryReadFilePath D.getFileSize

canonicalizePath ::
  Exception e =>
  ReadFilePathT e IO FilePath
canonicalizePath =
  tryReadFilePath D.canonicalizePath

makeAbsolute ::
  Exception e =>
  ReadFilePathT e IO FilePath
makeAbsolute =
  tryReadFilePath D.makeAbsolute

makeRelativeToCurrentDirectory ::
  Exception e =>
  ReadFilePathT e IO FilePath
makeRelativeToCurrentDirectory =
  tryReadFilePath D.makeRelativeToCurrentDirectory

doesPathExist ::
  ReadFilePathT e IO Bool
doesPathExist =
  successReadFilePath D.doesPathExist

doesFileExist ::
  ReadFilePathT e IO Bool
doesFileExist =
  successReadFilePath D.doesFileExist

doesDirectoryExist ::
  ReadFilePathT e IO Bool
doesDirectoryExist =
  successReadFilePath D.doesDirectoryExist

findExecutable ::
  ReadFilePathT e IO (Maybe FilePath)
findExecutable =
  successReadFilePath D.findExecutable

findExecutables ::
  ReadFilePathT e IO [FilePath]
findExecutables =
  successReadFilePath D.findExecutables

findExecutablesInDirectories ::
  [FilePath]
  -> ReadFilePathT e IO [FilePath]
findExecutablesInDirectories =
  successReadFilePath . D.findExecutablesInDirectories

findFile ::
  [FilePath]
  -> ReadFilePathT e IO (Maybe FilePath)
findFile =
  successReadFilePath . D.findFile

findFiles ::
  [FilePath]
  -> ReadFilePathT e IO [FilePath]
findFiles =
  successReadFilePath . D.findFiles

findFileWith ::
  ReadFilePathT () IO ()
  -> [FilePath]
  -> ReadFilePathT () IO FilePath
findFileWith x ps =
  over _Wrapped (\k -> fmap (maybe (Left ()) Right) . D.findFileWith (fmap (either (\() -> False) (\() -> True)) . k) ps) x

findFilesWith ::
  ReadFilePathT () IO ()
  -> [FilePath]
  -> ReadFilePathT e' IO [FilePath]
findFilesWith x ps =
  over _Wrapped (\w -> fmap Right . D.findFilesWith (fmap (either (\() -> False) (\() -> True)) . w) ps) x

createFileLink ::
  Exception e =>
  FilePath
  -> ReadFilePathT1 e IO
createFileLink =
  tryReadFilePath . D.createFileLink

createDirectoryLink ::
  Exception e =>
  FilePath
  -> ReadFilePathT1 e IO
createDirectoryLink =
  tryReadFilePath . D.createDirectoryLink

removeDirectoryLink ::
  Exception e =>
  ReadFilePathT1 e IO
removeDirectoryLink =
  tryReadFilePath D.removeDirectoryLink

pathIsSymbolicLink ::
  Exception e =>
  ReadFilePathT e IO Bool
pathIsSymbolicLink =
  tryReadFilePath D.pathIsSymbolicLink

getSymbolicLinkTarget ::
  Exception e =>
  ReadFilePathT e IO FilePath
getSymbolicLinkTarget =
  tryReadFilePath D.getSymbolicLinkTarget

getPermissions ::
  Exception e =>
  ReadFilePathT e IO Permissions
getPermissions =
  tryReadFilePath D.getPermissions

setPermissions ::
  Exception e =>
  Permissions
  -> ReadFilePathT1 e IO
setPermissions p =
  tryReadFilePath (`D.setPermissions` p)

copyPermissions ::
  Exception e =>
  FilePath
  -> ReadFilePathT1 e IO
copyPermissions =
  tryReadFilePath . D.copyPermissions

getAccessTime ::
  Exception e =>
  ReadFilePathT e IO UTCTime
getAccessTime =
  tryReadFilePath D.getAccessTime

getModificationTime ::
  Exception e =>
  ReadFilePathT e IO UTCTime
getModificationTime =
  tryReadFilePath D.getModificationTime

setAccessTime ::
  Exception e =>
  UTCTime
  -> ReadFilePathT1 e IO
setAccessTime u =
  tryReadFilePath (`D.setAccessTime` u)

setModificationTime ::
  Exception e =>
  UTCTime
  -> ReadFilePathT1 e IO
setModificationTime u =
  tryReadFilePath (`D.setModificationTime` u)