effects-fs-0.1: FileSystem effects
Safe HaskellNone
LanguageGHC2021

Effects.FileSystem.PathReader

Description

Provides the MonadPathReader effect.

Since: 0.1

Synopsis

Effect

class Monad m => MonadPathReader (m :: Type -> Type) where Source #

Represents file-system reader effects.

Since: 0.1

Methods

listDirectory :: OsPath -> m [OsPath] Source #

Lifted listDirectory.

Since: 0.1

getDirectoryContents :: OsPath -> m [OsPath] Source #

Lifted getDirectoryContents.

Since: 0.1

getCurrentDirectory :: m OsPath Source #

Lifted getCurrentDirectory.

Since: 0.1

getHomeDirectory :: m OsPath Source #

Lifted getHomeDirectory.

Since: 0.1

getXdgDirectory :: XdgDirectory -> OsPath -> m OsPath Source #

Lifted getXdgDirectory.

Since: 0.1

getXdgDirectoryList :: XdgDirectoryList -> m [OsPath] Source #

Lifted getXdgDirectoryList.

Since: 0.1

getAppUserDataDirectory :: OsPath -> m OsPath Source #

Lifted getAppUserDataDirectory.

Since: 0.1

getUserDocumentsDirectory :: m OsPath Source #

Lifted getUserDocumentsDirectory.

Since: 0.1

getTemporaryDirectory :: m OsPath Source #

Lifted getTemporaryDirectory.

Since: 0.1

getFileSize :: OsPath -> m Integer Source #

Lifted getFileSize.

Since: 0.1

canonicalizePath :: OsPath -> m OsPath Source #

Lifted canonicalizePath.

Since: 0.1

makeAbsolute :: OsPath -> m OsPath Source #

Lifted makeAbsolute.

Since: 0.1

makeRelativeToCurrentDirectory :: OsPath -> m OsPath Source #

doesPathExist :: OsPath -> m Bool Source #

Lifted doesPathExist.

Since: 0.1

doesFileExist :: OsPath -> m Bool Source #

Lifted doesFileExist.

Since: 0.1

doesDirectoryExist :: OsPath -> m Bool Source #

Lifted doesDirectoryExist.

Since: 0.1

findExecutable :: OsPath -> m (Maybe OsPath) Source #

Lifted findExecutable.

Since: 0.1

findExecutables :: OsPath -> m [OsPath] Source #

Lifted findExecutables.

Since: 0.1

findExecutablesInDirectories :: [OsPath] -> OsPath -> m [OsPath] Source #

findFileWith :: (OsPath -> m Bool) -> [OsPath] -> OsPath -> m (Maybe OsPath) Source #

Lifted findFileWith.

Since: 0.1

findFilesWith :: (OsPath -> m Bool) -> [OsPath] -> OsPath -> m [OsPath] Source #

Lifted findFilesWith.

Since: 0.1

pathIsSymbolicLink :: OsPath -> m Bool Source #

Lifted pathIsSymbolicLink.

Since: 0.1

getSymbolicLinkTarget :: OsPath -> m OsPath Source #

Lifted getSymbolicLinkTarget.

Since: 0.1

getPermissions :: OsPath -> m Permissions Source #

Lifted getPermissions.

Since: 0.1

getAccessTime :: OsPath -> m UTCTime Source #

Lifted getAccessTime.

Since: 0.1

getModificationTime :: OsPath -> m UTCTime Source #

Lifted getModificationTime.

Since: 0.1

Instances

Instances details
MonadPathReader IO Source # 
Instance details

Defined in Effects.FileSystem.PathReader

MonadPathReader m => MonadPathReader (ReaderT env m) Source # 
Instance details

Defined in Effects.FileSystem.PathReader

Methods

listDirectory :: OsPath -> ReaderT env m [OsPath] Source #

getDirectoryContents :: OsPath -> ReaderT env m [OsPath] Source #

getCurrentDirectory :: ReaderT env m OsPath Source #

getHomeDirectory :: ReaderT env m OsPath Source #

getXdgDirectory :: XdgDirectory -> OsPath -> ReaderT env m OsPath Source #

getXdgDirectoryList :: XdgDirectoryList -> ReaderT env m [OsPath] Source #

getAppUserDataDirectory :: OsPath -> ReaderT env m OsPath Source #

getUserDocumentsDirectory :: ReaderT env m OsPath Source #

getTemporaryDirectory :: ReaderT env m OsPath Source #

