2 module Main (main) where
6 import System.Environment
11 data CleanWhat = CleanFile FilePath
16 main = do args <- getArgs
18 [contentsBeforeFile, contentsAfterFile, wouldBeCleanedFile] ->
19 doit contentsBeforeFile contentsAfterFile wouldBeCleanedFile
23 doit :: FilePath -> FilePath -> FilePath -> IO ()
24 doit contentsBeforeFile contentsAfterFile wouldBeCleanedFile
25 = do contentsBefore <- liftM lines $ readFile contentsBeforeFile
26 contentsAfter <- liftM lines $ readFile contentsAfterFile
27 wouldBeCleaned <- liftM (map read . lines) $ readFile wouldBeCleanedFile
28 let newContentsAfter = contentsAfter \\ contentsBefore
29 let cleanedAfter = simulateCleans newContentsAfter wouldBeCleaned
30 unless (null cleanedAfter) $ do
31 hPutStrLn stderr "Files not cleaned:"
32 mapM_ (hPutStrLn stderr . show) cleanedAfter
33 exitWith (ExitFailure 1)
35 simulateCleans :: [FilePath] -> [CleanWhat] -> [FilePath]
36 simulateCleans fs cws = filter (not . cleaned) fs
37 where cleaned f = any (`willClean` f) cws
39 willClean :: CleanWhat -> FilePath -> Bool
40 CleanFile fp `willClean` f = fp `equalFilePath` f
41 CleanRec fp `willClean` f
42 = any (fp `equalFilePath`) (map joinPath $ inits $ splitPath f)