effects-fs-0.1: FileSystem effects
Safe HaskellNone
LanguageGHC2021

Effects.FileSystem.PathWriter

Description

Provides the MonadPathWriter effect.

Since: 0.1

Synopsis

Effect

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

Represents file-system writer effects.

Since: 0.1

Methods

createDirectory :: OsPath -> m () Source #

Lifted createDirectory.

Since: 0.1

createDirectoryIfMissing Source #

Arguments

:: Bool

Create its parents too?

-> OsPath

The path to the directory you want to make

-> m () 

Lifted createDirectoryIfMissing.

Since: 0.1

removeDirectory :: OsPath -> m () Source #

Lifted removeDirectory.

Since: 0.1

removeDirectoryRecursive :: OsPath -> m () Source #

Lifted removeDirectoryRecursive.

Since: 0.1

removePathForcibly :: OsPath -> m () Source #

Lifted removePathForcibly.

Since: 0.1

renameDirectory :: OsPath -> OsPath -> m () Source #

Lifted renameDirectory.

Since: 0.1

setCurrentDirectory :: OsPath -> m () Source #

Lifted setCurrentDirectory.

Since: 0.1

withCurrentDirectory :: HasCallStack => OsPath -> m a -> m a Source #

Lifted withCurrentDirectory.

Since: 0.1

removeFile :: OsPath -> m () Source #

Lifted removeFile.

Since: 0.1

renameFile :: OsPath -> OsPath -> m () Source #

Lifted renameFile.

Since: 0.1

renamePath Source #

Arguments

:: OsPath

Old path

-> OsPath

New path

-> m () 

Lifted renamePath.

Since: 0.1

copyFile Source #

Arguments

:: OsPath

Source filename

-> OsPath

Destination filename

-> m () 

Lifted copyFile.

Since: 0.1

copyFileWithMetadata Source #

Arguments

:: OsPath

Source file

-> OsPath

Destination file

-> m () 

Lifted copyFileWithMetadata.

Since: 0.1

createFileLink Source #

Arguments

:: OsPath

path to the target file

-> OsPath

path of the link to be created

-> m () 

Lifted createFileLink.

Since: 0.1

createDirectoryLink Source #

Arguments

:: OsPath

path to the target directory

-> OsPath

path of the link to be created

-> m () 

Lifted createDirectoryLink.

Since: 0.1

removeDirectoryLink :: OsPath -> m () Source #

Lifted removeDirectoryLink.

Since: 0.1

setPermissions :: OsPath -> Permissions -> m () Source #

Lifted setPermissions.

Since: 0.1

copyPermissions :: OsPath -> OsPath -> m () Source #

Lifted copyPermissions.

Since: 0.1

setAccessTime :: OsPath -> UTCTime -> m () Source #

Lifted setAccessTime.

Since: 0.1

setModificationTime :: OsPath -> UTCTime -> m () Source #

Lifted setModificationTime.

Since: 0.1

Instances

Instances details
MonadPathWriter IO Source #

Since: 0.1

Instance details

Defined in Effects.FileSystem.PathWriter

MonadPathWriter m => MonadPathWriter (ReaderT env m) Source #

Since: 0.1

Instance details

Defined in Effects.FileSystem.PathWriter

type OsPath = OsString #

Type representing filenames/pathnames.

This type doesn't add any guarantees over OsString.

Copying

Config

data CopyDirConfig Source #

Directory copying config.

Since: 0.1

Constructors

MkCopyDirConfig 

Fields

Instances

Instances details
Generic CopyDirConfig Source # 
Instance details

Defined in Effects.FileSystem.PathWriter

Associated Types

type Rep CopyDirConfig

Since: effects-fs-0.1

Instance details

Defined in Effects.FileSystem.PathWriter

