Copyright | © 2016–2017 Mark Karpov |
---|---|
License | BSD 3 clause |
Maintainer | Mark Karpov <markkarpov92@gmail.com> |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Failure-tolerant file and directory editing. All functions here can recover from exceptions thrown while they work. They bring file-system into the state it was in before specific function was called. Temporary files and backups are handled automatically.
- withNewFile :: (MonadIO m, MonadMask m) => PbConfig New -> Path b File -> (Path Abs File -> m a) -> m a
- withExistingFile :: (MonadIO m, MonadMask m) => PbConfig Existing -> Path b File -> (Path Abs File -> m a) -> m a
- withNewDir :: (MonadIO m, MonadMask m) => PbConfig New -> Path b Dir -> (Path Abs Dir -> m a) -> m a
- withExistingDir :: (MonadIO m, MonadMask m) => PbConfig Existing -> Path b Dir -> (Path Abs Dir -> m a) -> m a
- withNewContainer :: (MonadIO m, MonadMask m) => (Path Abs File -> Path Abs Dir -> m ()) -> (Path Abs Dir -> Path b File -> m ()) -> PbConfig New -> Path b File -> (Path Abs Dir -> m a) -> m a
- withExistingContainer :: (MonadIO m, MonadMask m) => (Path b File -> Path Abs Dir -> m ()) -> (Path Abs Dir -> Path b File -> m ()) -> PbConfig Existing -> Path b File -> (Path Abs Dir -> m a) -> m a
- tempDir :: HasTemp c => Path Abs Dir -> c
- nameTemplate :: HasTemp c => String -> c
- preserveCorpse :: HasTemp c => c
- moveByRenaming :: HasTemp c => c
- overrideIfExists :: CanHandleExisting c => c
- useIfExists :: CanHandleExisting c => c
Operations on files
:: (MonadIO m, MonadMask m) | |
=> PbConfig New | Configuration |
-> Path b File | Name of file to create |
-> (Path Abs File -> m a) | Given name of temporary file, do it |
-> m a |
Create a new file. Name of the file is taken as the second argument. The third argument allows to perform actions (in simplest case just creation of file), result of those actions should be new file with the given file name.
This action throws alreadyExistsErrorType
by default instead of
silently overwriting already existing file, use overrideIfExists
and
useIfExists
to change this behavior.
:: (MonadIO m, MonadMask m) | |
=> PbConfig Existing | Configuration |
-> Path b File | Name of file to edit |
-> (Path Abs File -> m a) | Given name of temporary file, do it |
-> m a |
Edit an existing file. Name of the file is taken as the second argument. The third argument allows to perform actions on temporary copy of the specified file.
This action throws doesNotExistErrorType
exception if target file does
not exist.
Operations on directories
:: (MonadIO m, MonadMask m) | |
=> PbConfig New | Configuration |
-> Path b Dir | Name of directory to create |
-> (Path Abs Dir -> m a) | Given name of temporary directory, do it |
-> m a |
Create a new directory. Name of the directory is specified as the second argument. The third argument allows to perform actions in “sandboxed” version of new directory.
This action throws alreadyExistsErrorType
by default instead of
silently overwriting already existing directory, use overrideIfExists
and useIfExists
to change this behavior.
:: (MonadIO m, MonadMask m) | |
=> PbConfig Existing | Configuration |
-> Path b Dir | Name of directory to edit |
-> (Path Abs Dir -> m a) | Given name of temporary directory, do it |
-> m a |
Edit an existing directory. Name of the directory is specified as the second argument. The third argument allows to perform actions in “sandboxed” copy of target directory.
This action throws doesNotExistErrorType
exception if target directory
does not exist.
Operations on containers
:: (MonadIO m, MonadMask m) | |
=> (Path Abs File -> Path Abs Dir -> m ()) | How to unpack file into specified directory |
-> (Path Abs Dir -> Path b File -> m ()) | How to pack specified directory into file |
-> PbConfig New | Configuration |
-> Path b File | Name of container to create |
-> (Path Abs Dir -> m a) | Given name of temporary directory, do it |
-> m a |
Create a new container file. This is suitable for processing of all sorts of archive-like objects. The first and second arguments specify how to unpack directory from file and pack it back. The fourth argument names the new file. The fifth argument allows to perform actions knowing name of temporary directory.
This action throws alreadyExistsErrorType
by default instead of
silently overwriting already existing file, use overrideIfExists
and
useIfExists
to change this behavior.
withExistingContainer Source #
:: (MonadIO m, MonadMask m) | |
=> (Path b File -> Path Abs Dir -> m ()) | How to unpack file into specified directory |
-> (Path Abs Dir -> Path b File -> m ()) | How to pack specified directory into file |
-> PbConfig Existing | Configuration |
-> Path b File | Name of container to edit |
-> (Path Abs Dir -> m a) | Given name of temporary directory, do it |
-> m a |
Edit an existing container file. This is suitable for processing of all sorts of archive-like objects. The first and second arguments specify how to unpack directory from file and pack it back (overwriting old version). Fourth argument names container file to edit. The last argument allows to perform actions knowing name of temporary directory.
This action throws doesNotExistErrorType
exception if target file does
not exist.
Configuration options
tempDir :: HasTemp c => Path Abs Dir -> c Source #
Specify name of temporary directory to use. The default is the system temporary directory. If the directory does not exist, it will be created, but won't be deleted.
nameTemplate :: HasTemp c => String -> c Source #
Specify the template string to use to name temporary directory, see
openTempFile
, default is "plan-b"
.
preserveCorpse :: HasTemp c => c Source #
preserveCorpse
preserves temporary files and directories when
exception is thrown (normally they are removed).
moveByRenaming :: HasTemp c => c Source #
By default files are moved by copying. Moving by renaming, although not always possible, often more efficient. This option enables it.
overrideIfExists :: CanHandleExisting c => c Source #
The option allows to avoid throwing exception if upon completion of specified action file with given name already exists in the file system.
useIfExists :: CanHandleExisting c => c Source #
The option will copy already existing file into temporary location, so you can edit it instead of creating new file.