@hackage plan-b0.1.1
Failure-tolerant file and directory editing
Categories
License
BSD-3-Clause
Maintainer
Mark Karpov <markkarpov@opmbx.org>
Links
Versions
Deprecated
Dependencies (5)
- base >=4.7 && <4.11
- exceptions >=0.8
- path >=0.5
- path-io >=1.0.1
- transformers >=0.3 Show all…
Dependents (2)
@hackage/acme-everything, @hackage/zip
Package Flags
dev
(off by default)
Turn on development settings.
Plan B
This is a Haskell library helping perform failure-tolerant operations on files and directories.
Quick start
The library allows to create and/or edit files, directories, and containers. By “container” we mean archive-like object that can contain representation of a directory inside it. Consequently, we have six functions available:
withNewFilewithExstingFilewithNewDirwithExistingDirwithNewContainerwithExistingContainer
You specify name of object to edit or create, options (more on them below),
and action that is passed Path argument with the same type as object you
intend to edit (we use type-safe file paths from
path package here to prevent a
certain class of potential bugs). Then, having that path, you can do all
actions you want to and if at some point during this editing an exception is
thrown, state of file system is rolled back — you get no corrupted files,
half-way edited directories, everything is intact as if nothing happened at
all. If, however, the action is executed successfully (i.e. no exceptions
thrown), all your manipulations are reflected in the file system.
This is a lightweight solution that makes it harder to corrupt sensitive information. And since file system exists in the real world, all sorts of bad things can (and will) happen. You should always have plan B.
Temporary files and back-ups are handled and deleted automatically, however you can pass options to change default behaviors. Not all options can be used with every function, but wrong combinations won't type-check, so it's OK.
Collection of options is a monoid. mempty corresponds to default behavior,
while non-standard behavioral deviations can be mappended to it.
By default, when we want to create new object and it already exists, we get an exception, two alternative options exist (only work when you create new object):
overrideIfExistuseIfExist
There is no way to prevent exception when you want to edit object that does not exist, though.
All functions make use of temporary directories. You can control certain aspects of this business:
-
tempDir dir— will tell the library to create temporary directories and files insidedir. By default system's standard temporary directory (e.g./tmp/on Unix-like systems) is used. -
nameTemplate template— specifies template to use for generation of unique file and directory names. By default"plan-b"is used. -
preserveCorpse— if you add this to options, in case of failure (exception), temporary directory is not automatically deleted and can be inspected. However, if operation succeeds, temporary directory is always deleted.
That should be enough for a quick intro, for more information regarding concrete functions, consult Haddocks.
License
Copyright © 2016 Mark Karpov
Distributed under BSD 3 clause license.