darcs-2.18.5: a distributed, interactive, smart revision control system

Safe Haskell | None
Language | Haskell2010

Darcs.Util.Tree.Monad

Contents

- `TreeMonad`
- Specializing to `IO`
- Read actions
- Write actions
- Other actions

Description

A monad transformer for `Tree` mutation. The main idea is to simulate IO-ish manipulation of real filesystem (that's the state part of the monad), and to keep memory usage down by reasonably often dumping the intermediate data to disk and forgetting it.

The implementation is configured by passing a procedure of type `DumpItem` to `runTreeMonad`.

This module provides the pre-configured `virtualTreeIO` that never writes any changes, but may trigger filesystem reads as appropriate.

Synopsis

- type TreeMonad (m :: Type -> Type) = RWST (DumpItem m) () (TreeState m) m
- data TreeState (m :: Type -> Type)
- runTreeMonad :: Monad m => TreeMonad m a -> Tree m -> DumpItem m -> m (a, Tree m)
- virtualTreeMonad :: Monad m => TreeMonad m a -> Tree m -> m (a, Tree m)
- type TreeIO = TreeMonad IO
- virtualTreeIO :: TreeIO a -> Tree IO -> IO (a, Tree IO)
- readFile :: MonadThrow m => AnchoredPath -> TreeMonad m ByteString
- exists :: MonadThrow m => AnchoredPath -> TreeMonad m Bool
- directoryExists :: Monad m => AnchoredPath -> TreeMonad m Bool
- fileExists :: Monad m => AnchoredPath -> TreeMonad m Bool
- writeFile :: MonadThrow m => AnchoredPath -> ByteString -> TreeMonad m ()
- createDirectory :: Monad m => AnchoredPath -> TreeMonad m ()
- unlink :: Monad m => AnchoredPath -> TreeMonad m ()
- rename :: MonadThrow m => AnchoredPath -> AnchoredPath -> TreeMonad m ()
- copy :: MonadThrow m => AnchoredPath -> AnchoredPath -> TreeMonad m ()
- findM :: Monad m => Tree m -> AnchoredPath -> m (Maybe (TreeItem m))
- findFileM :: Monad m => Tree m -> AnchoredPath -> m (Maybe (Blob m))
- findTreeM :: Monad m => Tree m -> AnchoredPath -> m (Maybe (Tree m))

# `TreeMonad`

type TreeMonad (m :: Type -> Type) = RWST (DumpItem m) () (TreeState m) m #

A monad transformer that adds state of type `TreeState` and an environment of type `DumpItem`.

data TreeState (m :: Type -> Type) #

Internal state of the `TreeMonad`. Keeps track of the current `Tree` content and unsync'd changes.

#### Instances

Instances details

MonadThrow m => ApplyMonad Tree (TreeMonad m) # |
Instance details Defined in Darcs.Patch.ApplyMonad Methods readFilePS :: ObjectIdOf Tree -> TreeMonad m ByteString #
MonadThrow m => ApplyMonadTree (TreeMonad m) # |
Instance details Defined in Darcs.Patch.ApplyMonad Methods mDoesDirectoryExist :: AnchoredPath -> TreeMonad m Bool # mDoesFileExist :: AnchoredPath -> TreeMonad m Bool # mReadFilePS :: AnchoredPath -> TreeMonad m ByteString # mCreateDirectory :: AnchoredPath -> TreeMonad m () # mRemoveDirectory :: AnchoredPath -> TreeMonad m () # mCreateFile :: AnchoredPath -> TreeMonad m () # mRemoveFile :: AnchoredPath -> TreeMonad m () # mRename :: AnchoredPath -> AnchoredPath -> TreeMonad m () # mModifyFilePS :: AnchoredPath -> (ByteString -> TreeMonad m ByteString) -> TreeMonad m () # mChangePref :: String -> String -> String -> TreeMonad m () #

runTreeMonad :: Monad m => TreeMonad m a -> Tree m -> DumpItem m -> m (a, Tree m) #

virtualTreeMonad :: Monad m => TreeMonad m a -> Tree m -> m (a, Tree m) #

Run a `TreeMonad` action without storing any changes. This is useful for running monadic tree mutations for obtaining the resulting `Tree` (as opposed to their effect of writing a modified tree to disk). The actions can do both read and write -- reads are passed through to the actual filesystem, but the writes are held in memory in the form of a modified `Tree`.

# Specializing to `IO`

type TreeIO = TreeMonad IO #

`TreeMonad` specialized to `IO`

virtualTreeIO :: TreeIO a -> Tree IO -> IO (a, Tree IO) #

`virtualTreeMonad` specialized to `IO`

# Read actions

readFile :: MonadThrow m => AnchoredPath -> TreeMonad m ByteString #

Grab content of a file in the current Tree at the given path.

exists :: MonadThrow m => AnchoredPath -> TreeMonad m Bool #

Check for existence of a node (file or directory, doesn't matter).

directoryExists :: Monad m => AnchoredPath -> TreeMonad m Bool #

Check for existence of a directory.

fileExists :: Monad m => AnchoredPath -> TreeMonad m Bool #

Check for existence of a file.

# Write actions

writeFile :: MonadThrow m => AnchoredPath -> ByteString -> TreeMonad m () #

Change content of a file at a given path. The change will be eventually flushed to disk, but might be buffered for some time.

createDirectory :: Monad m => AnchoredPath -> TreeMonad m () #

Create a directory.

unlink :: Monad m => AnchoredPath -> TreeMonad m () #

Remove the item at a path.

rename :: MonadThrow m => AnchoredPath -> AnchoredPath -> TreeMonad m () #

Rename the item at a path.

copy :: MonadThrow m => AnchoredPath -> AnchoredPath -> TreeMonad m () #

Copy an item from some path to another path. Doing this with a SubTree is weird... it means copy recursively, but with lazy copy-on-write semantics. What happens when we flush that? Seems to work, though, as it is used in Darcs.UI.Commands.Convert.Import

# Other actions

findM :: Monad m => Tree m -> AnchoredPath -> m (Maybe (TreeItem m)) #

findFileM :: Monad m => Tree m -> AnchoredPath -> m (Maybe (Blob m)) #

findTreeM :: Monad m => Tree m -> AnchoredPath -> m (Maybe (Tree m)) #