Auto merge of #5570 - alexcrichton:fix-deadlock, r=matklad
Fix an issue of deadlock in Cargo
Currently Cargo can deadlock itself via file locks in somewhat obscure
scenarios. One way to trigger this scenario is by causing the index to fail
being created, for example through an invalid `init.templatedir` configuration.
This commit takes the strategy of solving two bugs:
* First, the deadlock is fixed. This is done by manually ensuring that the
current deadlock doesn't happen by scheduling cached work to happen outside
the scope of a lock.
* Second, the initialization of the registry's index is fixed. We turn off the
usage of external templates as we don't want to use them for this internally
managed repository anyway.