type Rep CopyDirConfig = D1 ('MetaData "CopyDirConfig" "Effects.FileSystem.PathWriter" "effects-fs-0.1-inplace" 'False) (C1 ('MetaCons "MkCopyDirConfig" 'PrefixI 'True) (S1 ('MetaSel ('Just "overwrite") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Overwrite) :*: S1 ('MetaSel ('Just "targetName") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TargetName)))
Show CopyDirConfig Source #

Since: 0.1

Instance details

Defined in Effects.FileSystem.PathWriter

NFData CopyDirConfig Source #

Since: 0.1

Instance details

Defined in Effects.FileSystem.PathWriter

Methods

rnf :: CopyDirConfig -> () #

Eq CopyDirConfig Source #

Since: 0.1

Instance details

Defined in Effects.FileSystem.PathWriter

(k ~ A_Lens, a ~ Overwrite, b ~ Overwrite) => LabelOptic "overwrite" k CopyDirConfig CopyDirConfig a b Source #

Since: 0.1

Instance details

Defined in Effects.FileSystem.PathWriter

(k ~ A_Lens, a ~ TargetName, b ~ TargetName) => LabelOptic "targetName" k CopyDirConfig CopyDirConfig a b Source #

Since: 0.1

Instance details

Defined in Effects.FileSystem.PathWriter

type Rep CopyDirConfig Source #

Since: 0.1

Instance details

Defined in Effects.FileSystem.PathWriter

type Rep CopyDirConfig = D1 ('MetaData "CopyDirConfig" "Effects.FileSystem.PathWriter" "effects-fs-0.1-inplace" 'False) (C1 ('MetaCons "MkCopyDirConfig" 'PrefixI 'True) (S1 ('MetaSel ('Just "overwrite") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Overwrite) :*: S1 ('MetaSel ('Just "targetName") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TargetName)))

data Overwrite Source #

Determines file/directory overwrite behavior.

Since: 0.1

Constructors

OverwriteNone

No overwriting allowed.

Since: 0.1

OverwriteDirectories

Allow overwriting directories.

Since: 0.1

OverwriteAll

Allow overwriting the target directory and all subpaths.

Since: 0.1

Instances

Instances details
Generic Overwrite Source # 
Instance details

Defined in Effects.FileSystem.PathWriter

Associated Types

type Rep Overwrite

Since: effects-fs-0.1

Instance details

Defined in Effects.FileSystem.PathWriter

type Rep Overwrite = D1 ('MetaData "Overwrite" "Effects.FileSystem.PathWriter" "effects-fs-0.1-inplace" 'False) (C1 ('MetaCons "OverwriteNone" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "OverwriteDirectories" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "OverwriteAll" 'PrefixI 'False) (U1 :: Type -> Type)))
Show Overwrite Source #

Since: 0.1

Instance details

Defined in Effects.FileSystem.PathWriter

NFData Overwrite Source #

Since: 0.1

Instance details

Defined in Effects.FileSystem.PathWriter

Methods

rnf :: Overwrite -> () #

Eq Overwrite Source #

Since: 0.1

Instance details

Defined in Effects.FileSystem.PathWriter

type Rep Overwrite Source #

Since: 0.1

Instance details

Defined in Effects.FileSystem.PathWriter

type Rep Overwrite = D1 ('MetaData "Overwrite" "Effects.FileSystem.PathWriter" "effects-fs-0.1-inplace" 'False) (C1 ('MetaCons "OverwriteNone" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "OverwriteDirectories" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "OverwriteAll" 'PrefixI 'False) (U1 :: Type -> Type)))

data TargetName Source #

Determines how to name the target.

Since: 0.1

Constructors

TargetNameSrc

Uses the src dir as the dest name i.e. dest/<src>.

Since: 0.1

TargetNameLiteral !OsPath

Uses the given literal as the dest name i.e. dest/<targetName>.

Since: 0.1

TargetNameDest

Uses dest itself as the target i.e. dest/ (top-level copy).

Since: 0.1

Instances

Instances details
Generic TargetName Source # 
Instance details

Defined in Effects.FileSystem.PathWriter

Associated Types

type Rep TargetName

Since: effects-fs-0.1

Instance details

Defined in Effects.FileSystem.PathWriter

type Rep TargetName = D1 ('MetaData "TargetName" "Effects.FileSystem.PathWriter" "effects-fs-0.1-inplace" 'False) (C1 ('MetaCons "TargetNameSrc" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "TargetNameLiteral" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 OsPath)) :+: C1 ('MetaCons "TargetNameDest" 'PrefixI 'False) (U1 :: Type -> Type)))
Show TargetName Source #

Since: 0.1

Instance details

Defined in Effects.FileSystem.PathWriter

NFData TargetName Source #

Since: 0.1

Instance details

Defined in Effects.FileSystem.PathWriter

Methods

rnf :: TargetName -> () #

Eq TargetName Source #

Since: 0.1

Instance details

Defined in Effects.FileSystem.PathWriter

type Rep TargetName Source #

Since: 0.1

Instance details

Defined in Effects.FileSystem.PathWriter

type Rep TargetName = D1 ('MetaData "TargetName" "Effects.FileSystem.PathWriter" "effects-fs-0.1-inplace" 'False) (C1 ('MetaCons "TargetNameSrc" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "TargetNameLiteral" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 OsPath)) :+: C1 ('MetaCons "TargetNameDest" 'PrefixI 'False) (U1 :: Type -> Type)))

defaultCopyDirConfig :: CopyDirConfig Source #

Default config for copying directories.

>>> defaultCopyDirConfig
MkCopyDirConfig {overwrite = OverwriteNone, destName = TargetNameSrc}

Since: 0.1

Functions

copyDirectoryRecursiveConfig Source #

Arguments

:: (HasCallStack, MonadIORef m, MonadMask m, MonadPathReader m, MonadPathWriter m) 
=> CopyDirConfig

Config

-> OsPath

Source

-> OsPath

Destination

-> m () 

copyDirectoryRecursiveConfig cfg src dest copies the src and its contents into dest e.g.

copyDirectoryRecursiveConfig cfg "path/to/foo" "path/to/bar"

will create path/to/bar/foo, path/to/bar/<target>, or copy foo's contents directly into bar, depending on the value of targetName.

The atomicity semantics are as follows:

  • OverwriteNone: If an error is encountered, we roll back the successful writes by deleting the entire dest/<target>.
  • OverwriteDirectories: If an error is encountered, we attempt to delete all successfully written paths/directories. Because these deletes are performed sequentially, we cannot guarantee all are removed before the process is interrupted.
  • OverwriteAll: Same as OverwriteDirectories, except paths that were overwritten are not restored. That is, if a path dest/<src>/p is overwritten and an error later encountered, p is not restored.

Throws:

Since: 0.1

copySymbolicLink Source #

Arguments

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

Source

-> OsPath

Dest

-> m () 

Copies the symbolic link without traversing the link i.e. copy the link itself. Does not throw an exception if the target does exist. Throws an IOException if the path is not a symbolic link.

Windows: We have to distinguish between file and directory links (Posix makes no such distinction). If the target does not exist or is not considered a directory (e.g. it could also be a link), we fall back to creating a file link.

Since: 0.1

Optics

Removing

The removeXIfExists functions should be understood as helper combinators for the obvious doesXExist -> removeX pattern. They should not be understood as a total "delete arbitrary path if it exists" pattern.

For instance, doesDirectoryExist will return true if the target of a symbolic link is a directory, yet removeDirectory will throw an exception. Thus these functions should only be used when the type (file, dir, symlink) of a (possibly non-extant) path is known.

removeFileIfExists Source #

Arguments

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

.

-> m Bool 

Calls removeFile if doesFileExist is True. Returns true iff the path is deleted.

Since: 0.1

removeFileIfExists_ Source #

Arguments

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

.

-> m () 

Variant of removeFileIfExists that ignores the return value.

Since: 0.1

removeDirectoryIfExists Source #

Arguments

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

.

-> m Bool 

Calls removeDirectory if doesDirectoryExist is True. Returns true iff the path is deleted.

Since: 0.1

removeDirectoryIfExists_ Source #

Arguments

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

.

-> m () 

Variant of removeDirectoryIfExists that ignores the return value.

Since: 0.1

removeDirectoryRecursiveIfExists Source #

Arguments

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

.

-> m Bool 

Calls removeDirectoryRecursive if doesDirectoryExist is True. Returns true iff the path is deleted.

Since: 0.1

removeDirectoryRecursiveIfExists_ Source #

Arguments

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

.

-> m () 

Variant of removeDirectoryRecursiveIfExists that ignores the return value.

Since: 0.1

removePathForciblyIfExists Source #

Arguments

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

.

-> m Bool 

Calls removePathForcibly if doesPathExist is True. Returns true iff the path is deleted.

Since: 0.1

removePathForciblyIfExists_ Source #

Arguments

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

.

-> m () 

Variant of removePathForciblyIfExists that ignores the return value.

Since: 0.1

Symbolic Links

removeSymbolicLink Source #

Arguments

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

.

-> m () 

Removes a symbolic link. On Windows, attempts to distinguish file and directory links (Posix makes no distinction).

Since: 0.1

removeSymbolicLinkIfExists Source #

Calls removeSymbolicLink if doesSymbolicLinkExist is True. Returns true iff the path is deleted.

Since: 0.1

removeSymbolicLinkIfExists_ Source #

Arguments

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

.

-> m () 

Variant of removeSymbolicLinkIfExists that ignores the return value.

Since: 0.1

Reexports

data IOException #

Exceptions that occur in the IO monad. An IOException records a more specific error type, a descriptive string and maybe the handle that was used when the error was flagged.

Instances

Instances details
Exception IOException

Since: base-4.1.0.0

Instance details

Defined in GHC.IO.Exception

Show IOException

Since: base-4.1.0.0

Instance details

Defined in GHC.IO.Exception

Eq IOException

Since: base-4.1.0.0

Instance details

Defined in GHC.IO.Exception

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