summaryrefslogtreecommitdiff
path: root/src/Storage/Internal.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2022-07-16 17:20:29 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2022-07-16 17:20:29 +0200
commitcfdbb5b70abcede5e9ed980db5dd12a6764bb3f0 (patch)
tree5bba35c2585687dcebfe229b240079e3c20f522c /src/Storage/Internal.hs
parent3c05d0cbd310af1c34d3731a15feb2a9508aded2 (diff)
Test: store command for arbitrary type and data
Diffstat (limited to 'src/Storage/Internal.hs')
-rw-r--r--src/Storage/Internal.hs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Storage/Internal.hs b/src/Storage/Internal.hs
index 1f093b0..04fdf0d 100644
--- a/src/Storage/Internal.hs
+++ b/src/Storage/Internal.hs
@@ -193,6 +193,16 @@ instance StorageCompleteness Partial where
returnLoadResult = id
ioLoadBytes (Ref st dgst) = maybe (Left dgst) Right <$> ioLoadBytesFromStorage st dgst
+unsafeStoreRawBytes :: Storage' c -> BL.ByteString -> IO (Ref' c)
+unsafeStoreRawBytes st raw = do
+ let dgst = hashToRefDigest raw
+ case stBacking st of
+ StorageDir { dirPath = sdir } -> writeFileOnce (refPath sdir dgst) $ compress raw
+ StorageMemory { memObjs = tobjs } ->
+ dgst `deepseq` -- the TVar may be accessed when evaluating the data to be written
+ modifyMVar_ tobjs (return . M.insert dgst raw)
+ return $ Ref st dgst
+
ioLoadBytesFromStorage :: Storage' c -> RefDigest -> IO (Maybe BL.ByteString)
ioLoadBytesFromStorage st dgst = loadCurrent st >>=
\case Just bytes -> return $ Just bytes