diff --git a/Annex/DirHashes.hs b/Annex/DirHashes.hs index 1e1991364a..194b4932c5 100644 --- a/Annex/DirHashes.hs +++ b/Annex/DirHashes.hs @@ -65,14 +65,14 @@ hashDirs (HashLevels 1) sz s = addTrailingPathSeparator $ take sz s hashDirs _ sz s = addTrailingPathSeparator $ take sz s drop sz s hashDirLower :: HashLevels -> Hasher -hashDirLower n k = hashDirs n 3 $ take 6 $ show $ md5s $ serializeKey' $ nonChunkKey k +hashDirLower n k = hashDirs n 3 $ take 6 $ show $ md5 $ serializeKey' $ nonChunkKey k {- This was originally using Data.Hash.MD5 from MissingH. This new version - is faster, but ugly as it has to replicate the 4 Word32's that produced. -} hashDirMixed :: HashLevels -> Hasher hashDirMixed n k = hashDirs n 2 $ take 4 $ concatMap display_32bits_as_dir $ encodeWord32 $ map fromIntegral $ Data.ByteArray.unpack $ - Utility.Hash.md5s $ serializeKey' $ nonChunkKey k + Utility.Hash.md5 $ serializeKey' $ nonChunkKey k where encodeWord32 (b1:b2:b3:b4:rest) = (shiftL b4 24 .|. shiftL b3 16 .|. shiftL b2 8 .|. b1) diff --git a/Annex/Export.hs b/Annex/Export.hs index 2cc110cb83..47a6a75249 100644 --- a/Annex/Export.hs +++ b/Annex/Export.hs @@ -42,7 +42,6 @@ exportKey sha = mk <$> catKey sha , keyMtime = Nothing , keyChunkSize = Nothing , keyChunkNum = Nothing - , keySerialization = Nothing } exportTree :: Remote.RemoteConfig -> Bool diff --git a/Annex/Locations.hs b/Annex/Locations.hs index 835f7f9eac..9d6f1fe7d2 100644 --- a/Annex/Locations.hs +++ b/Annex/Locations.hs @@ -85,6 +85,7 @@ module Annex.Locations ( import Data.Char import Data.Default import qualified Data.ByteString.Char8 as S8 +import qualified Data.ByteString.Lazy as L import Common import Key @@ -515,7 +516,7 @@ keyFile = fromRawFilePath . keyFile' keyFile' :: Key -> RawFilePath keyFile' k = - let b = serializeKey' k + let b = L.toStrict (serializeKey' k) in if any (`S8.elem` b) ['&', '%', ':', '/'] then S8.concatMap esc b else b diff --git a/Annex/VariantFile.hs b/Annex/VariantFile.hs index 9808293be9..acab1e8281 100644 --- a/Annex/VariantFile.hs +++ b/Annex/VariantFile.hs @@ -10,7 +10,7 @@ module Annex.VariantFile where import Annex.Common import Utility.Hash -import qualified Data.ByteString as S +import qualified Data.ByteString.Lazy as L variantMarker :: String variantMarker = ".variant-" @@ -41,5 +41,5 @@ variantFile file key where doubleconflict = variantMarker `isInfixOf` file -shortHash :: S.ByteString -> String -shortHash = take 4 . show . md5s +shortHash :: L.ByteString -> String +shortHash = take 4 . show . md5 diff --git a/Backend.hs b/Backend.hs index 5b7b82e40c..2932253aec 100644 --- a/Backend.hs +++ b/Backend.hs @@ -58,10 +58,7 @@ genKey source preferredbackend = do Just k -> Just (makesane k, b) where -- keyNames should not contain newline characters. - makesane k = k - { keyName = S8.map fixbadchar (keyName k) - , keySerialization = Nothing - } + makesane k = k { keyName = S8.map fixbadchar (keyName k) } fixbadchar c | c == '\n' = '_' | otherwise = c diff --git a/Backend/Hash.hs b/Backend/Hash.hs index 6c42af19c3..b8977301b3 100644 --- a/Backend/Hash.hs +++ b/Backend/Hash.hs @@ -181,7 +181,6 @@ trivialMigrate' oldkey newbackend afile maxextlen | migratable && hasExt oldvariety = Just $ oldkey { keyName = keyHash oldkey , keyVariety = newvariety - , keySerialization = Nothing } {- Fast migration from hash to hashE backend. -} | migratable && hasExt newvariety = case afile of @@ -190,7 +189,6 @@ trivialMigrate' oldkey newbackend afile maxextlen { keyName = keyHash oldkey <> encodeBS (selectExtension maxextlen file) , keyVariety = newvariety - , keySerialization = Nothing } {- Upgrade to fix bad previous migration that created a - non-extension preserving key, with an extension @@ -198,7 +196,6 @@ trivialMigrate' oldkey newbackend afile maxextlen | newvariety == oldvariety && not (hasExt oldvariety) && keyHash oldkey /= keyName oldkey = Just $ oldkey { keyName = keyHash oldkey - , keySerialization = Nothing } | otherwise = Nothing where @@ -291,8 +288,5 @@ testKeyBackend = let b = genBackendE (SHA2Hash (HashSize 256)) in b { getKey = (fmap addE) <$$> getKey b } where - addE k = k - { keyName = keyName k <> longext - , keySerialization = Nothing - } + addE k = k { keyName = keyName k <> longext } longext = ".this-is-a-test-key" diff --git a/Command/AddUrl.hs b/Command/AddUrl.hs index cff1166fdb..be008f63aa 100644 --- a/Command/AddUrl.hs +++ b/Command/AddUrl.hs @@ -377,10 +377,7 @@ finishDownloadWith tmp u url file = do {- Adds the url size to the Key. -} addSizeUrlKey :: Url.UrlInfo -> Key -> Key -addSizeUrlKey urlinfo key = key - { keySize = Url.urlSize urlinfo - , keySerialization = Nothing - } +addSizeUrlKey urlinfo key = key { keySize = Url.urlSize urlinfo } {- Adds worktree file to the repository. -} addWorkTree :: UUID -> URLString -> FilePath -> Key -> Maybe FilePath -> Annex () diff --git a/Key.hs b/Key.hs index 00aea87352..593d674ccd 100644 --- a/Key.hs +++ b/Key.hs @@ -51,18 +51,14 @@ stubKey = Key , keyMtime = Nothing , keyChunkSize = Nothing , keyChunkNum = Nothing - , keySerialization = Nothing } -- Gets the parent of a chunk key. nonChunkKey :: Key -> Key -nonChunkKey k - | keyChunkSize k == Nothing && keyChunkNum k == Nothing = k - | otherwise = k - { keyChunkSize = Nothing - , keyChunkNum = Nothing - , keySerialization = Nothing - } +nonChunkKey k = k + { keyChunkSize = Nothing + , keyChunkNum = Nothing + } -- Where a chunk key is offset within its parent. chunkKeyOffset :: Key -> Maybe Integer @@ -98,13 +94,10 @@ buildKey k = byteString (formatKeyVariety (keyVariety k)) _ ?: Nothing = mempty serializeKey :: Key -> String -serializeKey = decodeBS' . serializeKey' +serializeKey = decodeBL' . serializeKey' -serializeKey' :: Key -> S.ByteString -serializeKey' k = case keySerialization k of - Nothing -> L.toStrict $ - toLazyByteStringWith (safeStrategy 128 smallChunkSize) L.empty (buildKey k) - Just b -> b +serializeKey' :: Key -> L.ByteString +serializeKey' = toLazyByteStringWith (safeStrategy 128 smallChunkSize) L.empty . buildKey {- This is a strict parser for security reasons; a key - can contain only 4 fields, which all consist only of numbers. @@ -134,7 +127,6 @@ keyParser = do , keyMtime = m , keyChunkSize = cs , keyChunkNum = cn - , keySerialization = Nothing } else fail "invalid keyName" where @@ -148,10 +140,7 @@ deserializeKey :: String -> Maybe Key deserializeKey = deserializeKey' . encodeBS' deserializeKey' :: S.ByteString -> Maybe Key -deserializeKey' b = either - (const Nothing) - (\k -> Just $ k { keySerialization = Just b }) - (A.parseOnly keyParser b) +deserializeKey' b = eitherToMaybe $ A.parseOnly keyParser b {- This splits any extension out of the keyName, returning the - keyName minus extension, and the extension (including leading dot). @@ -189,7 +178,6 @@ 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' diff --git a/Remote/Helper/Chunked.hs b/Remote/Helper/Chunked.hs index 595a4c4d63..f3c69c38dd 100644 --- a/Remote/Helper/Chunked.hs +++ b/Remote/Helper/Chunked.hs @@ -68,10 +68,7 @@ chunkKeyStream :: Key -> ChunkSize -> ChunkKeyStream chunkKeyStream basek chunksize = ChunkKeyStream $ map mk [1..] where mk chunknum = sizedk { keyChunkNum = Just chunknum } - sizedk = basek - { keyChunkSize = Just (toInteger chunksize) - , keySerialization = Nothing - } + sizedk = basek { keyChunkSize = Just (toInteger chunksize) } nextChunkKeyStream :: ChunkKeyStream -> (Key, ChunkKeyStream) nextChunkKeyStream (ChunkKeyStream (k:l)) = (k, ChunkKeyStream l) diff --git a/Types/Key.hs b/Types/Key.hs index 97d548ff78..df0e042606 100644 --- a/Types/Key.hs +++ b/Types/Key.hs @@ -23,7 +23,6 @@ data Key = Key , keyMtime :: Maybe EpochTime , keyChunkSize :: Maybe Integer , keyChunkNum :: Maybe Integer - , keySerialization :: Maybe S.ByteString -- ^ cached serialization } deriving (Eq, Ord, Read, Show) {- A filename may be associated with a Key. -} diff --git a/Upgrade/V1.hs b/Upgrade/V1.hs index e58e5818f7..c0dafbb842 100644 --- a/Upgrade/V1.hs +++ b/Upgrade/V1.hs @@ -150,7 +150,6 @@ readKey1 v , keyVariety = parseKeyVariety (encodeBS b) , keySize = s , keyMtime = t - , keySerialization = Nothing } where bits = splitc ':' v diff --git a/Utility/Hash.hs b/Utility/Hash.hs index 99923fedc7..23b3f26ec5 100644 --- a/Utility/Hash.hs +++ b/Utility/Hash.hs @@ -27,7 +27,6 @@ module Utility.Hash ( blake2b_512, #endif md5, - md5s, prop_hashes_stable, Mac(..), calcMac, @@ -113,9 +112,6 @@ blake2b_512 = hashlazy md5 :: L.ByteString -> Digest MD5 md5 = hashlazy -md5s :: S.ByteString -> Digest MD5 -md5s = hash - {- Check that all the hashes continue to hash the same. -} prop_hashes_stable :: Bool prop_hashes_stable = all (\(hasher, result) -> hasher foo == result)