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

Copyright© 2016–2017 Mark Karpov
LicenseBSD 3 clause
MaintainerMark Karpov <markkarpov92@gmail.com>
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 into 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 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.

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

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

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 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 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 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.