| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Effects.FileSystem.PathReader
Description
Provides the MonadPathReader effect.
Since: 0.1
Synopsis
- class Monad m => MonadPathReader (m :: Type -> Type) where
- listDirectory :: OsPath -> m [OsPath]
- getDirectoryContents :: OsPath -> m [OsPath]
- getCurrentDirectory :: m OsPath
- getHomeDirectory :: m OsPath
- getXdgDirectory :: XdgDirectory -> OsPath -> m OsPath
- getXdgDirectoryList :: XdgDirectoryList -> m [OsPath]
- getAppUserDataDirectory :: OsPath -> m OsPath
- getUserDocumentsDirectory :: m OsPath
- getTemporaryDirectory :: m OsPath
- getFileSize :: OsPath -> m Integer
- canonicalizePath :: OsPath -> m OsPath
- makeAbsolute :: OsPath -> m OsPath
- makeRelativeToCurrentDirectory :: OsPath -> m OsPath
- doesPathExist :: OsPath -> m Bool
- doesFileExist :: OsPath -> m Bool
- doesDirectoryExist :: OsPath -> m Bool
- findExecutable :: OsPath -> m (Maybe OsPath)
- findExecutables :: OsPath -> m [OsPath]
- findExecutablesInDirectories :: [OsPath] -> OsPath -> m [OsPath]
- findFileWith :: (OsPath -> m Bool) -> [OsPath] -> OsPath -> m (Maybe OsPath)
- findFilesWith :: (OsPath -> m Bool) -> [OsPath] -> OsPath -> m [OsPath]
- pathIsSymbolicLink :: OsPath -> m Bool
- getSymbolicLinkTarget :: OsPath -> m OsPath
- getPermissions :: OsPath -> m Permissions
- getAccessTime :: OsPath -> m UTCTime
- getModificationTime :: OsPath -> m UTCTime
- type OsPath = OsString
- findFile :: (HasCallStack, MonadPathReader m) => [OsPath] -> OsPath -> m (Maybe OsPath)
- findFiles :: (HasCallStack, MonadPathReader m) => [OsPath] -> OsPath -> m [OsPath]
- getXdgData :: (HasCallStack, MonadPathReader m) => OsPath -> m OsPath
- getXdgConfig :: (HasCallStack, MonadPathReader m) => OsPath -> m OsPath
- getXdgCache :: (HasCallStack, MonadPathReader m) => OsPath -> m OsPath
- getXdgState :: (HasCallStack, MonadPathReader m) => OsPath -> m OsPath
- data PathType
- displayPathType :: IsString a => PathType -> a
- getPathType :: (HasCallStack, MonadCatch m, MonadPathReader m) => OsPath -> m PathType
- isPathType :: (HasCallStack, MonadCatch m, MonadPathReader m) => PathType -> OsPath -> m Bool
- throwIfWrongPathType :: (HasCallStack, MonadCatch m, MonadPathReader m) => String -> PathType -> OsPath -> m ()
- expandTilde :: (HasCallStack, MonadPathReader m, MonadThrow m) => OsPath -> m OsPath
- forExpandedTilde :: (HasCallStack, MonadPathReader m, MonadThrow m) => OsPath -> (OsPath -> m a) -> m a
- onExpandedTilde :: (HasCallStack, MonadPathReader m) => (OsPath -> m a) -> OsPath -> m a
- listDirectoryRecursive :: (HasCallStack, MonadPathReader m) => OsPath -> m ([OsPath], [OsPath])
- listDirectoryRecursiveSymbolicLink :: (HasCallStack, MonadCatch m, MonadPathReader m) => OsPath -> m ([OsPath], [OsPath], [OsPath])
- doesSymbolicLinkExist :: (HasCallStack, MonadCatch m, MonadPathReader m) => OsPath -> m Bool
- pathIsSymbolicDirectoryLink :: (HasCallStack, MonadPathReader m) => OsPath -> m Bool
- pathIsSymbolicFileLink :: (HasCallStack, MonadPathReader m) => OsPath -> m Bool
- data XdgDirectory
- data XdgDirectoryList
- data Permissions
- data UTCTime = UTCTime {
- utctDay :: Day
- utctDayTime :: DiffTime
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 #
Lifted makeRelativeToCurrentDirectory.
Since: 0.1
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 #
Lifted findExecutablesInDirectories.
Since: 0.1
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
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
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
| NFData PathType Source # | Since: fs-utils-0.1 | ||||
Defined in FileSystem.PathType | |||||
| Bounded PathType Source # | Since: fs-utils-0.1 | ||||
| Enum PathType Source # | Since: fs-utils-0.1 | ||||
Defined in FileSystem.PathType | |||||
| Generic PathType Source # | |||||
Defined in FileSystem.PathType Associated Types
| |||||
| Show PathType Source # | Since: fs-utils-0.1 | ||||
| Eq PathType Source # | Since: fs-utils-0.1 | ||||
| Ord PathType Source # | Since: fs-utils-0.1 | ||||
Defined in FileSystem.PathType | |||||
| type Rep PathType Source # | Since: fs-utils-0.1 | ||||
Defined in FileSystem.PathType type Rep PathType = D1 ('MetaData "PathType" "FileSystem.PathType" "fs-utils-0.1-fbba4caea8c7c33ae6e68720026fbc0eb28dfe774a233f29a0428bd722806d8d" '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
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
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
Tilde expansion
Arguments
| :: (HasCallStack, MonadPathReader m, MonadThrow m) | |
| => OsPath | Path to potentially expand. |
| -> m OsPath |
onExpandedTilde that simply returns the expanded path.
Since: 0.1
Arguments
| :: (HasCallStack, MonadPathReader m, MonadThrow m) | |
| => OsPath | Path to potentially expand. |
| -> (OsPath -> m a) | Action to run on the expanded path. |
| -> m a |
Flipped onExpandedTilde.
Since: 0.1
Arguments
| :: (HasCallStack, MonadPathReader m) | |
| => (OsPath -> m a) | Action to run on the expanded path. |
| -> OsPath | Path to potentially expand. |
| -> m a |
Expands "tilde prefix(es)" (~) with the home directory, running the action on the result.
"~/..."
"~"
"~\..."(windows only)
If the path contains no tildes, it is handled normally.
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:
createFileLinkvs.createDirectoryLinkremoveFilevs.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
pathIsSymbolicFileLink :: (HasCallStack, MonadPathReader m) => OsPath -> m Bool Source #
Like pathIsSymbolicDirectoryLink but for files.
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 |
| XdgConfig | For configuration files.
It uses the |
| XdgCache | For non-essential files (e.g. cache).
It uses the |
| 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 Since: directory-1.3.7.0 |
Instances
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 |
| XdgConfigDirs | For configuration files.
It uses the |
Instances
data Permissions #
Instances
| Read Permissions # | |
Defined in System.Directory.Internal.Common Methods readsPrec :: Int -> ReadS Permissions # readList :: ReadS [Permissions] # readPrec :: ReadPrec Permissions # readListPrec :: ReadPrec [Permissions] # | |
| Show Permissions # | |
Defined in System.Directory.Internal.Common Methods showsPrec :: Int -> Permissions -> ShowS # show :: Permissions -> String # showList :: [Permissions] -> ShowS # | |
| Eq Permissions # | |
Defined in System.Directory.Internal.Common | |
| Ord Permissions # | |
Defined in System.Directory.Internal.Common Methods compare :: Permissions -> Permissions -> Ordering # (<) :: Permissions -> Permissions -> Bool # (<=) :: Permissions -> Permissions -> Bool # (>) :: Permissions -> Permissions -> Bool # (>=) :: Permissions -> Permissions -> Bool # max :: Permissions -> Permissions -> Permissions # min :: Permissions -> Permissions -> Permissions # | |
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
| NFData UTCTime # | |||||
Defined in Data.Time.Clock.Internal.UTCTime | |||||
| Data UTCTime # | |||||
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 # | |||||
| Generic UTCTime # | |||||
Defined in Data.Time.Clock.Internal.UTCTime Associated Types
| |||||
| Eq UTCTime # | |||||
| Ord UTCTime # | |||||
Defined in Data.Time.Clock.Internal.UTCTime | |||||
| ISO8601 UTCTime # |
| ||||
Defined in Data.Time.Format.ISO8601 Methods | |||||
| Lift UTCTime # | |||||
| type Rep UTCTime # | |||||
Defined in Data.Time.Clock.Internal.UTCTime type Rep UTCTime = D1 ('MetaData "UTCTime" "Data.Time.Clock.Internal.UTCTime" "time-1.14-247a" 'False) (C1 ('MetaCons "UTCTime" 'PrefixI 'True) (S1 ('MetaSel ('Just "utctDay") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Day) :*: S1 ('MetaSel ('Just "utctDayTime") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 DiffTime))) | |||||