@@ -61,15 +61,19 @@ formatOne mode config = \case
61 -- 101 is different from all the other exit codes we already use.
61 -- 101 is different from all the other exit codes we already use.
62 exitWith (ExitFailure 101)
62 exitWith (ExitFailure 101)
63 Just inputFile -> do
63 Just inputFile -> do
64+ originalInput <- TIO.readFile inputFile
64− r <- ormoluFile config inputFile
65+ formattedInput <- ormoluFile config inputFile
65 case mode of
66 case mode of
67− TIO.putStr r
68+ TIO.putStr formattedInput
68− InPlace ->
69+ InPlace -> do
70+ -- Only write when the contents have changed, in order to avoid
71+ -- updating the modified timestamp if the file was already correctly
73+ when (formattedInput /= originalInput) $
69− TIO.writeFile inputFile r
74+ TIO.writeFile inputFile formattedInput
70 Check -> do
75 Check -> do
71− r' <- TIO.readFile inputFile
76+ when (formattedInput /= originalInput) $
73 -- 100 is different to all the other exit code that are emitted
77 -- 100 is different to all the other exit code that are emitted
74 -- either from an 'OrmoluException' or from 'error' and
78 -- either from an 'OrmoluException' or from 'error' and
75 -- 'notImplemented'.
79 -- 'notImplemented'.