12 Sep 2012 08:04
getModificationTime and directory-1.2
Ganesh Sittampalam <ganesh <at> earth.li>
2012-09-12 06:04:18 GMT
2012-09-12 06:04:18 GMT
Hi,
directory 1.2 switches to being based on 'time' rather than 'old-time'.
Because time values are exposed in its external API, this is causing
some disruption. In particular something like this pattern seems
relatively common:
getModTime :: FilePath -> IO EpochTime
getModTime path = do
(TOD s _) <- getModificationTime path
return $! fromIntegral s
i.e. get the modification time of a file in seconds since the UNIX epoch.
The replacement is something like:
t <- getModificationTime path
return $! fromInteger $ floor
$ t `diffUTCTime` UTCTime (fromGregorian 1970 1 1) 0
But if you want to be backwards compatible then cabal flags and CPP are
needed, so it's all a bit verbose.
Amongst the dependencies of darcs, I've found myself making a similar
change to three packages now (unix-compat, tar, zip-archive), so I
wonder if it's worth putting this function somewhere central?
One problem is that it's too late to put it in directory, because
1.2.0.0 was shipped with ghc 7.6.1 and so packages need to work against
that version.
(Continue reading)
RSS Feed