@@ -35,7 +35,6 @@ import Prelude ()
3535
3636import Data.Binary.Get (runGetOrFail )
3737import qualified Data.ByteString.Lazy as BS
38- import qualified Data.Hashable as Hashable
3938import qualified Data.Map.Strict as Map
4039
4140import Control.Exception
@@ -51,6 +50,7 @@ import qualified Control.Monad.State as State
5150import Control.Monad.Trans (MonadIO , liftIO )
5251
5352import Distribution.Client.Glob
53+ import Distribution.Client.HashValue
5454import Distribution.Client.Utils (MergeResult (.. ), mergeBy )
5555import Distribution.Compat.Time
5656import Distribution.Simple.FileMonitor.Types
@@ -83,8 +83,6 @@ data MonitorStateFileSet
8383instance Binary MonitorStateFileSet
8484instance Structured MonitorStateFileSet
8585
86- type Hash = Int
87-
8886-- | The state necessary to determine whether a monitored file has changed.
8987--
9088-- This covers all the cases of 'MonitorFilePath' except for globs which is
@@ -107,7 +105,7 @@ data MonitorStateFileStatus
107105 | -- | cached file mtime
108106 MonitorStateFileModTime ! ModTime
109107 | -- | cached mtime and content hash
110- MonitorStateFileHashed ! ModTime ! Hash
108+ MonitorStateFileHashed ! ModTime ! HashValue
111109 | MonitorStateDirExists
112110 | -- | cached dir mtime
113111 MonitorStateDirModTime ! ModTime
@@ -961,21 +959,21 @@ buildMonitorStateGlobRel
961959-- updating a file monitor the set of files is the same or largely the same so
962960-- we can grab the previously known content hashes with their corresponding
963961-- mtimes.
964- type FileHashCache = Map FilePath (ModTime , Hash )
962+ type FileHashCache = Map FilePath (ModTime , HashValue )
965963
966964-- | We declare it a cache hit if the mtime of a file is the same as before.
967- lookupFileHashCache :: FileHashCache -> FilePath -> ModTime -> Maybe Hash
965+ lookupFileHashCache :: FileHashCache -> FilePath -> ModTime -> Maybe HashValue
968966lookupFileHashCache hashcache file mtime = do
969967 (mtime', hash) <- Map. lookup file hashcache
970968 guard (mtime' == mtime)
971969 return hash
972970
973971-- | Either get it from the cache or go read the file
974- getFileHash :: FileHashCache -> FilePath -> FilePath -> ModTime -> IO Hash
972+ getFileHash :: FileHashCache -> FilePath -> FilePath -> ModTime -> IO HashValue
975973getFileHash hashcache relfile absfile mtime =
976974 case lookupFileHashCache hashcache relfile mtime of
977975 Just hash -> return hash
978- Nothing -> readFileHash absfile
976+ Nothing -> readFileHashValue absfile
979977
980978-- | Build a 'FileHashCache' from the previous 'MonitorStateFileSet'. While
981979-- in principle we could preserve the structure of the previous state, given
@@ -998,7 +996,7 @@ readCacheFileHashes monitor =
998996 collectAllFileHashes singlePaths
999997 `Map.union` collectAllGlobHashes globPaths
1000998
1001- collectAllFileHashes :: [MonitorStateFile ] -> Map FilePath (ModTime , Hash )
999+ collectAllFileHashes :: [MonitorStateFile ] -> Map FilePath (ModTime , HashValue )
10021000 collectAllFileHashes singlePaths =
10031001 Map. fromList
10041002 [ (fpath, (mtime, hash))
@@ -1010,15 +1008,15 @@ readCacheFileHashes monitor =
10101008 singlePaths
10111009 ]
10121010
1013- collectAllGlobHashes :: [MonitorStateGlob ] -> Map FilePath (ModTime , Hash )
1011+ collectAllGlobHashes :: [MonitorStateGlob ] -> Map FilePath (ModTime , HashValue )
10141012 collectAllGlobHashes globPaths =
10151013 Map. fromList
10161014 [ (fpath, (mtime, hash))
10171015 | MonitorStateGlob _ _ _ gstate <- globPaths
10181016 , (fpath, (mtime, hash)) <- collectGlobHashes " " gstate
10191017 ]
10201018
1021- collectGlobHashes :: FilePath -> MonitorStateGlobRel -> [(FilePath , (ModTime , Hash ))]
1019+ collectGlobHashes :: FilePath -> MonitorStateGlobRel -> [(FilePath , (ModTime , HashValue ))]
10221020 collectGlobHashes dir (MonitorStateGlobDirs _ _ _ entries) =
10231021 [ res
10241022 | (subdir, fstate) <- entries
@@ -1043,13 +1041,13 @@ probeFileModificationTime root file mtime = do
10431041 unless unchanged (somethingChanged file)
10441042
10451043-- | Within the @root@ directory, check if @file@ has its 'ModTime' and
1046- -- 'Hash ' is the same as @mtime@ and @hash@, short-circuiting if it is
1044+ -- 'HashValue ' is the same as @mtime@ and @hash@, short-circuiting if it is
10471045-- different.
10481046probeFileModificationTimeAndHash
10491047 :: FilePath
10501048 -> FilePath
10511049 -> ModTime
1052- -> Hash
1050+ -> HashValue
10531051 -> ChangedM ()
10541052probeFileModificationTimeAndHash root file mtime hash = do
10551053 unchanged <-
@@ -1092,28 +1090,22 @@ checkModificationTimeUnchanged root file mtime =
10921090 return (mtime == mtime')
10931091
10941092-- | Returns @True@ if, inside the @root@ directory, @file@ has the
1095- -- same 'ModTime' and 'Hash ' as @mtime and @chash@.
1093+ -- same 'ModTime' and 'HashValue ' as @mtime and @chash@.
10961094checkFileModificationTimeAndHashUnchanged
10971095 :: FilePath
10981096 -> FilePath
10991097 -> ModTime
1100- -> Hash
1098+ -> HashValue
11011099 -> IO Bool
11021100checkFileModificationTimeAndHashUnchanged root file mtime chash =
11031101 handleIOException False $ do
11041102 mtime' <- getModTime (root </> file)
11051103 if mtime == mtime'
11061104 then return True
11071105 else do
1108- chash' <- readFileHash (root </> file)
1106+ chash' <- readFileHashValue (root </> file)
11091107 return (chash == chash')
11101108
1111- -- | Read a non-cryptographic hash of a @file@.
1112- readFileHash :: FilePath -> IO Hash
1113- readFileHash file =
1114- withBinaryFile file ReadMode $ \ hnd ->
1115- evaluate . Hashable. hash =<< BS. hGetContents hnd
1116-
11171109-- | Given a directory @dir@, return @Nothing@ if its 'ModTime'
11181110-- is the same as @mtime@, and the new 'ModTime' if it is not.
11191111checkDirectoryModificationTime :: FilePath -> ModTime -> IO (Maybe ModTime )
0 commit comments