This is a Haskell library helping perform failure-tolerant operations on files and directories.
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:
You specify name of an object to edit or create, options (more on them
below), and an action that gets a
Path argument with the same type as
object you intend to edit (we use type-safe file paths
path package here to
prevent a certain class of potential bugs). Then, having that path, you can
perform 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
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 the default
behavior, while non-standard behavioral deviations can be
mappended to it.
By default, when we want to create a new object and it already exists, we get an exception, two alternative options exist (only work when you create a new object):
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—tells the library to create temporary directories and files inside
dir. 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
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.
moveByRenaming—by default files and directories are moved by copying, this option enables moving by renaming. If you also specify
tempDirthat is on the same disk/partition as the final file you're generating, this may speed up things considerably.
That should be enough for a quick intro, for more information regarding concrete functions, consult Haddocks.
Copyright © 2016–2017 Mark Karpov
Distributed under BSD 3 clause license.
Plan B 0.2.1
Semigroupinstance for the
Improved documentation and metadata.
Plan B 0.2.0
moveByRenamingoption to allow move files and directories by renaming. This is not default because moving by renaming is not always possible, while moving by coping is always an option.
Plan B 0.1.1
Fixed the problem with moving of files and directories from
/tmp/to some location not under
/tmp/resulting in “unsupported operation” exception on Unix. Now they are moved by copying.
Plan B 0.1.0
- Initial release.