summaryrefslogtreecommitdiff
path: root/Key.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Key.hs')
-rw-r--r--Key.hs13
1 files changed, 11 insertions, 2 deletions
diff --git a/Key.hs b/Key.hs
index 16956ee5ea..eaa179d9f4 100644
--- a/Key.hs
+++ b/Key.hs
@@ -51,6 +51,7 @@ stubKey = Key
, keyMtime = Nothing
, keyChunkSize = Nothing
, keyChunkNum = Nothing
+ , keySerialization = Nothing
}
-- Gets the parent of a chunk key.
@@ -58,6 +59,7 @@ nonChunkKey :: Key -> Key
nonChunkKey k = k
{ keyChunkSize = Nothing
, keyChunkNum = Nothing
+ , keySerialization = Nothing
}
-- Where a chunk key is offset within its parent.
@@ -97,7 +99,9 @@ serializeKey :: Key -> String
serializeKey = decodeBL' . serializeKey'
serializeKey' :: Key -> L.ByteString
-serializeKey' = toLazyByteStringWith (safeStrategy 128 smallChunkSize) L.empty . buildKey
+serializeKey' k = case keySerialization k of
+ Nothing -> toLazyByteStringWith (safeStrategy 128 smallChunkSize) L.empty (buildKey k)
+ Just b -> L.fromStrict b
{- This is a strict parser for security reasons; a key
- can contain only 4 fields, which all consist only of numbers.
@@ -127,6 +131,7 @@ keyParser = do
, keyMtime = m
, keyChunkSize = cs
, keyChunkNum = cn
+ , keySerialization = Nothing
}
else fail "invalid keyName"
where
@@ -140,7 +145,10 @@ deserializeKey :: String -> Maybe Key
deserializeKey = deserializeKey' . encodeBS'
deserializeKey' :: S.ByteString -> Maybe Key
-deserializeKey' b = eitherToMaybe $ A.parseOnly keyParser b
+deserializeKey' b = either
+ (const Nothing)
+ (\k -> Just $ k { keySerialization = Just b })
+ (A.parseOnly keyParser b)
{- This splits any extension out of the keyName, returning the
- keyName minus extension, and the extension (including leading dot).
@@ -177,6 +185,7 @@ instance Arbitrary Key where
<*> ((abs . fromInteger <$>) <$> arbitrary) -- mtime cannot be negative
<*> ((abs <$>) <$> arbitrary) -- chunksize cannot be negative
<*> ((succ . abs <$>) <$> arbitrary) -- chunknum cannot be 0 or negative
+ <*> pure Nothing
instance Hashable Key where
hashIO32 = hashIO32 . serializeKey'