Hi Joachim,
The solution you've gone for certainly should work, but I'd be tempted
to go with the somewhat simpler:
writeFileChangedBS :: FilePath -> BS.ByteString -> Action ()
writeFileChangedBS name x = liftIO $ do
b <- doesFileExist name
if not b then BS.writeFile name x else do
b <- withFile name ReadMode $ \h -> do
src <- BS.hGetContents h
return $! src /= x
when b $ BS.writeFile name x
Then mark the rule for "site/index.html" as alwaysRerun and invoke
writeFileChangedBS. The code should be a bit simpler and reusable, and
you can skip storing the data in the Shake database as well as in the
binary and in the file.
The only downside is you have to read the file, which is another file
handle to open, but that shouldn't be terrible.
Another alternative, which might be the best performance wise, is to
have the Oracle store the hash of the bytestring, then you depend on
the oracle but use the bytestring directly. If the hash changes it
will rewrite, but the serialisation cost to the Shake database will be
minimal.
Thanks, Neil