plan-b: Failure-tolerant file and directory editing

[ bsd3, deprecated, filesystem, library, system ] [ Propose Tags ] [ Report a vulnerability ]
Deprecated

Failure-tolerant file and directory editing.


[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
dev

Turn on development settings.

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0, 0.1.1, 0.2.0, 0.2.1
Change log CHANGELOG.md
Dependencies base (>=4.7 && <5.0), exceptions (>=0.8 && <0.10), path (>=0.5 && <0.7), path-io (>=1.0.1 && <2.0), semigroups (>=0.18 && <0.19), transformers (>=0.3 && <0.6) [details]
Tested with ghc ==7.8.4, ghc ==7.10.3, ghc ==8.0.2, ghc ==8.2.1
License BSD-3-Clause
Author Mark Karpov <markkarpov92@gmail.com>
Maintainer Mark Karpov <markkarpov92@gmail.com>
Revised Revision 2 made by mrkkrp at 2018-02-27T17:17:26Z
Category System, Filesystem
Home page https://github.com/mrkkrp/plan-b
Bug tracker https://github.com/mrkkrp/plan-b/issues
Source repo head: git clone https://github.com/mrkkrp/plan-b.git
Uploaded by mrkkrp at 2017-05-23T11:28:00Z
Distributions
Reverse Dependencies 2 direct, 12 indirect [details]
Downloads 3300 total (12 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-05-23 [all 1 reports]

Readme for plan-b-0.2.1

[back to package description]

Plan B

License BSD3 Hackage Stackage Nightly Stackage LTS Build Status Coverage Status

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:

  • withNewFile
  • withExstingFile
  • withNewDir
  • withExistingDir
  • withNewContainer
  • withExistingContainer

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 from 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 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 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):

  • overrideIfExist
  • useIfExist

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

  • moveByRenaming—by default files and directories are moved by copying, this option enables moving by renaming. If you also specify tempDir that 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.

License

Copyright © 2016–2017 Mark Karpov

Distributed under BSD 3 clause license.