Copyright | (c) 2017 Red Hat Inc. |
---|---|
License | LGPL |
Maintainer | https://github.com/weldr |
Stability | alpha |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Create content stores, put objects into them, and retrieve objects from them.
- data ContentStore
- data CsError
- data CsMonad a
- runCsMonad :: CsMonad a -> IO (Either CsError a)
- contentStoreDigest :: ContentStore -> DigestAlgorithm
- contentStoreValid :: (MonadError CsError m, MonadIO m) => FilePath -> m Bool
- fetchByteString :: (MonadBaseControl IO m, MonadError CsError m, MonadIO m, MonadThrow m) => ContentStore -> ObjectDigest -> m ByteString
- fetchByteStringC :: (MonadError CsError m, MonadResource m) => ContentStore -> Conduit ObjectDigest m ByteString
- fetchFile :: (MonadBaseControl IO m, MonadError CsError m, MonadResource m) => ContentStore -> ObjectDigest -> FilePath -> m ()
- fetchLazyByteString :: (MonadBaseControl IO m, MonadError CsError m, MonadIO m, MonadThrow m) => ContentStore -> ObjectDigest -> m ByteString
- fetchLazyByteStringC :: (MonadError CsError m, MonadResource m) => ContentStore -> Conduit ObjectDigest m ByteString
- mkContentStore :: (MonadError CsError m, MonadIO m) => FilePath -> m ContentStore
- openContentStore :: (MonadError CsError m, MonadIO m) => FilePath -> m ContentStore
- storeByteString :: (MonadBaseControl IO m, MonadError CsError m, MonadIO m, MonadThrow m) => ContentStore -> ByteString -> m ObjectDigest
- storeByteStringC :: (MonadError CsError m, MonadResource m) => ContentStore -> Conduit ByteString m ObjectDigest
- storeByteStringSink :: MonadResource m => ContentStore -> Sink ByteString m ObjectDigest
- storeDirectory :: (MonadBaseControl IO m, MonadError CsError m, MonadResource m) => ContentStore -> FilePath -> m [(FilePath, ObjectDigest)]
- storeFile :: (MonadBaseControl IO m, MonadError CsError m, MonadResource m) => ContentStore -> FilePath -> m ObjectDigest
- storeLazyByteString :: (MonadBaseControl IO m, MonadError CsError m, MonadIO m, MonadThrow m) => ContentStore -> ByteString -> m ObjectDigest
- storeLazyByteStringC :: (MonadError CsError m, MonadResource m) => ContentStore -> Conduit ByteString m ObjectDigest
- storeLazyByteStringSink :: MonadResource m => ContentStore -> Sink ByteString m ObjectDigest
Documentation
data ContentStore Source #
The ContentStore is an opaque type that contains various pieces of information
used to describe an on-disk content store. Values of this type are constructed
via mkContentStore
and openContentStore
, depending on which operation you
need to perform. Users should not need to concern themselves with the internals
of this type.
A type to represent various errors that can occur during content store operations.
CsError String | Miscellaneous, uncategorized errors. The string is the exact error message. |
CsErrorCollision String | An object with this digest already exists in the content store. This error is not typically raised during write operations, because attempting to write the same thing twice is not really an error. |
CsErrorConfig String | A parse error occurred reading the content store's internal config file. This generally represents either a programming error or that someone has been modifying the internals. The string contains the error message. |
CsErrorInvalid String | The content store directory is invalid. This usually occurs because some file or directory is missing. The string is the name of what is missing. |
CsErrorMissing | The content store does not exist. |
CsErrorNoSuchObject String | The requested object does not exist in the content store. The string contains the object digest requested. |
CsErrorUnsupportedHash String | The hashing algorithm is not supported by the content store. Not all possible algorithms are supported. The string contains the name of the algorithm requested. |
Working with a ContentStore
requires a lot of behind-the-scenes management of
ResourceT
, ExceptT
, and IO
. Along with runCsMonad
, this provides a type
and function for doing much of that management for you. These two can be used like
so:
result <- runCsMonad $ do cs <- mkContentStore "/tmp/cs.repo" storeDirectory cs "/tmp/test-data" case result of Left e -> print e Right d -> do putStrLn "Stored objects: " mapM_ print d
Most functions in this module do not explicitly require use of CsMonad
, but any
that have a return type including m
can be run inside it.
contentStoreDigest :: ContentStore -> DigestAlgorithm Source #
Return the digest type used by a content store.
contentStoreValid :: (MonadError CsError m, MonadIO m) => FilePath -> m Bool Source #
Check that a content store exists and contains everything it's supposed to. This does
not check the validity of all the contents, however. A CsError
will be thrown if there
are any problems. Otherwise, this function returns True.
:: (MonadBaseControl IO m, MonadError CsError m, MonadIO m, MonadThrow m) | |
=> ContentStore | An opened |
-> ObjectDigest | The |
-> m ByteString |
Lookup and return some previously stored object as a strict ByteString
. Note that
you'll probably need to use fromByteString
to produce an ObjectDigest
from whatever
text or binary representation you've got from the usermddbetc.
fetchByteStringC :: (MonadError CsError m, MonadResource m) => ContentStore -> Conduit ObjectDigest m ByteString Source #
Given an opened ContentStore
and a Conduit
of ObjectDigest
s, load each one into
a strict ByteString
and put it into the conduit. This is useful for stream many
objects out of the content store at a time, like with exporting an RPM or other package
format.
:: (MonadBaseControl IO m, MonadError CsError m, MonadResource m) | |
=> ContentStore | An opened |
-> ObjectDigest | The |
-> FilePath | The destination |
-> m () |
Find some object in the content store and write it to a destination. If the destination already
exists, it will be overwritten. If the object does not already exist, a CsErrorNoSuchObject
will
be thrown.
fetchLazyByteString :: (MonadBaseControl IO m, MonadError CsError m, MonadIO m, MonadThrow m) => ContentStore -> ObjectDigest -> m ByteString Source #
Like fetchByteString
, but uses lazy ByteString
s instead.
fetchLazyByteStringC :: (MonadError CsError m, MonadResource m) => ContentStore -> Conduit ObjectDigest m ByteString Source #
Like fetchByteStringC
, but uses lazy ByteString
s instead.
mkContentStore :: (MonadError CsError m, MonadIO m) => FilePath -> m ContentStore Source #
Create a new ContentStore
on disk, rooted at the path given, and return it as if
openContentStore
had also been called. If a content store already exists at the
given root and is valid, return that as if openContentStore
had been called.
Various CsError
s could be thrown by this process.
openContentStore :: (MonadError CsError m, MonadIO m) => FilePath -> m ContentStore Source #
Return an already existing ContentStore
, after checking that it is valid.
Various CsError
s could be thrown by this process.
:: (MonadBaseControl IO m, MonadError CsError m, MonadIO m, MonadThrow m) | |
=> ContentStore | An opened |
-> ByteString | An object to be stored, as a strict |
-> m ObjectDigest |
Store some object into the content store and return its ObjectDigest
. If an object
with the same digest already exists in the content store, this is a duplicate. Simply
return the digest of the already stored object and do nothing else. A CsErrorCollision
will NOT be thrown.
storeByteStringC :: (MonadError CsError m, MonadResource m) => ContentStore -> Conduit ByteString m ObjectDigest Source #
Like storeByteString
, but read strict ByteString
s from a Conduit
and put their
ObjectDigest
s into the conduit. This is useful for storing many objects at a time,
like with importing an RPM or other package format.
storeByteStringSink :: MonadResource m => ContentStore -> Sink ByteString m ObjectDigest Source #
Read in a Conduit
of strict ByteString
s, store the stream into an object in an
already opened ContentStore
, and return the final digest. This is useful for
storing a stream of data as a single object.
:: (MonadBaseControl IO m, MonadError CsError m, MonadResource m) | |
=> ContentStore | An opened |
-> FilePath | A directory tree containing many objects. |
-> m [(FilePath, ObjectDigest)] |
Store all objects in a directory tree in the content store, returning the name and ObjectDigest
of each. Note that directories will not be stored. The content store only contains things that
have content. If you need to store directory information, that should be handled externally to
this module.
:: (MonadBaseControl IO m, MonadError CsError m, MonadResource m) | |
=> ContentStore | An opened |
-> FilePath | The file to be stored. |
-> m ObjectDigest |
Store an already existing file in the content store, returning its ObjectDigest
. The original
file will be left on disk.
storeLazyByteString :: (MonadBaseControl IO m, MonadError CsError m, MonadIO m, MonadThrow m) => ContentStore -> ByteString -> m ObjectDigest Source #
Like storeByteString
, but uses lazy ByteString
s instead.
storeLazyByteStringC :: (MonadError CsError m, MonadResource m) => ContentStore -> Conduit ByteString m ObjectDigest Source #
Like storeByteStringC
, but uses lazy ByteString
s instead.
storeLazyByteStringSink :: MonadResource m => ContentStore -> Sink ByteString m ObjectDigest Source #
Like storeByteStringSink
, but uses lazy ByteString
s instead.