getFileSize :: OsPath -> ReaderT env m Integer Source #

canonicalizePath :: OsPath -> ReaderT env m OsPath Source #

makeAbsolute :: OsPath -> ReaderT env m OsPath Source #

makeRelativeToCurrentDirectory :: OsPath -> ReaderT env m OsPath Source #

doesPathExist :: OsPath -> ReaderT env m Bool Source #

doesFileExist :: OsPath -> ReaderT env m Bool Source #

doesDirectoryExist :: OsPath -> ReaderT env m Bool Source #

findExecutable :: OsPath -> ReaderT env m (Maybe OsPath) Source #

findExecutables :: OsPath -> ReaderT env m [OsPath] Source #

findExecutablesInDirectories :: [OsPath] -> OsPath -> ReaderT env m [OsPath] Source #

findFileWith :: (OsPath -> ReaderT env m Bool) -> [OsPath] -> OsPath -> ReaderT env m (Maybe OsPath) Source #

findFilesWith :: (OsPath -> ReaderT env m Bool) -> [OsPath] -> OsPath -> ReaderT env m [OsPath] Source #

pathIsSymbolicLink :: OsPath -> ReaderT env m Bool Source #

getSymbolicLinkTarget :: OsPath -> ReaderT env m OsPath Source #

getPermissions :: OsPath -> ReaderT env m Permissions Source #

getAccessTime :: OsPath -> ReaderT env m UTCTime Source #

getModificationTime :: OsPath -> ReaderT env m UTCTime Source #

type OsPath = OsString #

Type representing filenames/pathnames.

This type doesn't add any guarantees over OsString.

Functions

findFile :: (HasCallStack, MonadPathReader m) => [OsPath] -> OsPath -> m (Maybe OsPath) Source #

Search through the given list of directories for the given file.

The behavior is equivalent to findFileWith, returning only the first occurrence. Details can be found in the documentation of findFileWith.

Since: 0.1

findFiles :: (HasCallStack, MonadPathReader m) => [OsPath] -> OsPath -> m [OsPath] Source #

Search through the given list of directories for the given file and returns all paths where the given file exists.

The behavior is equivalent to findFilesWith. Details can be found in the documentation of findFilesWith.

Since: 0.1

XDG Utils

getXdgData :: (HasCallStack, MonadPathReader m) => OsPath -> m OsPath Source #

Retrieves the XDG data directory e.g. ~/.local/share.

Since: 0.1

getXdgConfig :: (HasCallStack, MonadPathReader m) => OsPath -> m OsPath Source #

Retrieves the XDG config directory e.g. ~/.config.

Since: 0.1

getXdgCache :: (HasCallStack, MonadPathReader m) => OsPath -> m OsPath Source #

Retrieves the XDG cache directory e.g. ~/.cache.

Since: 0.1

getXdgState :: (HasCallStack, MonadPathReader m) => OsPath -> m OsPath Source #

Retrieves the XDG state directory e.g. ~/.local/state.

Since: 0.1

Path Types

data PathType Source #

Path type.

Since: fs-utils-0.1

Constructors

PathTypeFile

Since: fs-utils-0.1

PathTypeDirectory

Since: fs-utils-0.1

PathTypeSymbolicLink

Since: fs-utils-0.1

PathTypeOther

Since: fs-utils-0.1

Instances

Instances details
Bounded PathType

Since: fs-utils-0.1

Instance details

Defined in FileSystem.PathType

Enum PathType

Since: fs-utils-0.1

Instance details

Defined in FileSystem.PathType

Generic PathType 
Instance details

Defined in FileSystem.PathType

Associated Types

type Rep PathType

Since: fs-utils-0.1

Instance details

Defined in FileSystem.PathType

