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

Safe Haskell | None
Language | Haskell2010

Darcs.Util.Tree.Monad

Description

An experimental monadic interface to 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 monad interface itself is generic, and a number of actual implementations can be used. This module provides just `virtualTreeIO` that never writes any changes, but may trigger filesystem reads as appropriate.

Synopsis

- virtualTreeIO :: TreeIO a -> Tree IO -> IO (a, Tree IO)
- virtualTreeMonad :: (Functor m, Monad m) => TreeMonad m a -> Tree m -> m (a, Tree m)
- readFile :: TreeRO m => AnchoredPath -> m ByteString
- writeFile :: TreeRW m => AnchoredPath -> ByteString -> m ()
- createDirectory :: TreeRW m => AnchoredPath -> m ()
- rename :: TreeRW m => AnchoredPath -> AnchoredPath -> m ()
- copy :: TreeRW m => AnchoredPath -> AnchoredPath -> m ()
- unlink :: TreeRW m => AnchoredPath -> m ()
- fileExists :: TreeRO m => AnchoredPath -> m Bool
- directoryExists :: TreeRO m => AnchoredPath -> m Bool
- exists :: TreeRO m => AnchoredPath -> m Bool
- withDirectory :: TreeRO m => AnchoredPath -> m a -> m a
- currentDirectory :: TreeRO m => m AnchoredPath
- tree :: TreeState m -> Tree m
- data TreeState m
- type TreeMonad m = RWST AnchoredPath () (TreeState m) m
- type TreeIO = TreeMonad IO
- runTreeMonad :: (Functor m, Monad m) => TreeMonad m a -> TreeState m -> m (a, Tree m)
- initialState :: Tree m -> (TreeItem m -> m Hash) -> (AnchoredPath -> TreeItem m -> TreeMonad m (TreeItem m)) -> TreeState m
- replaceItem :: (Functor m, Monad m) => AnchoredPath -> Maybe (TreeItem m) -> TreeMonad m ()
- findM :: (Monad m, Functor m) => Tree m -> AnchoredPath -> m (Maybe (TreeItem m))
- findFileM :: (Monad m, Functor m) => Tree m -> AnchoredPath -> m (Maybe (Blob m))
- findTreeM :: (Monad m, Functor m) => Tree m -> AnchoredPath -> m (Maybe (Tree m))
- class (Functor m, Monad m) => TreeRO m where
- class TreeRO m => TreeRW m where

# Documentation

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

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

Run a TreeIO 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 a form of modified Tree.

readFile :: TreeRO m => AnchoredPath -> m ByteString #

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

writeFile :: TreeRW m => AnchoredPath -> ByteString -> 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 :: TreeRW m => AnchoredPath -> m () #

rename :: TreeRW m => AnchoredPath -> AnchoredPath -> m () #

copy :: TreeRW m => AnchoredPath -> AnchoredPath -> m () #

unlink :: TreeRW m => AnchoredPath -> m () #

fileExists :: TreeRO m => AnchoredPath -> m Bool #

Check for existence of a file.

directoryExists :: TreeRO m => AnchoredPath -> m Bool #

Check for existence of a directory.

exists :: TreeRO m => AnchoredPath -> m Bool #

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

withDirectory :: TreeRO m => AnchoredPath -> m a -> m a #

currentDirectory :: TreeRO m => m AnchoredPath #

tree :: TreeState m -> Tree m #

data TreeState m #

Internal state of the `TreeIO` monad. Keeps track of the current Tree content, unsync'd changes and a current working directory (of the monad).

Instances

(Functor m, Monad m) => ApplyMonad Tree (TreeMonad m) # |
Associated Types type ApplyMonadBase (TreeMonad m :: * -> *) :: * -> * # Methods nestedApply :: TreeMonad m x -> Tree (ApplyMonadBase (TreeMonad m)) -> TreeMonad m (x, Tree (ApplyMonadBase (TreeMonad m))) # liftApply :: (Tree (ApplyMonadBase (TreeMonad m)) -> ApplyMonadBase (TreeMonad m) x) -> Tree (ApplyMonadBase (TreeMonad m)) -> TreeMonad m (x, Tree (ApplyMonadBase (TreeMonad m))) # getApplyState :: TreeMonad m (Tree (ApplyMonadBase (TreeMonad m))) #
(Functor m, Monad m) => TreeRW (TreeMonad m) # |
Methods writeFile :: AnchoredPath -> ByteString -> TreeMonad m () # createDirectory :: AnchoredPath -> TreeMonad m () # unlink :: AnchoredPath -> TreeMonad m () # rename :: AnchoredPath -> AnchoredPath -> TreeMonad m () # copy :: AnchoredPath -> AnchoredPath -> TreeMonad m () #
(Functor m, Monad m) => TreeRO (TreeMonad m) # |
Methods currentDirectory :: TreeMonad m AnchoredPath # withDirectory :: AnchoredPath -> TreeMonad m a -> TreeMonad m a # expandTo :: AnchoredPath -> TreeMonad m AnchoredPath readFile :: AnchoredPath -> TreeMonad m ByteString # exists :: AnchoredPath -> TreeMonad m Bool # directoryExists :: AnchoredPath -> TreeMonad m Bool # fileExists :: AnchoredPath -> TreeMonad m Bool #
(Functor m, Monad m) => MonadProgress (TreeMonad m) # |
Methods runProgressActions :: String -> [ProgressAction (TreeMonad m) ()] -> TreeMonad m () #
(Functor m, Monad m) => ApplyMonadTree (TreeMonad m) # |
Methods mDoesDirectoryExist :: FileName -> TreeMonad m Bool # mDoesFileExist :: FileName -> TreeMonad m Bool # mReadFilePS :: FileName -> TreeMonad m ByteString # mReadFilePSs :: FileName -> TreeMonad m [ByteString] # mCreateDirectory :: FileName -> TreeMonad m () # mRemoveDirectory :: FileName -> TreeMonad m () # mCreateFile :: FileName -> TreeMonad m () # mRemoveFile :: FileName -> TreeMonad m () # mRename :: FileName -> FileName -> TreeMonad m () # mModifyFilePS :: FileName -> (ByteString -> TreeMonad m ByteString) -> TreeMonad m () # mModifyFilePSs :: FileName -> ([ByteString] -> TreeMonad m [ByteString]) -> TreeMonad m () # mChangePref :: String -> String -> String -> TreeMonad m () #
type ApplyMonadBase (TreeMonad m) # |
type ApplyMonadBase (TreeMonad m) = m

type TreeMonad m = RWST AnchoredPath () (TreeState m) m #

A `TreeIO` monad. A sort of like IO but it keeps a `TreeState` around as well, which is a sort of virtual filesystem. Depending on how you obtained your `TreeIO`, the actions in your virtual filesystem get somehow reflected in the actual real filesystem. For `virtualTreeIO`, nothing happens in real filesystem, however with `plainTreeIO`, the plain tree will be updated every now and then, and with `hashedTreeIO` a darcs-style hashed tree will get updated.

type TreeIO = TreeMonad IO #

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

initialState :: Tree m -> (TreeItem m -> m Hash) -> (AnchoredPath -> TreeItem m -> TreeMonad m (TreeItem m)) -> TreeState m #

replaceItem :: (Functor m, Monad m) => AnchoredPath -> Maybe (TreeItem m) -> TreeMonad m () #

Replace an item with a new version without modifying the content of the tree. This does not do any change tracking. Ought to be only used from a `sync` implementation for a particular storage format. The presumed use-case is that an existing in-memory Blob is replaced with a one referring to an on-disk file.

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

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

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

class (Functor m, Monad m) => TreeRO m where #

Minimal complete definition

currentDirectory, withDirectory, expandTo, readFile, exists, directoryExists, fileExists

Methods

currentDirectory :: m AnchoredPath #

withDirectory :: AnchoredPath -> m a -> m a #

readFile :: AnchoredPath -> m ByteString #

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

exists :: AnchoredPath -> m Bool #

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

directoryExists :: AnchoredPath -> m Bool #

Check for existence of a directory.

fileExists :: AnchoredPath -> m Bool #

Check for existence of a file.

Instances

(Functor m, Monad m) => TreeRO (TreeMonad m) # |
Methods currentDirectory :: TreeMonad m AnchoredPath # withDirectory :: AnchoredPath -> TreeMonad m a -> TreeMonad m a # expandTo :: AnchoredPath -> TreeMonad m AnchoredPath readFile :: AnchoredPath -> TreeMonad m ByteString # exists :: AnchoredPath -> TreeMonad m Bool # directoryExists :: AnchoredPath -> TreeMonad m Bool # fileExists :: AnchoredPath -> TreeMonad m Bool #

class TreeRO m => TreeRW m where #

Minimal complete definition

writeFile, createDirectory, unlink, rename, copy

Methods

writeFile :: AnchoredPath -> ByteString -> 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 :: AnchoredPath -> m () #

unlink :: AnchoredPath -> m () #

rename :: AnchoredPath -> AnchoredPath -> m () #

copy :: AnchoredPath -> AnchoredPath -> m () #

Instances

(Functor m, Monad m) => TreeRW (TreeMonad m) # |
Methods writeFile :: AnchoredPath -> ByteString -> TreeMonad m () # createDirectory :: AnchoredPath -> TreeMonad m () # unlink :: AnchoredPath -> TreeMonad m () # rename :: AnchoredPath -> AnchoredPath -> TreeMonad m () # copy :: AnchoredPath -> AnchoredPath -> TreeMonad m () #