Skip to content
Snippets Groups Projects
Commit 10978a9e authored by Jean-Paul Calderone's avatar Jean-Paul Calderone
Browse files

the actual directory downloading function (used by list-dircap example app)

parent 2afdd41b
No related branches found
No related tags found
1 merge request!8Add `downloadDirectory` function!
...@@ -229,3 +229,29 @@ downloadShare storageIndex (shareNum, s) = do ...@@ -229,3 +229,29 @@ downloadShare storageIndex (shareNum, s) = do
let massaged = first (ShareDownloadError . (displayException :: SomeException -> String)) shareBytes let massaged = first (ShareDownloadError . (displayException :: SomeException -> String)) shareBytes
print' "Downloaded it" print' "Downloaded it"
pure (shareNum, LB.fromStrict <$> massaged) pure (shareNum, LB.fromStrict <$> massaged)
{- | Download the data associated with a directory capability and interpret it
as a collection of entries.
-}
downloadDirectory ::
(MonadIO m, Readable readCap, Verifiable v, Verifier readCap ~ v) =>
-- | Information about the servers from which to consider downloading shares
-- representing the application data.
Map.Map StorageServerID StorageServerAnnouncement ->
-- | The read capability for the application data.
DirectoryCapability readCap ->
-- | Get functions for interacting with a server given its URL.
LookupServer m ->
-- | Either a description of how the recovery failed or the recovered
-- application data.
m (Either DirectoryDownloadError Directory)
downloadDirectory anns (DirectoryCapability cap) lookupServer = do
bs <- download anns cap lookupServer
pure $ do
bs' <- first UnderlyingDownloadError bs
first (const DecodingError) $ Directory.parse (LB.toStrict bs')
data DirectoryDownloadError
= UnderlyingDownloadError DownloadError
| DecodingError
deriving (Ord, Eq, Show)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment