plan-b-0.1.1: Failure-tolerant file and directory editing

Copyright© 2016 Mark Karpov
LicenseBSD 3 clause
MaintainerMark Karpov <markkarpov@openmailbox.org>
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

System.PlanB

Contents

Description

Failure-tolerant file and directory editing. All functions here can recover from exceptions thrown while they work. They bring file-system to the state it was in before specific function was called. Temporary files and backups are handled automatically.

Synopsis

Operations on files

withNewFile Source #

Arguments

:: (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 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 given file name.

This action throws alreadyExistsErrorType by default instead of silently overwriting already existing file, use overrideIfExists and useIfExists to change this behavior.

withExistingFile Source #

Arguments

:: (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 existing file. Name of the file is taken as the second argument. The third argument allows to perform actions on temporary copy of specified file.

This action throws doesNotExistErrorType exception if target file does not exist.

Operations on directories

withNewDir Source #

Arguments

:: (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 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 useIfExiststo change this behavior.

withExistingDir Source #

Arguments

:: (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 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

withNewContainer Source #

Arguments

:: (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 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 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 useIfExiststo change this behavior.

withExistingContainer Source #

Arguments

:: (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 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 #

Specifies name of temporary directory to use. Default is the system temporary directory. If the directory does not exist, it will be created, but not deleted.

nameTemplate :: HasTemp c => String -> c Source #

Specify template 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).

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.