diff options
Diffstat (limited to 'Types/Key.hs')
-rw-r--r-- | Types/Key.hs | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/Types/Key.hs b/Types/Key.hs index 26af6220f..90f66f23e 100644 --- a/Types/Key.hs +++ b/Types/Key.hs @@ -2,7 +2,7 @@ - - Most things should not need this, using Types instead - - - Copyright 2011 Joey Hess <joey@kitenet.net> + - Copyright 2011-2014 Joey Hess <joey@kitenet.net> - - Licensed under the GNU GPL version 3 or higher. -} @@ -30,6 +30,8 @@ data Key = Key , keyBackendName :: String , keySize :: Maybe Integer , keyMtime :: Maybe EpochTime + , keyChunkSize :: Maybe Integer + , keyChunkNum :: Maybe Integer } deriving (Eq, Ord, Read, Show) {- A filename may be associated with a Key. -} @@ -41,6 +43,8 @@ stubKey = Key , keyBackendName = "" , keySize = Nothing , keyMtime = Nothing + , keyChunkSize = Nothing + , keyChunkNum = Nothing } fieldSep :: Char @@ -50,13 +54,13 @@ fieldSep = '-' - The name field is always shown last, separated by doubled fieldSeps, - and is the only field allowed to contain the fieldSep. -} key2file :: Key -> FilePath -key2file Key { keyBackendName = b, keySize = s, keyMtime = m, keyName = n } = - b +++ ('s' ?: s) +++ ('m' ?: m) +++ (fieldSep : n) +key2file Key { keyBackendName = b, keySize = s, keyMtime = m, keyChunkSize = cs, keyChunkNum = cn, keyName = n } = + b +++ ('s' ?: s) +++ ('m' ?: m) +++ ('S' ?: cs) +++ ('C' ?: cn) +++ (fieldSep : n) where "" +++ y = y x +++ "" = x x +++ y = x ++ fieldSep:y - c ?: (Just v) = c : show v + f ?: (Just v) = f : show v _ ?: _ = "" file2key :: FilePath -> Maybe Key @@ -84,6 +88,13 @@ file2key s addfield 'm' k v = do mtime <- readish v return $ k { keyMtime = Just mtime } + addfield 'S' k v = do + chunksize <- readish v + return $ k { keyChunkSize = Just chunksize } + addfield 'C' k v = case readish v of + Just chunknum | chunknum > 0 -> + return $ k { keyChunkNum = Just chunknum } + _ -> return k addfield _ _ _ = Nothing instance Arbitrary Key where @@ -92,6 +103,8 @@ instance Arbitrary Key where <*> (listOf1 $ elements ['A'..'Z']) -- BACKEND <*> ((abs <$>) <$> arbitrary) -- size cannot be negative <*> arbitrary + <*> ((abs <$>) <$> arbitrary) -- chunksize cannot be negative + <*> ((succ . abs <$>) <$> arbitrary) -- chunknum cannot be 0 or negative prop_idempotent_key_encode :: Key -> Bool prop_idempotent_key_encode k = Just k == (file2key . key2file) k @@ -103,6 +116,6 @@ prop_idempotent_key_decode f where -- file2key will accept the fields in any order, so don't -- try the test unless the fields are in the normal order - normalfieldorder = fields `isPrefixOf` "sm" + normalfieldorder = fields `isPrefixOf` "smSC" fields = map (f !!) $ filter (< length f) $ map succ $ elemIndices fieldSep f |