summaryrefslogtreecommitdiff
path: root/src/Storage/Internal.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2021-01-30 22:33:15 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2021-02-04 21:31:28 +0100
commit0ef31d05e00696d08adaf3ff4d5300424f88bdc1 (patch)
treed84c75ebad8c18f25b5bf18b1537a60d727e2a14 /src/Storage/Internal.hs
parent543c49361518b2141d816d2ce9a8bbf79a2fa031 (diff)
Storage: encode digest algorithm alongside hash data
Diffstat (limited to 'src/Storage/Internal.hs')
-rw-r--r--src/Storage/Internal.hs13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/Storage/Internal.hs b/src/Storage/Internal.hs
index 59eb514..d589c44 100644
--- a/src/Storage/Internal.hs
+++ b/src/Storage/Internal.hs
@@ -101,7 +101,13 @@ showRef :: Ref' c -> ByteString
showRef = showRefDigest . refDigest
showRefDigest :: RefDigest -> ByteString
-showRefDigest = showHex
+showRefDigest x = BC.pack "blake2#" `BC.append` showHex x
+
+readRefDigest :: ByteString -> Maybe RefDigest
+readRefDigest x = case BC.split '#' x of
+ [alg, dgst] | BA.convert alg == BC.pack "blake2" ->
+ refDigestFromByteString =<< readHex @ByteString dgst
+ _ -> Nothing
refDigestFromByteString :: ByteArrayAccess ba => ba -> Maybe RefDigest
refDigestFromByteString = fmap RefDigest . digestFromByteString
@@ -181,8 +187,9 @@ ioLoadBytesFromStorage st dgst = loadCurrent st >>=
loadCurrent Storage { stBacking = StorageMemory { memObjs = tobjs } } = M.lookup dgst <$> readMVar tobjs
refPath :: FilePath -> RefDigest -> FilePath
-refPath spath dgst = intercalate "/" [spath, "objects", pref, rest]
- where (pref, rest) = splitAt 2 $ BC.unpack $ showRefDigest dgst
+refPath spath rdgst = intercalate "/" [spath, "objects", BC.unpack alg, pref, rest]
+ where [alg, dgst] = BC.split '#' $ showRefDigest rdgst
+ (pref, rest) = splitAt 2 $ BC.unpack dgst
openFdParents :: FilePath -> OpenMode -> Maybe FileMode -> OpenFileFlags -> IO Fd