Use a 'patch' command which should work on BSD
Do not clean tmp files in repository caches if there exists at least a compiler having the package installed.
Do not check the consistency on every state load, as this can be wrong in some cases (ie. for instance, when the global lock is taken).

Previously, having a long-running 'opam install <foo>' command in one term and an 'opam list' in an other will break in an horrible way as the 'opam list' consistency check will remove the eventual tmp dirs created by 'opam install <foo>'

This is fixed by doing global consistency check only when we have the global lock (ie. when we know that no other operation can be done concurrently) and switch consistency checks when we have the right switch lock.