on master help sign in
Merge pull request #2441 from paulkoerbitz/1163-Replace-outdated-IBC-files

Detect outdated IBC files in 'buildTree' function in Chaser.hs. Fixes #1163.

commit7a673206b6c2c965e8519eb444d65063b4ac50b1 authorNiklas Larsson <metaniklas@gmail.com> dateThu 16 Jul 2015, 16:23 (11 years ago) parent4fae6d4d5bde22
2 files changed+25−19
src/Idris/Chaser.hs+15−18 src/Idris/IBC.hs+10−1
src/Idris/Chaser.hs+15−18
@@ -116,29 +116,26 @@ buildTree built fp = btree [] fp
116116 else return []
117117 mt <- idrisCatch (runIO $ getModificationTime fn)
118118 (\c -> runIO $ getIModTime src)
119− ok <- checkIBCUpToDate fn src
120− return [MTree (IBC fn src) ok mt ms]
119+ -- FIXME: It's also not up to date if anything it imports has
120+ -- been modified since its own ibc has.
121+ --
122+ -- Issue #1592 on the issue tracker.
123+ --
124+ -- https://github.com/idris-lang/Idris-dev/issues/1592
125+ ibcOutdated <- fn `younger` (getSrcFile src)
126+ ibcValid <- hasValidIBCVersion fn
127+ return [MTree (IBC fn src) (ibcOutdated || not ibcValid) mt ms]
121128
122129 getSrcFile (IBC _ src) = getSrcFile src
123130 getSrcFile (LIDR src) = src
124131 getSrcFile (IDR src) = src
125132
126− -- FIXME: It's also not up to date if anything it imports has
127− -- been modified since its own ibc has.
128− --
129− -- Issue #1592 on the issue tracker.
130− --
131− -- https://github.com/idris-lang/Idris-dev/issues/1592
132−
133− checkIBCUpToDate fn (LIDR src) = older fn src
134− checkIBCUpToDate fn (IDR src) = older fn src
135−
136− older ibc src = do exist <- runIO $ doesFileExist src
137− if exist then do
138− ibct <- runIO $ getModificationTime ibc
139− srct <- runIO $ getModificationTime src
140− return (srct >= ibct)
141− else return False
133+ younger ibc src = do exist <- runIO $ doesFileExist src
134+ if exist then do
135+ ibct <- runIO $ getModificationTime ibc
136+ srct <- runIO $ getModificationTime src
137+ return (srct > ibct)
138+ else return False
142139
143140 children :: Bool -> FilePath -> [FilePath] -> Idris [ModuleTree]
144141 children lit f done = -- idrisCatch
src/Idris/IBC.hs+10−1
@@ -2,7 +2,8 @@
22{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
33
44module Idris.IBC (loadIBC, loadPkgIndex,
5− writeIBC, writePkgIndex) where
5+ writeIBC, writePkgIndex,
6+ hasValidIBCVersion) where
67
78import Idris.Core.Evaluate
89import Idris.Core.TT
@@ -94,6 +95,14 @@ deriving instance Binary IBCFile
9495initIBC :: IBCFile
9596initIBC = IBCFile ibcVersion "" [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] Nothing [] [] []
9697
98+hasValidIBCVersion :: FilePath -> Idris Bool
99+hasValidIBCVersion fp = do
100+ archiveFile <- runIO $ B.readFile fp
101+ case toArchiveOrFail archiveFile of
102+ Left _ -> return False
103+ Right archive -> do ver <- getEntry 0 "ver" archive
104+ return (ver == ibcVersion)
105+
97106loadIBC :: Bool -- ^ True = reexport, False = make everything private
98107 -> FilePath -> Idris ()
99108loadIBC reexport fp