Skip to content

Commit

Permalink
save modification time with sub-second granularity
Browse files Browse the repository at this point in the history
Some systems can get the file modification time with sub-second
granularity. However, Hakyll shaves off the sub-seconds, as defined in
the Binary instance of BinaryTime, which poses a problem because when a
file is checked to see if it was modified in `resourceModified`, it
still contains the sub-seconds. This results in a file (almost) always
being considered as having been modified.

Example:

1. First go around, modification time is 3:45.325. This time is saved
   as 3:45.000 (i.e. sub-seconds are shaved off).
2. Second go around, modification time is again read as 3:45.325 and
   compared against the stored time, 3:45.000. 3:45.325 is more recent
   than 3:45.000, so the file is considered to have been modified.

This change prevents the shaving off of sub-seconds. This will naturally
work on systems that don't support sub-second granularity, as that
'field' will simply appear as all zeros.

Closes jaspervdj#250
  • Loading branch information
blaenk committed May 9, 2014
1 parent 43c2aea commit d86b475
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/Hakyll/Core/Provider/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ import Data.Maybe (fromMaybe)
import Data.Monoid (mempty)
import Data.Set (Set)
import qualified Data.Set as S
import Data.Time (Day (..), UTCTime (..),
secondsToDiffTime)
import Data.Time (Day (..), UTCTime (..))
import Data.Typeable (Typeable)
import System.Directory (getModificationTime)
import System.FilePath (addExtension, (</>))
Expand Down Expand Up @@ -62,11 +61,11 @@ newtype BinaryTime = BinaryTime {unBinaryTime :: UTCTime}
--------------------------------------------------------------------------------
instance Binary BinaryTime where
put (BinaryTime (UTCTime (ModifiedJulianDay d) dt)) =
put d >> put (floor dt :: Integer)
put d >> put (toRational dt)

get = fmap BinaryTime $ UTCTime
<$> (ModifiedJulianDay <$> get)
<*> (secondsToDiffTime <$> get)
<*> (fromRational <$> get)


--------------------------------------------------------------------------------
Expand Down

0 comments on commit d86b475

Please sign in to comment.