git-annex/Annex
Joey Hess 345ee4f37c Switch to MonadCatchIO-transformers for better handling of state while catching exceptions.
As seen in this bug report, the lifted exception handling using the StateT
monad throws away state changes when an action throws an exception.
http://git-annex.branchable.com/bugs/git_annex_fork_bombs_on_gpg_file/
  .. Which can result in cached values being redundantly calculated, or other
     possibly worse bugs when the annex state gets out of sync with reality.

This switches from a StateT AnnexState to a ReaderT (MVar AnnexState).
All changes to the state go via the MVar. So when an Annex action is
running inside an exception handler, and it makes some changes, they
immediately go into affect in the MVar. If it then throws an exception
(or even crashes its thread!), the state changes are still in effect.

The MonadCatchIO-transformers change is actually only incidental.
I could have kept on using lifted-base for the exception handling.
However, I'd have needed to write a new instance of MonadBaseControl
for the new monad.. and I didn't write the old instance.. I begged Bas
and he kindly sent it to me. Happily, MonadCatchIO-transformers is
able to derive a MonadCatchIO instance for my monad.

This is a deep level change. It passes the test suite! What could it break?

Well.. The most likely breakage would be to code that runs an Annex action
in an exception handler, and *wants* state changes to be thrown away.
Perhaps the state changes leaves the state inconsistent, or wrong. Since
there are relatively few places in git-annex that catch exceptions in the
Annex monad, and the AnnexState is generally just used to cache calculated
data, this is unlikely to be a problem.

Oh yeah, this change also makes Assistant.Types.ThreadedMonad a bit
redundant. It's now entirely possible to run concurrent Annex actions in
different threads, all sharing access to the same state! The ThreadedMonad
just adds some extra work on top of that, with its own MVar, and avoids
such actions possibly stepping on one-another's toes. I have not gotten
rid of it, but might try that later. Being able to run concurrent Annex
actions would simplify parts of the Assistant code.
2013-05-19 14:16:36 -04:00
..
Content store copy in inode cache too 2013-05-17 16:16:10 -04:00
Branch.hs fix android build, broken by changes for windows port 2013-05-16 11:52:48 -04:00
BranchState.hs remove git-annex branch read cache 2012-10-19 14:25:15 -04:00
CatFile.hs Merge branch 'master' into windows 2013-05-15 19:18:04 -04:00
CheckAttr.hs finished where indentation changes 2012-12-13 00:24:19 -04:00
Content.hs improve handling of receiving object in direct mode when associated files are modified 2013-05-17 16:25:18 -04:00
Direct.hs test suite passes in direct mode 2013-05-17 15:59:37 -04:00
Environment.hs fix warnings 2013-05-13 15:30:18 -04:00
Exception.hs Switch to MonadCatchIO-transformers for better handling of state while catching exceptions. 2013-05-19 14:16:36 -04:00
FileMatcher.hs per-IA-item content directories 2013-04-25 23:44:55 -04:00
Journal.hs fix the day's windows permissions damage 2013-05-12 19:09:48 -04:00
Link.hs fix the day's Windows permissions damage 2013-05-14 20:15:14 -04:00
LockPool.hs fix permission damage (thanks, Windows) 2013-05-11 23:54:25 -04:00
Perms.hs fix permission damage (thanks, Windows) 2013-05-11 23:54:25 -04:00
Queue.hs type based git config handling for remotes 2013-01-01 13:58:14 -04:00
ReplaceFile.hs test suite passes in direct mode 2013-05-17 15:59:37 -04:00
Ssh.hs fix imports 2013-05-14 13:53:29 -04:00
TaggedPush.hs expose Control.Monad.join 2013-04-22 20:24:53 -04:00
UUID.hs Now uses the Haskell uuid library, rather than needing a uuid program. 2013-02-10 14:52:54 -04:00
Version.hs git-annex now builds on Windows (doesn't work) 2013-05-11 15:03:00 -05:00
Wanted.hs --auto fixes 2012-12-06 13:22:16 -04:00