Skip to content

Commit d363712

Browse files
committed
Update to store-0.4.1
This has the side effect of invalidating all of the stored binary caches, with the upside of having better error reporting for the future.
1 parent 941c388 commit d363712

5 files changed

Lines changed: 29 additions & 24 deletions

File tree

src/Data/Store/VersionTagged.hs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import qualified Data.Map as M
2525
import Data.Monoid ((<>))
2626
import qualified Data.Set as S
2727
import Data.Store
28+
import Data.Store.Core (unsafeEncodeWith)
2829
import Data.Store.Version
2930
import qualified Data.Text as T
3031
import Language.Haskell.TH
@@ -33,65 +34,65 @@ import Path.IO (ensureDir)
3334
import Prelude
3435

3536
versionedEncodeFile :: Data a => VersionConfig a -> Q Exp
36-
versionedEncodeFile vc = [e| \fp x -> storeEncodeFile fp ($(wrapVersion vc) x) |]
37+
versionedEncodeFile vc = [e| storeEncodeFile $(encodeWithVersionQ vc) $(decodeWithVersionQ vc) |]
3738

3839
versionedDecodeOrLoad :: Data a => VersionConfig a -> Q Exp
39-
versionedDecodeOrLoad vc = [| versionedDecodeOrLoadImpl $(wrapVersion vc) $(checkVersion vc) |]
40+
versionedDecodeOrLoad vc = [| versionedDecodeOrLoadImpl $(encodeWithVersionQ vc) $(decodeWithVersionQ vc) |]
4041

4142
versionedDecodeFile :: Data a => VersionConfig a -> Q Exp
42-
versionedDecodeFile vc = [e| versionedDecodeFileImpl $(checkVersion vc) |]
43+
versionedDecodeFile vc = [e| versionedDecodeFileImpl $(decodeWithVersionQ vc) |]
4344

4445
-- | Write to the given file.
4546
storeEncodeFile :: (Store a, MonadIO m, MonadLogger m, Eq a)
46-
=> Path Abs File
47+
=> (a -> (Int, Poke ()))
48+
-> Peek a
49+
-> Path Abs File
4750
-> a
4851
-> m ()
49-
storeEncodeFile fp x = do
52+
storeEncodeFile pokeFunc peekFunc fp x = do
5053
let fpt = T.pack (toFilePath fp)
5154
$logDebug $ "Encoding " <> fpt
5255
ensureDir (parent fp)
53-
let encoded = encode x
54-
assert (decodeEx encoded == x) $ liftIO $ BS.writeFile (toFilePath fp) encoded
56+
let (sz, poker) = pokeFunc x
57+
encoded = unsafeEncodeWith poker sz
58+
assert (decodeExWith peekFunc encoded == x) $ liftIO $ BS.writeFile (toFilePath fp) encoded
5559
$logDebug $ "Finished writing " <> fpt
5660

5761
-- | Read from the given file. If the read fails, run the given action and
5862
-- write that back to the file. Always starts the file off with the
5963
-- version tag.
6064
versionedDecodeOrLoadImpl :: (Store a, Eq a, MonadIO m, MonadLogger m, MonadBaseControl IO m)
61-
=> (a -> WithVersion a)
62-
-> (WithVersion a -> Either VersionCheckException a)
65+
=> (a -> (Int, Poke ()))
66+
-> Peek a
6367
-> Path Abs File
6468
-> m a
6569
-> m a
66-
versionedDecodeOrLoadImpl wrap check fp mx = do
70+
versionedDecodeOrLoadImpl pokeFunc peekFunc fp mx = do
6771
let fpt = T.pack (toFilePath fp)
6872
$logDebug $ "Trying to decode " <> fpt
69-
mres <- versionedDecodeFileImpl check fp
73+
mres <- versionedDecodeFileImpl peekFunc fp
7074
case mres of
7175
Just x -> do
7276
$logDebug $ "Success decoding " <> fpt
7377
return x
7478
_ -> do
7579
$logDebug $ "Failure decoding " <> fpt
7680
x <- mx
77-
storeEncodeFile fp (wrap x)
81+
storeEncodeFile pokeFunc peekFunc fp x
7882
return x
7983

8084
versionedDecodeFileImpl :: (Store a, MonadIO m, MonadLogger m, MonadBaseControl IO m)
81-
=> (WithVersion a -> Either VersionCheckException a)
85+
=> Peek a
8286
-> Path loc File
8387
-> m (Maybe a)
84-
versionedDecodeFileImpl check fp = do
88+
versionedDecodeFileImpl peekFunc fp = do
8589
mbs <- liftIO (Just <$> BS.readFile (toFilePath fp)) `catch` \(err :: IOException) -> do
8690
$logDebug ("Exception ignored when attempting to load " <> T.pack (toFilePath fp) <> ": " <> T.pack (show err))
8791
return Nothing
8892
case mbs of
8993
Nothing -> return Nothing
9094
Just bs ->
91-
liftIO (do decoded <- decodeIO bs
92-
return $ case check decoded of
93-
Right res -> Just res
94-
_ -> Nothing) `catch` \(err :: PeekException) -> do
95+
liftIO (Just <$> decodeIOWith peekFunc bs) `catch` \(err :: PeekException) -> do
9596
let fpt = T.pack (toFilePath fp)
9697
$logDebug ("Error while decoding " <> fpt <> ": " <> T.pack (show err) <> " (this might not be an error, when switching between stack versions)")
9798
return Nothing

stack-8.0.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ nix:
99
packages:
1010
- zlib
1111
extra-deps:
12-
- store-0.3.1
13-
- store-core-0.3
12+
- store-0.4.1
13+
- store-core-0.4
1414
- th-utilities-0.2.0.1
1515
- http-client-tls-0.3.4

stack-nightly.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ image:
33
containers:
44
- base: "fpco/stack-base" # see ./etc/docker/stack-base/Dockerfile
55
name: "fpco/stack-test"
6+
extra-deps:
7+
- store-0.4.1
8+
- store-core-0.4
69
nix:
710
# --nix on the command-line to enable.
811
enable: false

stack.cabal

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ library
273273
, project-template >= 0.2
274274
, zip-archive < 0.4
275275
, hpack >= 0.17.0 && < 0.18
276-
, store >= 0.2.1.0
276+
, store >= 0.4.1 && < 0.5
277+
, store-core >= 0.4 && < 0.5
277278
, annotated-wl-pprint
278279
, file-embed >= 0.0.10
279280
if os(windows)
@@ -378,7 +379,7 @@ test-suite stack-test
378379
, th-reify-many
379380
, smallcheck
380381
, bytestring
381-
, store >= 0.2.1.0
382+
, store >= 0.4.1 && < 0.5
382383
, vector >= 0.10.12.3 && < 0.13
383384
, unordered-containers
384385
, template-haskell

stack.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ nix:
1414
extra-deps:
1515
- Cabal-1.24.2.0
1616
- th-utilities-0.2.0.1
17-
- store-0.3
18-
- store-core-0.3
17+
- store-0.4.1
18+
- store-core-0.4
1919
- th-orphans-0.13.1
2020
- http-client-0.5.3.3
2121
- http-client-tls-0.3.4

0 commit comments

Comments
 (0)