Skip to content

Commit

Permalink
Fix caches.
Browse files Browse the repository at this point in the history
There was an issues that caused the decoding of the caches to fail (see
mgsloan/store#25): decodeFileMaybe tried to deserialize to a value of type
a, while the files contained values of type Tagged a.
  • Loading branch information
Philipp Kant authored and mgsloan committed May 24, 2016
1 parent d3aef90 commit 12ec101
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
14 changes: 5 additions & 9 deletions src/Data/Store/VersionTagged.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import Data.Monoid ((<>))
import Data.Store
import Data.Store.TypeHash
import qualified Data.Text as T
import Data.Text.Encoding (encodeUtf8)
import Path
import Path.IO (ensureDir)

Expand All @@ -35,8 +34,6 @@ taggedEncodeFile fp x = do
$logDebug $ "Encoding " <> fpt
ensureDir (parent fp)
let encoded = encode (Tagged x)
-- liftIO $ BS.appendFile "encode-log" $ encodeUtf8 fpt <> " is " <> encoded <> "DONE"
-- $logDebug $ "Encoded: " <> decodeUtf8 (B16.encode encoded)
assert (decodeEx encoded == Tagged x) $ liftIO $ BS.writeFile (toFilePath fp) encoded
$logDebug $ "Finished writing " <> fpt

Expand All @@ -57,11 +54,11 @@ taggedDecodeOrLoad fp mx = do
x <- mx
taggedEncodeFile fp x
return x
Just (Tagged x) -> do
Just x -> do
$logDebug $ "Success decoding " <> fpt
return x

decodeFileMaybe :: (Store a, MonadIO m, MonadLogger m, MonadBaseControl IO m)
decodeFileMaybe :: (Store a, HasTypeHash a, MonadIO m, MonadLogger m, MonadBaseControl IO m)
=> Path loc File
-> m (Maybe a)
decodeFileMaybe fp = do
Expand All @@ -70,10 +67,9 @@ decodeFileMaybe fp = do
return Nothing
case mbs of
Nothing -> return Nothing
Just bs -> do
liftIO (Just <$> decodeIO bs) `catch` \(err :: PeekException) -> do
Just bs ->
liftIO (do (Tagged res) <- decodeIO bs
return (Just res)) `catch` \(err :: PeekException) -> do
let fpt = T.pack (toFilePath fp)
$logDebug ("Error while decoding " <> fpt <> ": " <> T.pack (show err) <> " (this might not be an error, when switching between stack versions)")
-- liftIO $ BS.appendFile "decode-error-log" $ encodeUtf8 fpt <> " is " <> bs <> "DONE"
-- $logDebug $ "Input: " <> decodeUtf8 (B16.encode bs)
return Nothing
4 changes: 2 additions & 2 deletions src/Stack/Build/Cache.hs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ tryGetCabalMod :: (MonadIO m, MonadReader env m, MonadThrow m, HasEnvConfig env,
tryGetCabalMod = tryGetCache configCabalMod

-- | Try to load a cache.
tryGetCache :: (MonadIO m, Store a, MonadBaseControl IO m, MonadLogger m)
tryGetCache :: (MonadIO m, Store a, HasTypeHash a, MonadBaseControl IO m, MonadLogger m)
=> (Path Abs Dir -> m (Path Abs File))
-> Path Abs Dir
-> m (Maybe a)
Expand Down Expand Up @@ -328,7 +328,7 @@ readPrecompiledCache pkgident copts depIDs = do
(file, getOldFile) <- precompiledCacheFile pkgident copts depIDs
mres <- decodeFileMaybe file
case mres of
Just res -> return res
Just res -> return (Just res)
Nothing -> do
-- Fallback on trying the old binary format.
oldFile <- getOldFile
Expand Down

0 comments on commit 12ec101

Please sign in to comment.