diff --git a/CmdLine/GitAnnex/Options.hs b/CmdLine/GitAnnex/Options.hs index 3c90513d8b..be7a3c292f 100644 --- a/CmdLine/GitAnnex/Options.hs +++ b/CmdLine/GitAnnex/Options.hs @@ -210,7 +210,7 @@ parseAllOption = flag' WantAllKeys ) parseKey :: Monad m => String -> m Key -parseKey = maybe (fail "invalid key") return . file2key +parseKey = maybe (fail "invalid key") return . deserializeKey -- Options to match properties of annexed files. annexedMatchingOptions :: [GlobalOption] diff --git a/CmdLine/Seek.hs b/CmdLine/Seek.hs index efb373fb40..dbbde5b968 100644 --- a/CmdLine/Seek.hs +++ b/CmdLine/Seek.hs @@ -158,7 +158,7 @@ withFilesMaybeModified a params = seekActions $ withKeys :: (Key -> CommandSeek) -> CmdParams -> CommandSeek withKeys a l = seekActions $ return $ map (a . parse) l where - parse p = fromMaybe (giveup "bad key") $ file2key p + parse p = fromMaybe (giveup "bad key") $ deserializeKey p withNothing :: CommandSeek -> CmdParams -> CommandSeek withNothing a [] = a diff --git a/Command/CheckPresentKey.hs b/Command/CheckPresentKey.hs index fb8f9e53e2..fa7b3a1830 100644 --- a/Command/CheckPresentKey.hs +++ b/Command/CheckPresentKey.hs @@ -69,7 +69,7 @@ batchResult Present = liftIO $ putStrLn "1" batchResult _ = liftIO $ putStrLn "0" toKey :: String -> Key -toKey = fromMaybe (giveup "Bad key") . file2key +toKey = fromMaybe (giveup "Bad key") . deserializeKey toRemote :: String -> Annex Remote toRemote rn = maybe (giveup "Unknown remote") return diff --git a/Command/ContentLocation.hs b/Command/ContentLocation.hs index 202d76a21d..57350917ba 100644 --- a/Command/ContentLocation.hs +++ b/Command/ContentLocation.hs @@ -19,7 +19,7 @@ cmd = noCommit $ noMessages $ run :: () -> String -> Annex Bool run _ p = do - let k = fromMaybe (giveup "bad key") $ file2key p + let k = fromMaybe (giveup "bad key") $ deserializeKey p maybe (return False) (\f -> liftIO (putStrLn f) >> return True) =<< inAnnex' (pure True) Nothing check k where diff --git a/Command/DropKey.hs b/Command/DropKey.hs index df85803062..546c9795e1 100644 --- a/Command/DropKey.hs +++ b/Command/DropKey.hs @@ -38,7 +38,7 @@ seek o = do Batch fmt -> batchInput fmt parsekey $ batchCommandAction . start NoBatch -> noop where - parsekey = maybe (Left "bad key") Right . file2key + parsekey = maybe (Left "bad key") Right . deserializeKey start :: Key -> CommandStart start key = do diff --git a/Command/FromKey.hs b/Command/FromKey.hs index 4b48f4e5c2..4e1bc4fcae 100644 --- a/Command/FromKey.hs +++ b/Command/FromKey.hs @@ -79,7 +79,7 @@ mkKey :: String -> Key mkKey s = case parseURI s of Just u | not (isKeyPrefix (uriScheme u)) -> Backend.URL.fromUrl s Nothing - _ -> case file2key s of + _ -> case deserializeKey s of Just k -> k Nothing -> giveup $ "bad key/url " ++ s diff --git a/Command/LockContent.hs b/Command/LockContent.hs index b5902ed282..dfa867aa80 100644 --- a/Command/LockContent.hs +++ b/Command/LockContent.hs @@ -32,7 +32,7 @@ start [ks] = do then exitSuccess else exitFailure where - k = fromMaybe (giveup "bad key") (file2key ks) + k = fromMaybe (giveup "bad key") (deserializeKey ks) locksuccess = liftIO $ do putStrLn contentLockedMarker hFlush stdout diff --git a/Command/Multicast.hs b/Command/Multicast.hs index ce34481683..6bdd085091 100644 --- a/Command/Multicast.hs +++ b/Command/Multicast.hs @@ -208,7 +208,7 @@ receive ups = do storeReceived :: FilePath -> Annex () storeReceived f = do - case file2key (takeFileName f) of + case deserializeKey (takeFileName f) of Nothing -> do warning $ "Received a file " ++ f ++ " that is not a git-annex key. Deleting this file." liftIO $ nukeFile f diff --git a/Command/ReKey.hs b/Command/ReKey.hs index ef97d2459e..ed8210ee5a 100644 --- a/Command/ReKey.hs +++ b/Command/ReKey.hs @@ -43,7 +43,7 @@ batchParser :: String -> Either String (FilePath, Key) batchParser s = case separate (== ' ') (reverse s) of (rk, rf) | null rk || null rf -> Left "Expected: \"file key\"" - | otherwise -> case file2key (reverse rk) of + | otherwise -> case deserializeKey (reverse rk) of Nothing -> Left "bad key" Just k -> Right (reverse rf, k) @@ -53,7 +53,7 @@ seek o = case batchOption o of NoBatch -> withPairs (commandAction . start . parsekey) (reKeyThese o) where parsekey (file, skey) = - (file, fromMaybe (giveup "bad key") (file2key skey)) + (file, fromMaybe (giveup "bad key") (deserializeKey skey)) start :: (FilePath, Key) -> CommandStart start (file, newkey) = ifAnnexed file go stop diff --git a/Command/ReadPresentKey.hs b/Command/ReadPresentKey.hs index d1e298196b..a5fc0eeecd 100644 --- a/Command/ReadPresentKey.hs +++ b/Command/ReadPresentKey.hs @@ -27,5 +27,5 @@ start (ks:us:[]) = do then liftIO exitSuccess else liftIO exitFailure where - k = fromMaybe (giveup "bad key") (file2key ks) + k = fromMaybe (giveup "bad key") (deserializeKey ks) start _ = giveup "Wrong number of parameters" diff --git a/Command/SetKey.hs b/Command/SetKey.hs index 32be029b24..3681fb7bc4 100644 --- a/Command/SetKey.hs +++ b/Command/SetKey.hs @@ -26,7 +26,7 @@ start (keyname:file:[]) = do start _ = giveup "specify a key and a content file" mkKey :: String -> Key -mkKey = fromMaybe (giveup "bad key") . file2key +mkKey = fromMaybe (giveup "bad key") . deserializeKey perform :: FilePath -> Key -> CommandPerform perform file key = do diff --git a/Command/SetPresentKey.hs b/Command/SetPresentKey.hs index a9dbe54522..bb03ef1bbf 100644 --- a/Command/SetPresentKey.hs +++ b/Command/SetPresentKey.hs @@ -40,7 +40,7 @@ data KeyStatus = KeyStatus Key UUID LogStatus parseKeyStatus :: [String] -> Either String KeyStatus parseKeyStatus (ks:us:vs:[]) = do - k <- maybe (Left "bad key") Right (file2key ks) + k <- maybe (Left "bad key") Right (deserializeKey ks) let u = toUUID us s <- maybe (Left "bad value") Right (parseStatus vs) return $ KeyStatus k u s diff --git a/Command/TransferInfo.hs b/Command/TransferInfo.hs index 2278121424..81389c3ab5 100644 --- a/Command/TransferInfo.hs +++ b/Command/TransferInfo.hs @@ -38,7 +38,7 @@ seek = withWords (commandAction . start) -} start :: [String] -> CommandStart start (k:[]) = do - case file2key k of + case deserializeKey k of Nothing -> error "bad key" (Just key) -> whenM (inAnnex key) $ do afile <- AssociatedFile <$> Fields.getField Fields.associatedFile diff --git a/Key.hs b/Key.hs index 93aed8ecac..16956ee5ea 100644 --- a/Key.hs +++ b/Key.hs @@ -14,8 +14,8 @@ module Key ( buildKey, keyParser, serializeKey, - serializeKey, - deserializeKey', + serializeKey', + deserializeKey, deserializeKey', nonChunkKey, chunkKeyOffset, @@ -179,8 +179,8 @@ instance Arbitrary Key where <*> ((succ . abs <$>) <$> arbitrary) -- chunknum cannot be 0 or negative instance Hashable Key where - hashIO32 = hashIO32 . deserializeKey' - hashIO64 = hashIO64 . deserializeKey' + hashIO32 = hashIO32 . serializeKey' + hashIO64 = hashIO64 . serializeKey' instance ToJSON' Key where toJSON' = toJSON' . serializeKey diff --git a/Upgrade/V1.hs b/Upgrade/V1.hs index 99be467567..a1fb076cbd 100644 --- a/Upgrade/V1.hs +++ b/Upgrade/V1.hs @@ -144,7 +144,7 @@ oldlog2key l -- as the v2 key that it is. readKey1 :: String -> Key readKey1 v - | mixup = fromJust $ file2key $ intercalate ":" $ Prelude.tail bits + | mixup = fromJust $ deserializeKey $ intercalate ":" $ Prelude.tail bits | otherwise = stubKey { keyName = encodeBS n , keyVariety = parseKeyVariety (encodeBS b)