type Rep PathType = D1 ('MetaData "PathType" "FileSystem.PathType" "fs-utils-0.1-e372dd9cd77baa6a563dd7032c473a3c70c538a3226981dab13c2716d821a2ce" 'False) ((C1 ('MetaCons "PathTypeFile" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PathTypeDirectory" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "PathTypeSymbolicLink" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PathTypeOther" 'PrefixI 'False) (U1 :: Type -> Type)))

Methods

from :: PathType -> Rep PathType x #

to :: Rep PathType x -> PathType #

Show PathType

Since: fs-utils-0.1

Instance details

Defined in FileSystem.PathType

NFData PathType

Since: fs-utils-0.1

Instance details

Defined in FileSystem.PathType

Methods

rnf :: PathType -> () #

Eq PathType

Since: fs-utils-0.1

Instance details

Defined in FileSystem.PathType

Ord PathType

Since: fs-utils-0.1

Instance details

Defined in FileSystem.PathType

type Rep PathType

Since: fs-utils-0.1

Instance details

Defined in FileSystem.PathType

type Rep PathType = D1 ('MetaData "PathType" "FileSystem.PathType" "fs-utils-0.1-e372dd9cd77baa6a563dd7032c473a3c70c538a3226981dab13c2716d821a2ce" 'False) ((C1 ('MetaCons "PathTypeFile" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PathTypeDirectory" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "PathTypeSymbolicLink" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PathTypeOther" 'PrefixI 'False) (U1 :: Type -> Type)))

Functions

displayPathType :: IsString a => PathType -> a Source #

String representation of PathType.

Since: fs-utils-0.1

getPathType :: (HasCallStack, MonadCatch m, MonadPathReader m) => OsPath -> m PathType Source #

Returns the type for a given path without following symlinks. Throws IOException if the path does not exist or the type cannot be detected.

For a faster version in terms of PosixCompat, see effects-unix-compat.

Since: 0.1

isPathType Source #

Arguments

:: (HasCallStack, MonadCatch m, MonadPathReader m) 
=> PathType

Expected path type.

-> OsPath 
-> m Bool 

Checks that the path type matches the expectation. Throws IOException if the path does not exist or the type cannot be detected.

For a faster version in terms of Posix(Compat), see effects-unix(-compat).

Since: 0.1

throwIfWrongPathType Source #

Arguments

:: (HasCallStack, MonadCatch m, MonadPathReader m) 
=> String

The location for the thrown exception (e.g. function name)

-> PathType

Expected path type

-> OsPath

Path

-> m () 

Throws IOException if the path does not exist or the expected path type does not match actual.

For a faster version in terms of Posix(Compat), see effects-unix(-compat).

Since: 0.1

Misc

listDirectoryRecursive Source #

Arguments

:: (HasCallStack, MonadPathReader m) 
=> OsPath

Root path.

-> m ([OsPath], [OsPath])

(files, directories)

Retrieves the recursive directory contents; splits the sub folders and directories apart.

Since: 0.1

listDirectoryRecursiveSymbolicLink Source #

Arguments

:: (HasCallStack, MonadCatch m, MonadPathReader m) 
=> OsPath

Root path.

-> m ([OsPath], [OsPath], [OsPath])

(files, directories, symbolic links)

Like listDirectoryRecursive except symbolic links are not traversed i.e. they are returned separately.

Since: 0.1

doesSymbolicLinkExist :: (HasCallStack, MonadCatch m, MonadPathReader m) => OsPath -> m Bool Source #

Returns true if the path is a symbolic link. Does not traverse the link.

Since: 0.1

pathIsSymbolicDirectoryLink :: (HasCallStack, MonadPathReader m) => OsPath -> m Bool Source #

Returns true if p is a symbolic link and it points to an extant directory. Throws an exception if the path is not a symbolic link or the target does not exist.

This function and pathIsSymbolicFileLink are intended to distinguish file and directory links on Windows. This matters for knowing when to use:

  • createFileLink vs. createDirectoryLink
  • removeFile vs. removeDirectoryLink

Suppose we want to copy an arbitrary path p. We first determine that p is a symlink via doesSymbolicLinkExist. If pathIsSymbolicDirectoryLink returns true then we know we should use Effects.FileSystem.PathWriter's createDirectoryLink. Otherwise we can fall back to createFileLink.

Because this relies on the symlink's target, this is best effort, and it is possible pathIsSymbolicDirectoryLink and pathIsSymbolicFileLink both return false.

Note that Posix makes no distinction between file and directory symbolic links. Thus if your system only has to work on Posix, you probably don't need this function.

Since: 0.1

Re-exports

data XdgDirectory #

Special directories for storing user-specific application data, configuration, and cache files, as specified by the XDG Base Directory Specification.

Note: On Windows, XdgData and XdgConfig usually map to the same directory.

Since: directory-1.2.3.0

Constructors

XdgData

For data files (e.g. images). It uses the XDG_DATA_HOME environment variable. On non-Windows systems, the default is ~/.local/share. On Windows, the default is %APPDATA% (e.g. C:/Users/<user>/AppData/Roaming). Can be considered as the user-specific equivalent of /usr/share.

XdgConfig

For configuration files. It uses the XDG_CONFIG_HOME environment variable. On non-Windows systems, the default is ~/.config. On Windows, the default is %APPDATA% (e.g. C:/Users/<user>/AppData/Roaming). Can be considered as the user-specific equivalent of /etc.

XdgCache

For non-essential files (e.g. cache). It uses the XDG_CACHE_HOME environment variable. On non-Windows systems, the default is ~/.cache. On Windows, the default is %LOCALAPPDATA% (e.g. C:/Users/<user>/AppData/Local). Can be considered as the user-specific equivalent of /var/cache.

XdgState

For data that should persist between (application) restarts, but that is not important or portable enough to the user that it should be stored in XdgData. It uses the XDG_STATE_HOME environment variable. On non-Windows sytems, the default is ~/.local/state. On Windows, the default is %LOCALAPPDATA% (e.g. C:/Users/<user>/AppData/Local).

Since: directory-1.3.7.0

Instances

Instances details
Bounded XdgDirectory 
Instance details

Defined in System.Directory.Internal.Common

Enum XdgDirectory 
Instance details

Defined in System.Directory.Internal.Common

Read XdgDirectory 
Instance details

Defined in System.Directory.Internal.Common

Show XdgDirectory 
Instance details

Defined in System.Directory.Internal.Common

Eq XdgDirectory 
Instance details

Defined in System.Directory.Internal.Common

Ord XdgDirectory 
Instance details

Defined in System.Directory.Internal.Common

data XdgDirectoryList #

Search paths for various application data, as specified by the XDG Base Directory Specification.

The list of paths is split using searchPathSeparator, which on Windows is a semicolon.

Note: On Windows, XdgDataDirs and XdgConfigDirs usually yield the same result.

Since: directory-1.3.2.0

Constructors

XdgDataDirs

For data files (e.g. images). It uses the XDG_DATA_DIRS environment variable. On non-Windows systems, the default is /usr/local/share/ and /usr/share/. On Windows, the default is %PROGRAMDATA% or %ALLUSERSPROFILE% (e.g. C:/ProgramData).

XdgConfigDirs

For configuration files. It uses the XDG_CONFIG_DIRS environment variable. On non-Windows systems, the default is /etc/xdg. On Windows, the default is %PROGRAMDATA% or %ALLUSERSPROFILE% (e.g. C:/ProgramData).

Instances

Instances details
Bounded XdgDirectoryList 
Instance details

Defined in System.Directory.Internal.Common

Enum XdgDirectoryList 
Instance details

Defined in System.Directory.Internal.Common

Read XdgDirectoryList 
Instance details

Defined in System.Directory.Internal.Common

Show XdgDirectoryList 
Instance details

Defined in System.Directory.Internal.Common

Eq XdgDirectoryList 
Instance details

Defined in System.Directory.Internal.Common

Ord XdgDirectoryList 
Instance details

Defined in System.Directory.Internal.Common

data UTCTime #

This is the simplest representation of UTC. It consists of the day number, and a time offset from midnight. Note that if a day has a leap second added to it, it will have 86401 seconds.

Constructors

UTCTime 

Fields

Instances

Instances details
Data UTCTime 
Instance details

Defined in Data.Time.Clock.Internal.UTCTime

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> UTCTime -> c UTCTime #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c UTCTime #

toConstr :: UTCTime -> Constr #

dataTypeOf :: UTCTime -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c UTCTime) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c UTCTime) #

gmapT :: (forall b. Data b => b -> b) -> UTCTime -> UTCTime #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> UTCTime -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> UTCTime -> r #

gmapQ :: (forall d. Data d => d -> u) -> UTCTime -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> UTCTime -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> UTCTime -> m UTCTime #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> UTCTime -> m UTCTime #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> UTCTime -> m UTCTime #

NFData UTCTime 
Instance details

Defined in Data.Time.Clock.Internal.UTCTime

Methods

rnf :: UTCTime -> () #

Eq UTCTime 
Instance details

Defined in Data.Time.Clock.Internal.UTCTime

Methods

(==) :: UTCTime -> UTCTime -> Bool #

(/=) :: UTCTime -> UTCTime -> Bool #

Ord UTCTime 
Instance details

Defined in Data.Time.Clock.Internal.UTCTime

ISO8601 UTCTime

yyyy-mm-ddThh:mm:ss[.sss]Z (ISO 8601:2004(E) sec. 4.3.2 extended format)

Instance details

Defined in Data.Time.Format.ISO8601