Skip to content

Commit 53b520e

Browse files
committed
Add MD5 comparison
1 parent 5b72046 commit 53b520e

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

app/Main.hs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
{-# LANGUAGE ScopedTypeVariables #-}
22
module Main where
33

4-
import Control.Exception (IOException, catch)
5-
import Control.Monad (filterM, liftM, unless)
6-
import Data.Map.Lazy (adjust, fromList, insert, toList)
7-
import Data.Maybe (listToMaybe)
8-
import Data.Typeable (typeOf)
9-
import Debug.Trace (traceShow)
10-
import GHC.IO.Exception (IOErrorType (..))
11-
import System.Directory (doesFileExist, getDirectoryContents,
12-
removeFile, renameFile)
13-
import System.Environment (getArgs, getEnvironment)
14-
import System.Exit (ExitCode (..))
15-
import System.FilePath (hasExtension, replaceBaseName,
16-
takeBaseName, (</>))
17-
import System.IO (hPutStrLn, stderr)
18-
import System.IO.Error (ioeGetErrorType)
19-
import System.Process (createProcess, env, shell, waitForProcess)
4+
import Control.Exception (IOException, catch)
5+
import Control.Monad (filterM, liftM, unless)
6+
import qualified Data.ByteString.Lazy as BL
7+
import Data.Digest.Pure.MD5 (md5)
8+
import Data.Map.Lazy (adjust, fromList, insert, toList)
9+
import Data.Maybe (listToMaybe)
10+
import Data.Typeable (typeOf)
11+
--import Debug.Trace (traceShow)
12+
import GHC.IO.Exception (IOErrorType (..))
13+
import System.Directory (doesFileExist, getDirectoryContents,
14+
removeFile, renameFile)
15+
import System.Environment (getArgs, getEnvironment)
16+
import System.Exit (ExitCode (..))
17+
import System.FilePath (hasExtension, replaceBaseName,
18+
takeBaseName, (</>))
19+
import System.IO (IOMode (..), hGetLine, hPutStrLn, stderr,
20+
withFile)
21+
import System.IO.Error (ioeGetErrorType)
22+
import System.Process (createProcess, env, shell,
23+
waitForProcess)
2024

21-
traceShow' arg = traceShow arg arg
25+
--traceShow' arg = traceShow arg arg
2226

2327
main :: IO ()
2428
main = mapM_ redo =<< getArgs
@@ -61,13 +65,14 @@ upToDate :: String -> IO Bool
6165
upToDate target =
6266
catch
6367
(do deps <- getDirectoryContents depDir
64-
(traceShow' . all id) `liftM` mapM depUpToDate deps)
68+
all id `liftM` mapM depUpToDate deps)
6569
(\(e :: IOException) -> return False)
6670
where
6771
depDir = ".redo" </> target
6872
depUpToDate :: FilePath -> IO Bool
6973
depUpToDate dep =
7074
catch
71-
(do oldMD5 <- traceShow' `liftM` readFile (depDir </> dep)
72-
return False)
75+
(do oldMD5 <- withFile (depDir </> dep) ReadMode hGetLine
76+
newMD5 <- md5 `liftM` BL.readFile dep
77+
return $ oldMD5 == show newMD5)
7378
(\(e :: IOException) -> return (ioeGetErrorType e == InappropriateType))

package.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ description: Please see the README on GitHub at <https://github.com/gith
2121

2222
dependencies:
2323
- base >= 4.7 && < 5
24+
- bytestring
2425
- containers
2526
- directory
2627
- filepath
28+
- pureMD5
2729
- process
2830

2931
library:

0 commit comments

Comments
 (0)