fix a case where fileProperty reported a change despite not making one
The problem occurred because two lists of lines of the file can be different, while representing the same file content. For example: ["foo", "bar"] ["foo\nbar"]
This commit is contained in:
parent
040a5fe3c7
commit
f8943c2036
|
@ -62,11 +62,11 @@ fileProperty' :: (FilePath -> String -> IO ()) -> Desc -> ([Line] -> [Line]) ->
|
||||||
fileProperty' writer desc a f = property desc $ go =<< liftIO (doesFileExist f)
|
fileProperty' writer desc a f = property desc $ go =<< liftIO (doesFileExist f)
|
||||||
where
|
where
|
||||||
go True = do
|
go True = do
|
||||||
ls <- liftIO $ lines <$> readFile f
|
old <- liftIO $ readFile f
|
||||||
let ls' = a ls
|
let new = unlines (a (lines old))
|
||||||
if ls' == ls
|
if old == new
|
||||||
then noChange
|
then noChange
|
||||||
else makeChange $ viaTmp updatefile f (unlines ls')
|
else makeChange $ viaTmp updatefile f new
|
||||||
go False = makeChange $ writer f (unlines $ a [])
|
go False = makeChange $ writer f (unlines $ a [])
|
||||||
|
|
||||||
-- viaTmp makes the temp file mode 600.
|
-- viaTmp makes the temp file mode 600.
|
||||||
|
|
Loading…
Reference in New Issue