summaryrefslogtreecommitdiff
path: root/Remote/External
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2014-12-11 15:32:42 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2014-12-11 15:33:42 -0400
commitc4ff79b1a460a3526c6772ab754cb34e5f7f3dd2 (patch)
tree80bea71f1d453348cb2d0a92ce10e463aab9259e /Remote/External
parent4e88f7e9af6a776347649047f2473e470a729ed9 (diff)
Expand checkurl to support recommended filename, and multi-file-urls
This commit was sponsored by an anonymous bitcoiner.
Diffstat (limited to 'Remote/External')
-rw-r--r--Remote/External/Types.hs25
1 files changed, 18 insertions, 7 deletions
diff --git a/Remote/External/Types.hs b/Remote/External/Types.hs
index b00352702..73177d316 100644
--- a/Remote/External/Types.hs
+++ b/Remote/External/Types.hs
@@ -137,8 +137,8 @@ data Response
| INITREMOTE_FAILURE ErrorMsg
| CLAIMURL_SUCCESS
| CLAIMURL_FAILURE
- | CHECKURL_SIZE Size
- | CHECKURL_SIZEUNKNOWN
+ | CHECKURL_CONTENTS Size FilePath
+ | CHECKURL_MULTI [(URLString, Size, FilePath)]
| CHECKURL_FAILURE ErrorMsg
| UNSUPPORTED_REQUEST
deriving (Show)
@@ -159,8 +159,8 @@ instance Proto.Receivable Response where
parseCommand "INITREMOTE-FAILURE" = Proto.parse1 INITREMOTE_FAILURE
parseCommand "CLAIMURL-SUCCESS" = Proto.parse0 CLAIMURL_SUCCESS
parseCommand "CLAIMURL-FAILURE" = Proto.parse0 CLAIMURL_FAILURE
- parseCommand "CHECKURL-SIZE" = Proto.parse1 CHECKURL_SIZE
- parseCommand "CHECKURL-SIZEUNKNOWN" = Proto.parse0 CHECKURL_SIZEUNKNOWN
+ parseCommand "CHECKURL-CONTENTS" = Proto.parse2 CHECKURL_CONTENTS
+ parseCommand "CHECKURL-MULTI" = Proto.parse1 CHECKURL_MULTI
parseCommand "CHECKURL-FAILURE" = Proto.parse1 CHECKURL_FAILURE
parseCommand "UNSUPPORTED-REQUEST" = Proto.parse0 UNSUPPORTED_REQUEST
parseCommand _ = Proto.parseFail
@@ -233,7 +233,7 @@ instance Proto.Receivable AsyncMessage where
type ErrorMsg = String
type Setting = String
type ProtocolVersion = Int
-type Size = Integer
+type Size = Maybe Integer
supportedProtocolVersions :: [ProtocolVersion]
supportedProtocolVersions = [1]
@@ -263,8 +263,10 @@ instance Proto.Serializable Cost where
deserialize = readish
instance Proto.Serializable Size where
- serialize = show
- deserialize = readish
+ serialize (Just s) = show s
+ serialize Nothing = "UNKNOWN"
+ deserialize "UNKNOWN" = Just Nothing
+ deserialize s = maybe Nothing (Just . Just) (readish s)
instance Proto.Serializable Availability where
serialize GloballyAvailable = "GLOBAL"
@@ -277,3 +279,12 @@ instance Proto.Serializable Availability where
instance Proto.Serializable BytesProcessed where
serialize (BytesProcessed n) = show n
deserialize = BytesProcessed <$$> readish
+
+instance Proto.Serializable [(URLString, Size, FilePath)] where
+ serialize = unwords . map go
+ where
+ go (url, sz, f) = url ++ " " ++ maybe "UNKNOWN" show sz ++ " " ++ f
+ deserialize = Just . go [] . words
+ where
+ go c (url:sz:f:rest) = go ((url, readish sz, f):c) rest
+ go c _ = reverse c