hashed-storage-0.5.9: Hashed file storage support code.




The index is a binary file that overlays a hashed tree over the working copy. This means that every working file and directory has an entry in the index, that contains its path and hash and validity data. The validity data is a timestamp plus the file size. The file hashes are sha256's of the file's content.

There are two entry types, a file entry and a directory entry. Both have a common binary format (see Item). The on-disk format is best described by the section Index format below.



Index format

The Index is organised into "lines" where each line describes a single indexed item. Cf. Item.

The first word on the index "line" is the length of the file path (which is the only variable-length part of the line). Then comes the path itself, then fixed-length hash (sha256) of the file in question, then two words, one for size and one aux, which is used differently for directories and for files.

With directories, this aux holds the offset of the next sibling line in the index, so we can efficiently skip reading the whole subtree starting at a given directory (by just seeking aux bytes forward). The lines are pre-ordered with respect to directory structure -- the directory comes first and after it come all its items. Cf. readIndex'.

For files, the aux field holds a timestamp.



readIndex :: FilePath -> (Tree IO -> Hash) -> IO IndexSource

Read an index and build up a Tree object from it, referring to current working directory. The initial Index object returned by readIndex is not directly useful. However, you can use Tree.filter on it. Either way, to obtain the actual Tree object, call update.

The usual use pattern is this:

 do (idx, update) <- readIndex
    tree <- update =<< filter predicate idx

The resulting tree will be fully expanded.

updateIndexFrom :: FilePath -> (Tree IO -> Hash) -> Tree IO -> IO IndexSource


indexFormatValid :: FilePath -> IO BoolSource


type Index = IndexM IOSource

filter :: FilterTree a m => (AnchoredPath -> TreeItem m -> Bool) -> a m -> a mSource

Given pred tree, produce a Tree that only has items for which pred returns True. The tree might contain stubs. When expanded, these will be subject to filtering as well.