Fix ghc-pkg reports cache out date (#10205)
authorThomas Miedema <thomasmiedema@gmail.com>
Tue, 16 Jun 2015 21:38:38 +0000 (16:38 -0500)
committerAustin Seipp <austin@well-typed.com>
Tue, 16 Jun 2015 21:40:09 +0000 (16:40 -0500)
commitf0636562908236f6ce9bf91796bc952534074a61
tree4f588f59f37b7bee38531d39dc0ed9eb95146de1
parent65d4b895d8331ff9e7df6aaf0a0de898c857201c
Fix ghc-pkg reports cache out date (#10205)

See Note [writeAtomic leaky abstraction].

GHC on Linux already received a patch for this bug in
e0801a0fb342eea9a312906eab72874d631271cf. On Windows several cabal tests
were hitting the bug, causing validate failures, but we never noticed
because of all the other tests that were failing on Windows. And it
didn't start happening till `getModificationTime` received sub-second
resolution support on Windows in
5cf76186d373842bf64d49cecb09e0a9ddce3203.

Since there are regression tests already, I am not adding another one.
But for good measure, here is a script that shows the bug without
needing to do a full validate run:

  DB=/tmp/package.conf.d.test
  GHC_PKG=ghc-pkg #utils/ghc-pkg/dist/build/tmp/ghc-pkg
  LOCAL_GHC_PKG="${GHC_PKG} --no-user-package-db --global-package-db=${DB}"
  while true; do
    rm -rf ${DB}
    ${LOCAL_GHC_PKG} init "${DB}"
    ${LOCAL_GHC_PKG} list
  done

If you see "WARNING: cache is out of date" after a few seconds, the bug
is not fixed.

Reviewed By: austin

Differential Revision: https://phabricator.haskell.org/D990

GHC Trac Issues: #10205
utils/ghc-pkg/Main.hs